mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-14 20:25:26 +02:00
fix(llm): keep answers too deeply nested to parse whole in prefilled mode
Signed-off-by: FenjuFu <fufenjupku@gmail.com>
This commit is contained in:
@@ -55,14 +55,17 @@ def _is_json_document(content: str) -> bool:
|
||||
|
||||
Reasoning followed by a closing tag is never valid JSON, so a structured
|
||||
answer that carries the tag inside a string value is left whole. Input
|
||||
nested too deeply to parse is not treated as JSON rather than failing the
|
||||
request.
|
||||
nested too deeply for the parser to finish is kept whole as well: reasoning
|
||||
does not open with that many brackets, so cutting it would only risk
|
||||
truncating a real answer.
|
||||
"""
|
||||
stripped = content.strip()
|
||||
if not stripped.startswith(("{", "[")):
|
||||
return False
|
||||
try:
|
||||
json.loads(stripped)
|
||||
except (ValueError, RecursionError):
|
||||
except RecursionError:
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -70,7 +70,7 @@ def test_strip_reasoning_prefilled_survives_deeply_nested_json() -> None:
|
||||
# Deep enough for json.loads to raise RecursionError on every supported Python.
|
||||
depth = 100_000
|
||||
content = "[" * depth + '"</think>"' + "]" * depth
|
||||
assert strip_reasoning(content, prefilled=True) == '"' + "]" * depth
|
||||
assert strip_reasoning(content, prefilled=True) == content
|
||||
|
||||
|
||||
def _openai_provider(content: str, **kwargs: Any) -> OpenAIProvider:
|
||||
|
||||
Reference in New Issue
Block a user