This commit is contained in:
Brandon Hancock
2024-07-08 20:04:27 -04:00
parent 363ce5e9ce
commit fffe4df8c3
3 changed files with 16 additions and 2 deletions

View File

@@ -459,7 +459,7 @@ class Crew(BaseModel):
self._file_handler.log(
agent=role, task=task.description, status="started"
)
# TODO: IF USER OVERRIDE THE CONTEXT, PASS THAT
if task.async_execution:
context = aggregate_raw_outputs_from_task_outputs(task_outputs)
future = task.execute_async(

View File

@@ -8,6 +8,7 @@ from crewai.utilities.formatter import aggregate_raw_outputs_from_task_outputs
class CrewOutput(BaseModel):
output: List[TaskOutput] = Field(description="Result of the final task")
# TODO: TYPED OUTPUT
tasks_output: list[TaskOutput] = Field(
description="Output of each task", default=[]
)
@@ -15,14 +16,24 @@ class CrewOutput(BaseModel):
description="Processed token summary", default={}
)
# TODO: Support 1 output by default
# TODO: GIVE THEM THE OPTION TO ACCESS
# TODO: RESULT get's back a string
# TODO: Ask @joao what is the desired behavior here
def result(
self,
) -> List[str | BaseModel | Dict[str, Any]]:
"""Return the result of the task based on the available output."""
if len(self.output) == 1:
return self.output[0].result()
results = [output.result() for output in self.output]
return results
# TODO: RESULT PYDANTIC
# TODO: RESULT JSON D
def raw_output(self) -> str:
"""Return the raw output of the task."""
return aggregate_raw_outputs_from_task_outputs(self.output)
@@ -41,4 +52,5 @@ class CrewOutput(BaseModel):
# TODO: Confirm with Joao that we want to print the raw output and not the object
def __str__(self):
# TODO: GRAB LAST TASK AND CALL RESULT ON IT.
return str(self.raw_output())

View File

@@ -7,6 +7,8 @@ from pydantic import BaseModel, Field, model_validator
class TaskOutput(BaseModel):
"""Class that represents the result of a task."""
# TODO: MAKE SURE TO FULLY SUPPORT OUTPUT FILE
description: str = Field(description="Description of the task")
summary: Optional[str] = Field(description="Summary of the task", default=None)
raw_output: str = Field(description="Result of the task")
@@ -43,7 +45,7 @@ class TaskOutput(BaseModel):
return self.json_output[key]
raise KeyError(f"Key '{key}' not found in pydantic_output or json_output")
def to_output_dict(self) -> Dict[str, Any]:
def to_dict(self) -> Dict[str, Any]:
"""Convert json_output and pydantic_output to a dictionary."""
output_dict = {}
if self.json_output: