Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align with pydantic v2, @validator -> @field_validator and class Config -> model_config #225

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions models/llama3/api/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from enum import Enum
from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field, field_validator

from typing_extensions import Annotated
from ...datatypes import * # noqa
Expand Down Expand Up @@ -44,8 +44,7 @@ def __str__(self) -> str:
class ImageMedia(BaseModel):
image: Union[PIL_Image.Image, URL]

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)


InterleavedTextMedia = Union[
Expand Down Expand Up @@ -117,7 +116,7 @@ class ToolCall(BaseModel):
tool_name: Union[BuiltinTool, str]
arguments: Dict[str, RecursiveType]

@validator("tool_name", pre=True)
@field_validator("tool_name", mode="before")
@classmethod
def validate_field(cls, v):
if isinstance(v, str):
Expand All @@ -134,7 +133,7 @@ class ToolResponse(BaseModel):
tool_name: Union[BuiltinTool, str]
content: InterleavedTextMedia

@validator("tool_name", pre=True)
@field_validator("tool_name", mode="before")
@classmethod
def validate_field(cls, v):
if isinstance(v, str):
Expand All @@ -159,7 +158,7 @@ class ToolDefinition(BaseModel):
description: Optional[str] = None
parameters: Optional[Dict[str, ToolParamDefinition]] = None

@validator("tool_name", pre=True)
@field_validator("tool_name", mode="before")
@classmethod
def validate_field(cls, v):
if isinstance(v, str):
Expand Down
Loading