From 0b9f598c7d652747180299eb2e034c4feb3b87b4 Mon Sep 17 00:00:00 2001 From: Giancarmine Salucci Date: Tue, 12 May 2026 21:11:50 +0200 Subject: [PATCH] fix(parser): handle thinking models in recipe detection 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> --- src/lib/server/parser.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/server/parser.ts b/src/lib/server/parser.ts index d9474c7..6691ad9 100644 --- a/src/lib/server/parser.ts +++ b/src/lib/server/parser.ts @@ -49,11 +49,17 @@ export async function detectRecipe(text: string): Promise { 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 }); - 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); return detectionResult.includes('yes');