fix: the take-home sheet gives a reasoning model room to think and still write
All checks were successful
Forgejo Docker Build / Root app tests (push) Successful in 47s
Forgejo Docker Build / Build Docker image (push) Successful in 9s
Forgejo Docker Build / End-to-end (browser) (push) Successful in 6s

The 1,800-token ceiling was spent entirely on hidden reasoning, so the
sheet came back empty. Same budget as the answer path now, with one retry
at a larger budget if the reply is still blank.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv6sqaY6Vq3ChZHMem3cnU
This commit is contained in:
Daniel 2026-09-14 05:23:13 +02:00
parent 012a06c107
commit 1d58e5b509

View file

@ -27,14 +27,23 @@ async function generatePatientTakehome(opts) {
{ role: 'system', content: behavior }, { role: 'system', content: behavior },
{ role: 'user', content: 'Clinical answer:\n' + answer + '\n\nWrite the patient take-home sheet now.' } { role: 'user', content: 'Clinical answer:\n' + answer + '\n\nWrite the patient take-home sheet now.' }
]; ];
// The budget covers the model's hidden reasoning as well as the sheet. At
// 1,800 tokens a reasoning model (DeepSeek flash spent 8,400 characters
// thinking about a discharge sheet) hit the limit before writing a word and
// the user saw "empty take-home sheet". Same ceiling as the answer path,
// and one retry with more room when the reply still comes back empty.
var ai; var ai;
var budgets = [5000, 9000];
for (var attempt = 0; attempt < budgets.length; attempt++) {
try { try {
ai = await opts.callAI(messages, assistantGenerationOptions({ model: opts.model || undefined, temperature: 0.15, maxTokens: 1800 })); ai = await opts.callAI(messages, assistantGenerationOptions({ model: opts.model || undefined, temperature: 0.15, maxTokens: budgets[attempt] }));
} catch (err) { } catch (err) {
err = err || new Error('Take-home generation failed'); err = err || new Error('Take-home generation failed');
if (!err.statusCode && !err.response) err.statusCode = 502; if (!err.statusCode && !err.response) err.statusCode = 502;
throw err; throw err;
} }
if (ai && String(ai.content || '').trim()) break;
}
var text = stripCitationTokens(ai && ai.content || '').slice(0, MAX_RESULT_CHARS); var text = stripCitationTokens(ai && ai.content || '').slice(0, MAX_RESULT_CHARS);
if (!text) { e = new Error('The model returned an empty take-home sheet'); e.statusCode = 502; throw e; } if (!text) { e = new Error('The model returned an empty take-home sheet'); e.statusCode = 502; throw e; }
return { text: text, model: ai.model || null, provider: ai.provider || null }; return { text: text, model: ai.model || null, provider: ai.provider || null };