fix(parser): handle thinking models in recipe detection
Some checks failed
Build & Push Docker Image / test-and-build (push) Failing after 38s

Increase max_tokens from 10 to 1024 for detection so thinking
models have room to reason. Also fall back to reasoning_content
if content is empty, since some local models (e.g. Gemma 4
thinking variants) put their answer there.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giancarmine Salucci
2026-05-12 21:11:50 +02:00
parent 97355d859f
commit 0b9f598c7d

View File

@@ -49,11 +49,17 @@ export async function detectRecipe(text: string): Promise<boolean> {
content: `Does this text contain a recipe?\n\n${text}` content: `Does this text contain a recipe?\n\n${text}`
} }
], ],
max_tokens: 10, // 1024 gives thinking models room to reason before answering
max_tokens: 1024,
temperature: 0 temperature: 0
}); });
const detectionResult = detectionResponse.choices[0].message.content?.toLowerCase() ?? ''; const msg = detectionResponse.choices[0].message;
// Some local models (e.g. Gemma thinking variants) return the answer in
// reasoning_content instead of content when max_tokens is tight.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reasoning: string = (msg as any).reasoning_content ?? '';
const detectionResult = (msg.content ?? reasoning).toLowerCase();
console.log('[LLM] Detection response:', detectionResult); console.log('[LLM] Detection response:', detectionResult);
return detectionResult.includes('yes'); return detectionResult.includes('yes');