fix: 20q answers truncate at sentence boundary, not mid-word
Instead of a raw 6-word slice (which left dangling fragments like 'Partly - Not exclusively American; has'), extract the first complete sentence (up to 10 words). Falls back to the 6-word cap only if no sentence boundary is found in the response. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2823,7 +2823,10 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
|
||||
) as response:
|
||||
data = await response.json()
|
||||
raw = data.get("message", {}).get("content", "").strip()
|
||||
# Hard cap at 6 words — enough for a real answer, not enough to name-drop
|
||||
# Take the first sentence; fall back to a 6-word hard cap
|
||||
m = re.search(r"^[^.!?\n]+[.!?]", raw)
|
||||
if m and len(m.group(0).split()) <= 10:
|
||||
return m.group(0).strip()
|
||||
words = raw.split()
|
||||
return " ".join(words[:6]) if words else "..."
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user