fix(mnemopi): anchored think stripping to leading blocks

- Restricted the reasoning-wrapper removal to leading <think> blocks so a
  literal think tag after real content is preserved instead of deleted.
- Added coverage asserting mid-content think tags survive cleanOutput.

Fixes #7231
This commit is contained in:
roboomp
2026-08-01 05:18:25 +00:00
parent ebd7ea3578
commit c95d182bf2
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -254,7 +254,7 @@ export function cleanOutput(text: string): string {
.replaceAll("<|user|>", "")
.replaceAll("</s>", "")
.trim()
.replace(/<think>[\s\S]*?<\/think>/gi, "")
.replace(/^(?:\s*<think>[\s\S]*?<\/think>)+\s*/i, "")
.replace(/^(Summarize the following memories.*?[.!?:]\s*)/is, "")
.replace(/^(Preserve facts.*?[.!?:]\s*)/is, "")
.replace(/^Source:.*?\n/im, "")
+5
View File
@@ -11,6 +11,7 @@ import {
callLocalLlm,
callRemoteLlm,
chunkMemoriesByBudget,
cleanOutput,
complete,
llmAvailable,
localGgufAvailable,
@@ -83,6 +84,10 @@ describe("local LLM TypeScript port", () => {
);
});
it("preserves a literal think tag that follows real content", () => {
expect(cleanOutput("The XML tag is <think>keep</think>")).toBe("The XML tag is <think>keep</think>");
});
it("keeps local GGUF unavailable and returns null for local completion", async () => {
expect(localGgufAvailable()).toBe(false);
expect(await callLocalLlm("prompt")).toBeNull();