From f6a65486f17805a60219726be59191148af80c68 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:27:57 +0000 Subject: [PATCH] fix: Update json and model_dump_json signatures to match BaseModel Co-Authored-By: Joe Moura --- src/crewai/crews/crew_output.py | 19 ++++++++++++++----- src/crewai/tasks/task_output.py | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/crewai/crews/crew_output.py b/src/crewai/crews/crew_output.py index 9864088e2..4d16cbc5d 100644 --- a/src/crewai/crews/crew_output.py +++ b/src/crewai/crews/crew_output.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, Optional, Set, Union +from typing import Any, Callable, Dict, Optional, Set, Union from pydantic import BaseModel, Field from typing_extensions import Literal @@ -27,8 +27,19 @@ class CrewOutput(BaseModel): ) token_usage: UsageMetrics = Field(description="Processed token summary", default={}) - @property - def json(self) -> str: + def json( + self, + *, + include: Optional[IncEx] = None, + exclude: Optional[IncEx] = None, + by_alias: bool = False, + exclude_unset: bool = False, + exclude_defaults: bool = False, + exclude_none: bool = False, + encoder: Optional[Callable[[Any], Any]] = None, + models_as_dict: bool = True, + **dumps_kwargs: Any, + ) -> str: """Get the JSON representation of the output.""" if self.tasks_output and self.tasks_output[-1].output_format != OutputFormat.JSON: raise ValueError( @@ -42,14 +53,12 @@ class CrewOutput(BaseModel): indent: Optional[int] = None, include: Optional[IncEx] = None, exclude: Optional[IncEx] = None, - context: Optional[Any] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool | Literal["none", "warn", "error"] = False, - serialize_as_any: bool = False, ) -> str: """Override model_dump_json to handle custom JSON output.""" return super().model_dump_json( diff --git a/src/crewai/tasks/task_output.py b/src/crewai/tasks/task_output.py index 6e3aa42f0..5a1444a49 100644 --- a/src/crewai/tasks/task_output.py +++ b/src/crewai/tasks/task_output.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, Optional, Set, Union +from typing import Any, Callable, Dict, Optional, Set, Union from pydantic import BaseModel, Field, model_validator from typing_extensions import Literal @@ -38,8 +38,19 @@ class TaskOutput(BaseModel): self.summary = f"{excerpt}..." return self - @property - def json(self) -> str: + def json( + self, + *, + include: Optional[IncEx] = None, + exclude: Optional[IncEx] = None, + by_alias: bool = False, + exclude_unset: bool = False, + exclude_defaults: bool = False, + exclude_none: bool = False, + encoder: Optional[Callable[[Any], Any]] = None, + models_as_dict: bool = True, + **dumps_kwargs: Any, + ) -> str: """Get the JSON representation of the output.""" if self.output_format != OutputFormat.JSON: raise ValueError( @@ -57,14 +68,12 @@ class TaskOutput(BaseModel): indent: Optional[int] = None, include: Optional[IncEx] = None, exclude: Optional[IncEx] = None, - context: Optional[Any] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool | Literal["none", "warn", "error"] = False, - serialize_as_any: bool = False, ) -> str: """Override model_dump_json to handle custom JSON output.""" return super().model_dump_json(