Skip to content

Commit

Permalink
fix: 去除掉ai返回内容中的代码块样式
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyao2333 committed Jul 22, 2024
1 parent 2f53d99 commit c985e5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/services/bot/memory/long-term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class LongTermMemoryAgent {
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();
}
}
4 changes: 4 additions & 0 deletions src/services/bot/memory/short-term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class ShortTermMemoryAgent {
.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();
}
}

0 comments on commit c985e5b

Please sign in to comment.