From 5574a3c59d927280faa0fc67d91c0c6831ab64cf Mon Sep 17 00:00:00 2001 From: Fahri Can Date: Sun, 17 May 2026 16:47:05 +0300 Subject: [PATCH] feat: separate commentary endpoint - non-blocking Ollama --- .../predictions/predictions.controller.ts | 13 ++++++++++ .../predictions/predictions.service.ts | 25 ++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/modules/predictions/predictions.controller.ts b/src/modules/predictions/predictions.controller.ts index d65c45b..eb151bd 100755 --- a/src/modules/predictions/predictions.controller.ts +++ b/src/modules/predictions/predictions.controller.ts @@ -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 diff --git a/src/modules/predictions/predictions.service.ts b/src/modules/predictions/predictions.service.ts index cbb4977..2de5a26 100755 --- a/src/modules/predictions/predictions.service.ts +++ b/src/modules/predictions/predictions.service.ts @@ -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, - ); - if (aiCommentary) { - (prediction as unknown as Record).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 { + // 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, + ); + } catch { + return null; + } + } + async getCachedPrediction( matchId: string, ): Promise {