tasks.py: don't call Converter when model response is valid (#406)

* tasks.py: don't call Converter when model response is valid

Try to convert the task output to the expected Pydantic model before sending it to Converter, maybe the model got it right.
This commit is contained in:
ftoppi
2024-04-04 15:11:46 +02:00
committed by GitHub
parent 2edc824b61
commit ce9c343c0a

View File

@@ -221,6 +221,16 @@ class Task(BaseModel):
if self.output_pydantic or self.output_json:
model = self.output_pydantic or self.output_json
# try to convert task_output directly to pydantic/json
try:
exported_result = model.model_validate_json(result)
if self.output_json:
return exported_result.model_dump()
return exported_result
except Exception:
pass
llm = self.agent.function_calling_llm or self.agent.llm
if not self._is_gpt(llm):