mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
Revert "fix: handle <think> reasoning tags in parseExtractorOutput (#2559)"
This reverts commit 2724c3b6c9.
This commit is contained in:
@@ -295,8 +295,6 @@ export function isWellFormedEmptyExtraction(raw: string): boolean {
|
||||
export function parseExtractorOutput(raw: string): ProposedTake[] {
|
||||
if (!raw || raw.trim().length === 0) return [];
|
||||
let text = raw.trim();
|
||||
// Strip <think>...</think> reasoning tags (MiniMax-M3, DeepSeek-R1, etc.).
|
||||
text = text.replace(/<think>[\s\S]*?<\/think>/g, '').trim();
|
||||
// Strip markdown code fence wrapper.
|
||||
const fenced = text.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?```$/);
|
||||
if (fenced) text = (fenced[1] ?? '').trim();
|
||||
@@ -309,21 +307,7 @@ export function parseExtractorOutput(raw: string): ProposedTake[] {
|
||||
try {
|
||||
parsed = JSON.parse(text.slice(start));
|
||||
} catch {
|
||||
// Fallback: truncate at last ] or } to handle trailing noise (e.g. leftover
|
||||
// markdown fences after <think> stripping). Try array-closing first.
|
||||
const sliced = text.slice(start);
|
||||
const lastArr = sliced.lastIndexOf(']');
|
||||
const lastObj = sliced.lastIndexOf('}');
|
||||
const end = Math.max(lastArr, lastObj);
|
||||
if (end > 0) {
|
||||
try {
|
||||
parsed = JSON.parse(sliced.slice(0, end + 1));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
const arr = Array.isArray(parsed) ? parsed : [parsed];
|
||||
const out: ProposedTake[] = [];
|
||||
|
||||
@@ -170,26 +170,6 @@ describe('parseExtractorOutput', () => {
|
||||
const out = parseExtractorOutput(raw);
|
||||
expect(out[0]!.domain).toBe('macro');
|
||||
});
|
||||
|
||||
test('strips <think> reasoning tags before parsing (MiniMax-M3, DeepSeek-R1)', () => {
|
||||
const raw = '<think>Analyzing the prose... I see several claims.</think>\n\n```json\n[{"claim_text":"X","kind":"take","holder":"brain","weight":0.5}]\n```';
|
||||
const out = parseExtractorOutput(raw);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]!.claim_text).toBe('X');
|
||||
});
|
||||
|
||||
test('strips multiple <think> blocks', () => {
|
||||
const raw = '<think>First thought.</think>\n<tool_call>...</tool_call>\n<think>Second thought.</think>\n\n[{"claim_text":"Y","kind":"bet","holder":"brain","weight":0.7}]';
|
||||
const out = parseExtractorOutput(raw);
|
||||
expect(out).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('handles trailing noise after JSON (leftover fences)', () => {
|
||||
const raw = '<think>done</think>\n```json\n[{"claim_text":"Z","kind":"take","holder":"brain","weight":0.6}]\n```\n';
|
||||
const out = parseExtractorOutput(raw);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]!.claim_text).toBe('Z');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── isWellFormedEmptyExtraction ────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user