Skip to content

Commit 05f954b

Browse files
fixed pydantic error
1 parent 591ae35 commit 05f954b

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: [3.11]
15+
python-version: [3.11, 3.12, 3.13]
1616

1717
steps:
1818
- name: Checkout

backend/api/routers/predict.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ async def predict_caloric_needs(
4545
raise HTTPException(status_code=500, detail="Model loader not initialized")
4646

4747
try:
48-
# Convert Pydantic model to dict
49-
input_dict = input_data.dict()
48+
# Convert Pydantic model to dict (use model_dump for Pydantic v2)
49+
# `model_dump` is the v2 replacement for `.dict()` and returns a dict.
50+
input_dict = input_data.model_dump()
5051

5152
# Make prediction
5253
result = model_loader.predict(input_dict, model_preference=model)
@@ -89,7 +90,7 @@ async def batch_predict(
8990

9091
for input_data in batch_input.inputs:
9192
try:
92-
input_dict = input_data.dict()
93+
input_dict = input_data.model_dump()
9394
result = model_loader.predict(input_dict, model_preference=model_pref)
9495
results.append(result)
9596

backend/tests/test_loader_and_api.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
from fastapi.testclient import TestClient
1010

1111

12-
def make_dummy_model(pred_value=123.45, feature_names=None):
13-
class DummyModel:
14-
def __init__(self, v, cols=None):
15-
self._v = v
16-
if cols is not None:
17-
# mimic scikit-learn attribute
18-
self.feature_names_in_ = cols
12+
class DummyModel:
13+
def __init__(self, v, cols=None):
14+
self._v = v
15+
if cols is not None:
16+
# mimic scikit-learn attribute
17+
self.feature_names_in_ = cols
18+
19+
def predict(self, X):
20+
# return array-like
21+
return [self._v] * len(X)
1922

20-
def predict(self, X):
21-
# return array-like
22-
return [self._v] * len(X)
2323

24+
def make_dummy_model(pred_value=123.45, feature_names=None):
2425
return DummyModel(pred_value, feature_names)
2526

2627

0 commit comments

Comments
 (0)