fix(eo): sanitize DeepSeek JSON response before parsing
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0c6e4cfac1
commit
4fde66d930
1 changed files with 15 additions and 1 deletions
|
|
@ -402,6 +402,20 @@ export function truncateToMaxWords(
|
|||
|
||||
// ── Appels DeepSeek ──────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Strip d'éventuels fences markdown autour d'une réponse JSON.
|
||||
*
|
||||
* DeepSeek wrappe parfois sa sortie dans des blocs ```json ... ``` malgré
|
||||
* `response_format: { type: "json_object" }`. On retire ces fences avant
|
||||
* `JSON.parse` pour éviter `SyntaxError: Expected property name`.
|
||||
*/
|
||||
function sanitizeJsonContent(raw: string): string {
|
||||
return raw
|
||||
.replace(/^\s*```(?:json)?\s*/i, "")
|
||||
.replace(/\s*```\s*$/i, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
async function callDeepSeek(
|
||||
system: string,
|
||||
user: string,
|
||||
|
|
@ -444,7 +458,7 @@ async function callDeepSeek(
|
|||
throw new Error("DeepSeek API: réponse vide");
|
||||
}
|
||||
|
||||
return content;
|
||||
return sanitizeJsonContent(content);
|
||||
} catch (err) {
|
||||
const kind =
|
||||
err instanceof Error && err.name === "TimeoutError"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue