refactor: streamline result processing in structured output parser

- Converted the result processing logic into a generator function for improved memory efficiency and clarity.
- Maintained the existing functionality while enhancing the structure of the code for better readability.
pull/21565/head
Yeuoly 11 months ago
parent 79290687bf
commit ade1e8a120

@ -142,6 +142,8 @@ def invoke_llm_with_structured_output(
prompt_messages=llm_result.prompt_messages, prompt_messages=llm_result.prompt_messages,
) )
else: else:
def generator():
result_text = "" result_text = ""
for event in llm_result: for event in llm_result:
if isinstance(event, LLMResultChunk): if isinstance(event, LLMResultChunk):
@ -150,6 +152,8 @@ def invoke_llm_with_structured_output(
yield LLMStructuredOutput(structured_output=_parse_structured_output(result_text)) yield LLMStructuredOutput(structured_output=_parse_structured_output(result_text))
return generator()
def _handle_native_json_schema( def _handle_native_json_schema(
provider: str, provider: str,

Loading…
Cancel
Save