feat: separate commentary endpoint - non-blocking Ollama
Deploy Iddaai Backend / build-and-deploy (push) Successful in 30s
Deploy Iddaai Backend / build-and-deploy (push) Successful in 30s
This commit is contained in:
@@ -143,6 +143,19 @@ export class PredictionsController {
|
|||||||
return prediction;
|
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
|
* POST /predictions/generate
|
||||||
* Generate prediction with provided match data
|
* Generate prediction with provided match data
|
||||||
|
|||||||
@@ -239,18 +239,6 @@ export class PredictionsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
matchContext,
|
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.recordPredictionRun(matchId, response.data);
|
||||||
await this.cachePrediction(matchId, prediction);
|
await this.cachePrediction(matchId, prediction);
|
||||||
return 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(
|
async getCachedPrediction(
|
||||||
matchId: string,
|
matchId: string,
|
||||||
): Promise<MatchPredictionDto | null> {
|
): Promise<MatchPredictionDto | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user