chore: apply ruff linting fixes to crews module

This commit is contained in:
Greyson LaLonde
2025-09-19 22:02:22 -04:00
committed by GitHub
parent 8e571ea8a7
commit 24b84a4b68

View File

@@ -1,5 +1,5 @@
import json import json
from typing import Any, Dict, Optional from typing import Any
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@@ -12,19 +12,21 @@ class CrewOutput(BaseModel):
"""Class that represents the result of a crew.""" """Class that represents the result of a crew."""
raw: str = Field(description="Raw output of crew", default="") raw: str = Field(description="Raw output of crew", default="")
pydantic: Optional[BaseModel] = Field( pydantic: BaseModel | None = Field(
description="Pydantic output of Crew", default=None description="Pydantic output of Crew", default=None
) )
json_dict: Optional[Dict[str, Any]] = Field( json_dict: dict[str, Any] | None = Field(
description="JSON dict output of Crew", default=None description="JSON dict output of Crew", default=None
) )
tasks_output: list[TaskOutput] = Field( tasks_output: list[TaskOutput] = Field(
description="Output of each task", default=[] description="Output of each task", default=[]
) )
token_usage: UsageMetrics = Field(description="Processed token summary", default={}) token_usage: UsageMetrics = Field(
description="Processed token summary", default_factory=UsageMetrics
)
@property @property
def json(self) -> Optional[str]: def json(self) -> str | None: # type: ignore[override]
if self.tasks_output[-1].output_format != OutputFormat.JSON: if self.tasks_output[-1].output_format != OutputFormat.JSON:
raise ValueError( raise ValueError(
"No JSON output found in the final task. Please make sure to set the output_json property in the final task in your crew." "No JSON output found in the final task. Please make sure to set the output_json property in the final task in your crew."
@@ -32,7 +34,7 @@ class CrewOutput(BaseModel):
return json.dumps(self.json_dict) return json.dumps(self.json_dict)
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> dict[str, Any]:
"""Convert json_output and pydantic_output to a dictionary.""" """Convert json_output and pydantic_output to a dictionary."""
output_dict = {} output_dict = {}
if self.json_dict: if self.json_dict:
@@ -44,10 +46,9 @@ class CrewOutput(BaseModel):
def __getitem__(self, key): def __getitem__(self, key):
if self.pydantic and hasattr(self.pydantic, key): if self.pydantic and hasattr(self.pydantic, key):
return getattr(self.pydantic, key) return getattr(self.pydantic, key)
elif self.json_dict and key in self.json_dict: if self.json_dict and key in self.json_dict:
return self.json_dict[key] return self.json_dict[key]
else: raise KeyError(f"Key '{key}' not found in CrewOutput.")
raise KeyError(f"Key '{key}' not found in CrewOutput.")
def __str__(self): def __str__(self):
if self.pydantic: if self.pydantic: