Remove model inheritance (#30)

This commit is contained in:
Greyson LaLonde
2023-12-31 08:52:08 -05:00
committed by GitHub
parent 1f0001b644
commit e41844334e
3 changed files with 62 additions and 8 deletions

View File

@@ -1,14 +1,16 @@
import uuid
from typing import Any, List, Optional
from pydantic import Field, model_validator
from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
from pydantic_core import PydanticCustomError
from crewai.agent import Agent
from crewai.base.model import CrewAIBaseModel
class Task(CrewAIBaseModel):
class Task(BaseModel):
"""Class that represent a task to be executed."""
__hash__ = object.__hash__
description: str = Field(description="Description of the actual task.")
agent: Optional[Agent] = Field(
description="Agent responsible for the task.", default=None
@@ -17,6 +19,19 @@ class Task(CrewAIBaseModel):
default_factory=list,
description="Tools the agent are limited to use for this task.",
)
id: UUID4 = Field(
default_factory=uuid.uuid4,
frozen=True,
description="Unique identifier for the object, not set by user.",
)
@field_validator("id", mode="before")
@classmethod
def _deny_user_set_id(cls, v: Optional[UUID4]) -> None:
if v:
raise PydanticCustomError(
"may_not_set_field", "This field is not to be set by the user.", {}
)
@model_validator(mode="after")
def check_tools(self):