fix: 20q answers truncate at sentence boundary, not mid-word
Lint / Shell (shellcheck) (push) Successful in 15s
Lint / JS (eslint) (push) Successful in 9s
Lint / Python (ruff) (push) Successful in 10s
Lint / Python deps (pip-audit) (push) Successful in 58s
Lint / Secret scan (gitleaks) (push) Successful in 6s

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:
2026-04-26 20:10:49 -04:00
parent 75f9c7bdb9
commit 121e160535
+4 -1
View File
@@ -2823,7 +2823,10 @@ async def _answer_20q(thing: str, category: str, question: str) -> str:
) as response: ) as response:
data = await response.json() data = await response.json()
raw = data.get("message", {}).get("content", "").strip() 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() words = raw.split()
return " ".join(words[:6]) if words else "..." return " ".join(words[:6]) if words else "..."
except Exception as e: except Exception as e: