Spaces:
Running
Running
Commit
·
2e33030
1
Parent(s):
7493f69
Fix reasoning trace parsing for incomplete XML tags
Browse files- Update detectReasoningTrace to require both opening AND closing tags
- Add console warning when incomplete reasoning traces are detected
- Skip malformed reasoning traces to avoid confusing partial content
- Maintains full functionality for well-formed reasoning traces
- js/reasoning-parser.js +16 -7
js/reasoning-parser.js
CHANGED
|
@@ -12,15 +12,18 @@ class ReasoningParser {
|
|
| 12 |
static detectReasoningTrace(text) {
|
| 13 |
if (!text || typeof text !== 'string') return false;
|
| 14 |
|
| 15 |
-
// Check for
|
| 16 |
-
const
|
| 17 |
-
/<think>/i,
|
| 18 |
-
/<thinking>/i,
|
| 19 |
-
/<reasoning>/i,
|
| 20 |
-
/<thought>/i
|
| 21 |
];
|
| 22 |
|
| 23 |
-
return
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
|
@@ -77,6 +80,12 @@ class ReasoningParser {
|
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
// If no patterns match, return original text as answer
|
| 81 |
return {
|
| 82 |
reasoning: null,
|
|
|
|
| 12 |
static detectReasoningTrace(text) {
|
| 13 |
if (!text || typeof text !== 'string') return false;
|
| 14 |
|
| 15 |
+
// Check for complete reasoning trace patterns (both opening and closing tags)
|
| 16 |
+
const completePatterns = [
|
| 17 |
+
{ start: /<think>/i, end: /<\/think>/i },
|
| 18 |
+
{ start: /<thinking>/i, end: /<\/thinking>/i },
|
| 19 |
+
{ start: /<reasoning>/i, end: /<\/reasoning>/i },
|
| 20 |
+
{ start: /<thought>/i, end: /<\/thought>/i }
|
| 21 |
];
|
| 22 |
|
| 23 |
+
// Only return true if we find BOTH opening and closing tags
|
| 24 |
+
return completePatterns.some(pattern =>
|
| 25 |
+
pattern.start.test(text) && pattern.end.test(text)
|
| 26 |
+
);
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
|
|
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
+
// Check if there are incomplete reasoning tags (opening but no closing)
|
| 84 |
+
const hasOpeningTag = /<think>|<thinking>|<reasoning>|<thought>/i.test(text);
|
| 85 |
+
if (hasOpeningTag) {
|
| 86 |
+
console.warn('Incomplete reasoning trace detected - missing closing tags');
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
// If no patterns match, return original text as answer
|
| 90 |
return {
|
| 91 |
reasoning: null,
|