Skip to content

Commit e682138

Browse files
committed
Pydantic 2 upgrade for root model
1 parent 1a9076a commit e682138

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/clip_api_service/service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Item(BaseItem):
3131

3232

3333
class ItemList(ListModel):
34-
__root__: List[Item]
34+
root: List[Item]
3535

3636

3737
class RankInput(BaseItem):
@@ -43,7 +43,6 @@ class RankOutput(BaseItem):
4343
probabilities: List[List[float]]
4444
cosine_similarities: List[List[float]]
4545

46-
4746
bento_model = init_model()
4847
logit_scale = np.exp(bento_model.info.metadata.get("logit_scale", 4.60517))
4948

src/clip_api_service/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
from bentoml.exceptions import BadInput
1010
from PIL import Image
11-
from pydantic import BaseModel
11+
from pydantic import BaseModel, RootModel
1212

1313

1414
def base64_to_image(base64_string: str) -> Image:
@@ -56,14 +56,14 @@ def dict(self, *args, **kwargs) -> dict[str, Any]:
5656
return super().dict(*args, exclude_none=True, **kwargs)
5757

5858

59-
class ListModel(BaseItem):
60-
__root__: List[Any]
59+
class ListModel(RootModel):
60+
root: List[Any]
6161

6262
def __iter__(self):
63-
return iter(self.__root__)
63+
return iter(self.root)
6464

6565
def __getitem__(self, item):
66-
return self.__root__[item]
66+
return self.root[item]
6767

6868
def append(self, item):
69-
return self.__root__.append(item)
69+
return self.root.append(item)

0 commit comments

Comments
 (0)