mirror of
https://github.com/langgenius/dify.git
synced 2025-06-27 05:30:04 +00:00
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:
parent
0e3f902992
commit
9dade0ad5a
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user