diff --git a/src/routes/clinicalAssistant.js b/src/routes/clinicalAssistant.js index 7646a06..536bed7 100644 --- a/src/routes/clinicalAssistant.js +++ b/src/routes/clinicalAssistant.js @@ -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; }