fix assistant truncated answer detection

This commit is contained in:
Daniel 2026-05-07 23:38:35 +02:00
parent 4e3e6031d4
commit 73fe617afc

View file

@ -886,8 +886,11 @@ function shouldRegenerateTruncatedAnswer(answer, finishReason) {
answer = String(answer || '').trim();
if (!answer) return false;
if (finishReason === 'length') return true;
if (/\b(the|a|an|and|or|but|with|without|for|to|of|in|on|as|by|from|because|therefore|however)$/i.test(answer)) return true;
if (/\b(the|a|an|and|or|but|with|without|for|to|of|in|on|as|by|from|because|therefore|however|some|many|most|few|several|additional|other|further|including|such)$/i.test(answer)) return true;
if (/[,:;\-–—(]$/.test(answer)) return true;
var lines = answer.split(/\n+/).map(function(line) { return line.trim(); }).filter(Boolean);
var last = lines.length ? lines[lines.length - 1] : answer;
if (last.length > 24 && /[A-Za-z]$/.test(last) && !/[.!?\])”"']$/.test(last)) return true;
return false;
}