strip tags de respuestas IA (DeepSeek reasoning)

This commit is contained in:
2026-05-28 14:08:07 -05:00
parent 8cec93b90a
commit e950eb1285
+16 -1
View File
@@ -103,7 +103,22 @@ export async function callAI(
const content = data.choices?.[0]?.message?.content || null const content = data.choices?.[0]?.message?.content || null
if (!content) throw new Error('Respuesta vacía del proveedor de IA') if (!content) throw new Error('Respuesta vacía del proveedor de IA')
return content return stripThinkTags(content)
}
/**
* Elimina bloques de razonamiento interno del modelo (DeepSeek, etc.).
* Ej: "...." o "..."
*/
function stripThinkTags(text: string): string {
return text
.replace(/```thinking[\s\S]*?```/gi, '')
.replace(/```reasoning[\s\S]*?```/gi, '')
.replace(/<think>[\s\S]*?<\/think>/gi, '')
.replace(/<thinking>[\s\S]*?<\/thinking>/gi, '')
.replace(/^.*?\*\*Respuesta:/s, '')
.replace(/^.*?\*\*Final Answer:/s, '')
.trim()
} }
export async function chatWithAI( export async function chatWithAI(