Add docs for crewoutput and taskoutput (#943)

* Add docs for crewoutput and taskoutput

* Add reference to change log
This commit is contained in:
Brandon Hancock (bhancock_ai)
2024-07-15 20:39:15 -04:00
committed by GitHub
parent dd8a199e99
commit ac2815c781
5 changed files with 166 additions and 70 deletions

View File

@@ -24,16 +24,6 @@ class CrewOutput(BaseModel):
description="Processed token summary", default={}
)
# @property
# def pydantic(self) -> Optional[BaseModel]:
# # Check if the final task output included a pydantic model
# if self.tasks_output[-1].output_format != OutputFormat.PYDANTIC:
# raise ValueError(
# "No pydantic model found in the final task. Please make sure to set the output_pydantic property in the final task in your crew."
# )
# return self._pydantic
@property
def json(self) -> Optional[str]:
if self.tasks_output[-1].output_format != OutputFormat.JSON:
@@ -44,11 +34,13 @@ class CrewOutput(BaseModel):
return json.dumps(self.json_dict)
def to_dict(self) -> Dict[str, Any]:
"""Convert json_output and pydantic_output to a dictionary."""
output_dict = {}
if self.json_dict:
return self.json_dict
if self.pydantic:
return self.pydantic.model_dump()
raise ValueError("No output to convert to dictionary")
output_dict.update(self.json_dict)
elif self.pydantic:
output_dict.update(self.pydantic.model_dump())
return output_dict
def __str__(self):
if self.pydantic:

View File

@@ -30,20 +30,6 @@ class TaskOutput(BaseModel):
self.summary = f"{excerpt}..."
return self
# @property
# def pydantic(self) -> Optional[BaseModel]:
# # Check if the final task output included a pydantic model
# if self.output_format != OutputFormat.PYDANTIC:
# raise ValueError(
# """
# Invalid output format requested.
# If you would like to access the pydantic model,
# please make sure to set the output_pydantic property for the task.
# """
# )
# return self._pydantic
@property
def json(self) -> Optional[str]:
if self.output_format != OutputFormat.JSON:
@@ -62,7 +48,7 @@ class TaskOutput(BaseModel):
output_dict = {}
if self.json_dict:
output_dict.update(self.json_dict)
if self.pydantic:
elif self.pydantic:
output_dict.update(self.pydantic.model_dump())
return output_dict