mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 05:12:15 +00:00
fix: strip antml thinking tags
This commit is contained in:
@@ -461,6 +461,11 @@ File contents here`,
|
||||
text: "<antthinking>Some reasoning</antthinking>The actual answer.",
|
||||
expected: "The actual answer.",
|
||||
},
|
||||
{
|
||||
name: "antml namespaced thinking tag",
|
||||
text: "<antml:thinking>This shows Robin Waslander DMing maintainers o...</antml:thinking>Actual reply.",
|
||||
expected: "Actual reply.",
|
||||
},
|
||||
{
|
||||
name: "final wrapper",
|
||||
text: "<final>\nAnswer\n</final>",
|
||||
|
||||
@@ -50,6 +50,11 @@ describe("stripReasoningTagsFromText", () => {
|
||||
input: "X <antthinking>internal</antthinking> Y",
|
||||
expected: "X Y",
|
||||
},
|
||||
{
|
||||
name: "strips antml namespaced thinking tags",
|
||||
input: "Before <antml:thinking>secret</antml:thinking> after",
|
||||
expected: "Before after",
|
||||
},
|
||||
{
|
||||
name: "strips multiple reasoning blocks",
|
||||
input: "<think>first</think>A<think>second</think>B",
|
||||
@@ -194,6 +199,10 @@ describe("stripReasoningTagsFromText", () => {
|
||||
input: "A <THINK>hidden</THINK> <Thinking>also hidden</Thinking> B",
|
||||
expected: "A B",
|
||||
},
|
||||
{
|
||||
input: "A <ANTML:THINKING hidden='1'>secret</ANTML:THINKING> B",
|
||||
expected: "A B",
|
||||
},
|
||||
] as const)("handles unicode/attributes/case-insensitive names: %j", (testCase) => {
|
||||
expectStrippedCase(testCase);
|
||||
});
|
||||
|
||||
@@ -2,9 +2,10 @@ import { findCodeRegions, isInsideCode } from "./code-regions.js";
|
||||
export type ReasoningTagMode = "strict" | "preserve";
|
||||
export type ReasoningTagTrim = "none" | "start" | "both";
|
||||
|
||||
const QUICK_TAG_RE = /<\s*\/?\s*(?:think(?:ing)?|thought|antthinking|final)\b/i;
|
||||
const QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i;
|
||||
const FINAL_TAG_RE = /<\s*\/?\s*final\b[^<>]*>/gi;
|
||||
const THINKING_TAG_RE = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\b[^<>]*>/gi;
|
||||
const THINKING_TAG_RE =
|
||||
/<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\b[^<>]*>/gi;
|
||||
|
||||
function applyTrim(value: string, mode: ReasoningTagTrim): string {
|
||||
if (mode === "none") {
|
||||
|
||||
Reference in New Issue
Block a user