fix(aux): bracket-prefixed and fence-containing prose titles are kept
`_is_truncated_structured_output` flagged any reply starting with `{`/`[` or
containing an odd number of fences, so a provider that ignores response_format
and answers `[WIP] Fix login flow` or `Fix ``` rendering in chat` lost its
title (the derived title stayed). Truncated JSON is recognised by its JSON-shaped
opener (`{"`, `["`, `[{`) and an unclosed fence only when the fence opens the
reply — the fragments from #83903 are still dropped.
Review follow-up on #113960; two legit-title cases added to the existing
parametrized invariant (red on the previous head).
This commit is contained in:
@@ -245,9 +245,10 @@ def _extract_json_title(raw: str) -> Optional[str]:
|
||||
def _is_truncated_structured_output(raw: str) -> bool:
|
||||
"""Structured output the token cap cut before its closing quote/brace/fence (``{"title``, a bare fence opener).
|
||||
|
||||
Checked only after the JSON paths failed, and on structure alone (a leading brace/bracket, an
|
||||
unclosed fence) so quoted or *emphasized* prose titles are untouched (#83903)."""
|
||||
return raw.count("```") % 2 == 1 or raw.startswith(("{", "["))
|
||||
Checked only after the JSON paths failed, and on structure alone (a JSON-shaped opener, a fence
|
||||
opener that is never closed) so quoted, *emphasized* or ``[WIP]``-prefixed prose titles are
|
||||
untouched (#83903)."""
|
||||
return raw.startswith(('{"', '["', "[{")) or (raw.startswith("```") and raw.count("```") % 2 == 1)
|
||||
|
||||
|
||||
def _extract_title_text(content: str) -> str:
|
||||
|
||||
@@ -82,6 +82,10 @@ class TestGenerateTitle:
|
||||
("修复登录按钮", "修复登录按钮"),
|
||||
("42", "42"),
|
||||
('```json\n{"title": "Fix login button"', "Fix login button"),
|
||||
# Bracket/brace-prefixed prose and a literal fence inside a sentence are titles, not
|
||||
# truncated JSON — a provider that ignores response_format still gets its title kept.
|
||||
("[WIP] Fix login flow", "[WIP] Fix login flow"),
|
||||
("Fix ``` rendering in chat", "Fix ``` rendering in chat"),
|
||||
],
|
||||
)
|
||||
def test_truncated_structured_output_never_becomes_the_title(self, content, expected):
|
||||
|
||||
Reference in New Issue
Block a user