strip tags de respuestas IA (DeepSeek reasoning)
This commit is contained in:
+16
-1
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user