mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user