Skip to content

Commit

Permalink
tasks.py: don't call Converter when model response is valid (#406)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ftoppi authored Apr 4, 2024
1 parent 3848622 commit 8ed4c66
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/crewai/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ def _export_output(self, result: str) -> Any:

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):
Expand Down

0 comments on commit 8ed4c66

Please sign in to comment.