feat: separate commentary endpoint - non-blocking Ollama
Deploy Iddaai Backend / build-and-deploy (push) Successful in 30s

This commit is contained in:
2026-05-17 16:47:05 +03:00
parent 94c7a4481a
commit 5574a3c59d
2 changed files with 26 additions and 12 deletions
@@ -143,6 +143,19 @@ export class PredictionsController {
return prediction;
}
/**
* GET /predictions/:matchId/commentary
* Get AI expert commentary for a match (separate async call)
*/
@Get(":matchId/commentary")
async getCommentary(
@Param("matchId") matchId: string,
@CurrentUser() user: any,
): Promise<{ commentary: string | null }> {
const commentary = await this.predictionsService.getAiCommentary(matchId);
return { commentary };
}
/**
* POST /predictions/generate
* Generate prediction with provided match data
+13 -12
View File
@@ -239,18 +239,6 @@ export class PredictionsService implements OnModuleInit, OnModuleDestroy {
matchContext,
);
// Generate AI expert commentary via Ollama (non-blocking, best-effort)
try {
const aiCommentary = await generateExpertCommentary(
response.data as unknown as Record<string, unknown>,
);
if (aiCommentary) {
(prediction as unknown as Record<string, unknown>).ai_expert_commentary = aiCommentary;
}
} catch {
// Ollama failure is non-fatal
}
await this.recordPredictionRun(matchId, response.data);
await this.cachePrediction(matchId, prediction);
return prediction;
@@ -1304,6 +1292,19 @@ export class PredictionsService implements OnModuleInit, OnModuleDestroy {
}
}
async getAiCommentary(matchId: string): Promise<string | null> {
// Use cached prediction data to generate commentary
const cached = await this.getStoredPrediction(matchId);
if (!cached) return null;
try {
return await generateExpertCommentary(
cached as unknown as Record<string, unknown>,
);
} catch {
return null;
}
}
async getCachedPrediction(
matchId: string,
): Promise<MatchPredictionDto | null> {