refactor: improve parsing logic in structured output parser

- Updated the logic for handling lists in the parsing process to ensure only dictionary items are considered, enhancing robustness.
- Maintained existing functionality while improving the clarity and reliability of the output parsing.
This commit is contained in:
Yeuoly 2025-06-26 17:18:23 +08:00
parent 0e3f902992
commit 9dade0ad5a

View File

@ -250,7 +250,7 @@ def _parse_structured_output(result_text: str) -> Mapping[str, Any]:
if not isinstance(temp_parsed, dict):
# handle reasoning model like deepseek-r1 got '<think>\n\n</think>\n' prefix
if isinstance(temp_parsed, list):
temp_parsed = next((item for item in parsed if isinstance(item, dict)), {})
temp_parsed = next((item for item in temp_parsed if isinstance(item, dict)), {})
else:
raise OutputParserError(f"Failed to parse structured output: {result_text}")
structured_output = cast(dict, temp_parsed)