mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
fix: Update json and model_dump_json signatures to match BaseModel
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import json
|
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 pydantic import BaseModel, Field
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
@@ -27,8 +27,19 @@ class CrewOutput(BaseModel):
|
|||||||
)
|
)
|
||||||
token_usage: UsageMetrics = Field(description="Processed token summary", default={})
|
token_usage: UsageMetrics = Field(description="Processed token summary", default={})
|
||||||
|
|
||||||
@property
|
def json(
|
||||||
def json(self) -> str:
|
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."""
|
"""Get the JSON representation of the output."""
|
||||||
if self.tasks_output and self.tasks_output[-1].output_format != OutputFormat.JSON:
|
if self.tasks_output and self.tasks_output[-1].output_format != OutputFormat.JSON:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@@ -42,14 +53,12 @@ class CrewOutput(BaseModel):
|
|||||||
indent: Optional[int] = None,
|
indent: Optional[int] = None,
|
||||||
include: Optional[IncEx] = None,
|
include: Optional[IncEx] = None,
|
||||||
exclude: Optional[IncEx] = None,
|
exclude: Optional[IncEx] = None,
|
||||||
context: Optional[Any] = None,
|
|
||||||
by_alias: bool = False,
|
by_alias: bool = False,
|
||||||
exclude_unset: bool = False,
|
exclude_unset: bool = False,
|
||||||
exclude_defaults: bool = False,
|
exclude_defaults: bool = False,
|
||||||
exclude_none: bool = False,
|
exclude_none: bool = False,
|
||||||
round_trip: bool = False,
|
round_trip: bool = False,
|
||||||
warnings: bool | Literal["none", "warn", "error"] = False,
|
warnings: bool | Literal["none", "warn", "error"] = False,
|
||||||
serialize_as_any: bool = False,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Override model_dump_json to handle custom JSON output."""
|
"""Override model_dump_json to handle custom JSON output."""
|
||||||
return super().model_dump_json(
|
return super().model_dump_json(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import json
|
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 pydantic import BaseModel, Field, model_validator
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
@@ -38,8 +38,19 @@ class TaskOutput(BaseModel):
|
|||||||
self.summary = f"{excerpt}..."
|
self.summary = f"{excerpt}..."
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
def json(
|
||||||
def json(self) -> str:
|
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."""
|
"""Get the JSON representation of the output."""
|
||||||
if self.output_format != OutputFormat.JSON:
|
if self.output_format != OutputFormat.JSON:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@@ -57,14 +68,12 @@ class TaskOutput(BaseModel):
|
|||||||
indent: Optional[int] = None,
|
indent: Optional[int] = None,
|
||||||
include: Optional[IncEx] = None,
|
include: Optional[IncEx] = None,
|
||||||
exclude: Optional[IncEx] = None,
|
exclude: Optional[IncEx] = None,
|
||||||
context: Optional[Any] = None,
|
|
||||||
by_alias: bool = False,
|
by_alias: bool = False,
|
||||||
exclude_unset: bool = False,
|
exclude_unset: bool = False,
|
||||||
exclude_defaults: bool = False,
|
exclude_defaults: bool = False,
|
||||||
exclude_none: bool = False,
|
exclude_none: bool = False,
|
||||||
round_trip: bool = False,
|
round_trip: bool = False,
|
||||||
warnings: bool | Literal["none", "warn", "error"] = False,
|
warnings: bool | Literal["none", "warn", "error"] = False,
|
||||||
serialize_as_any: bool = False,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Override model_dump_json to handle custom JSON output."""
|
"""Override model_dump_json to handle custom JSON output."""
|
||||||
return super().model_dump_json(
|
return super().model_dump_json(
|
||||||
|
|||||||
Reference in New Issue
Block a user