From 468394022c2946c03e82ecb1dafb33848adf679d Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Sat, 4 Oct 2025 12:46:21 +0000 Subject: [PATCH] Improve AI response parsing by adding more flexible regex and logging Add console logs to `server/services/openrouter.ts` to aid in debugging AI response parsing, specifically for different versions (1, 2, 3) of AI-generated content. Enhance regex flexibility for recognizing version separators and content. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/sEXz3DF --- server/services/openrouter.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/services/openrouter.ts b/server/services/openrouter.ts index 4cc1ef9..4d22b33 100644 --- a/server/services/openrouter.ts +++ b/server/services/openrouter.ts @@ -101,6 +101,9 @@ VERSION 3 - ÉMOTIONNELLE: // Normaliser les retours à la ligne (CRLF -> LF) const normalizedContent = content.replace(/\r\n/g, '\n'); + console.log('🔍 AI Response to parse (first 800 chars):\n', normalizedContent.substring(0, 800)); + console.log('🔍 AI Response length:', normalizedContent.length); + // Regex ultra-flexibles acceptant: // - markdown (** optionnel) // - tirets variés (-, –, —) @@ -110,6 +113,8 @@ VERSION 3 - ÉMOTIONNELLE: const version1Match = normalizedContent.match(/\*{0,2}\s*VERSION\s+1\s*[-–—]\s*DYNAMIQUE\s*\*{0,2}:?\s*[\r\n]+([\s\S]*?)(?=\s*[-*]{3,}\s*[\r\n]+|\*{0,2}\s*VERSION\s+2|$)/i); const version2Match = normalizedContent.match(/\*{0,2}\s*VERSION\s+2\s*[-–—]\s*INFORMATIVE?\s*\*{0,2}:?\s*[\r\n]+([\s\S]*?)(?=\s*[-*]{3,}\s*[\r\n]+|\*{0,2}\s*VERSION\s+3|$)/i); const version3Match = normalizedContent.match(/\*{0,2}\s*VERSION\s+3\s*[-–—]\s*[ÉE]MOTIONNELLE?\s*\*{0,2}:?\s*[\r\n]+([\s\S]*?)$/i); + + console.log('🔍 Matches found:', { v1: !!version1Match, v2: !!version2Match, v3: !!version3Match }); if (version1Match) { const text = version1Match[1].trim();