Skip to content

Commit

Permalink
Fix pydantic 2 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
8W9aG committed Oct 9, 2024
1 parent 272756f commit 1a8a374
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
17 changes: 10 additions & 7 deletions python/cog/base_input.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from pathlib import Path

import pydantic
from pydantic import BaseModel

from .types import (
URLPath,
)
from .types import PYDANTIC_V2, URLPath


# Base class for inputs, constructed dynamically in get_input_type().
# (This can't be a docstring or it gets passed through to the schema.)
class BaseInput(BaseModel):
class Config:
# When using `choices`, the type is converted into an enum to validate
# But, after validation, we want to pass the actual value to predict(), not the enum object
use_enum_values = True
if PYDANTIC_V2:
model_config = pydantic.ConfigDict(use_enum_values=True) # type: ignore
else:

class Config:
# When using `choices`, the type is converted into an enum to validate
# But, after validation, we want to pass the actual value to predict(), not the enum object
use_enum_values = True

def cleanup(self) -> None:
"""
Expand Down
11 changes: 1 addition & 10 deletions python/cog/server/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@
from ..json import upload_files
from ..logging import setup_logging
from ..mode import Mode
from ..predictor import (
get_input_type,
get_output_type,
get_predictor_ref,
get_training_input_type,
get_training_output_type,
load_config,
load_slim_predictor_from_ref,
)
from ..types import PYDANTIC_V2, CogConfig
from ..types import PYDANTIC_V2

if PYDANTIC_V2:
from .helpers import (
Expand Down

0 comments on commit 1a8a374

Please sign in to comment.