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:
@@ -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, "")
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user