fix: 去除掉ai返回内容中的代码块样式

This commit is contained in:
roitium 2024-07-22 12:13:02 +08:00
parent 2f53d99359
commit c985e5b08f
2 changed files with 8 additions and 0 deletions

View File

@ -67,6 +67,10 @@ export class LongTermMemoryAgent {
shortTermMemory: lastOf(newMemories)!.text, shortTermMemory: lastOf(newMemories)!.text,
}), }),
}); });
// 如果返回内容是个markdown代码块,就让他变回普通json
res?.content?.trim();
if (res?.content?.startsWith("```json")) {res.content = res?.content?.replace("```json", "");}
if (res?.content?.endsWith("```")) {res.content = res?.content?.replace("```", "");}
return jsonDecode(res?.content)?.longTermMemories?.toString(); return jsonDecode(res?.content)?.longTermMemories?.toString();
} }
} }

View File

@ -78,6 +78,10 @@ export class ShortTermMemoryAgent {
.join("\n"), .join("\n"),
}), }),
}); });
// 如果返回内容是个markdown代码块,就让他变回普通json
res?.content?.trim();
if (res?.content?.startsWith("```json")) {res.content = res?.content?.replace("```json", "");}
if (res?.content?.endsWith("```")) {res.content = res?.content?.replace("```", "");}
return jsonDecode(res?.content)?.shortTermMemories?.toString(); return jsonDecode(res?.content)?.shortTermMemories?.toString();
} }
} }