Skip to content

Commit ba4cc07

Browse files
update to allow local model cache for prediction
1 parent a3ed8f2 commit ba4cc07

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,5 @@ Next steps
225225
To learn more about publishing packages, check out the PyPA guides on building and publishing.
226226

227227
Or, read on for guides on integrating uv with other software.
228-
.ruff_cache/
228+
.ruff_cache/
229+
model_cache/

src/api/endpoints.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,14 @@ async def predict(model_id: str, text: str) -> dict:
747747
"""
748748
try:
749749
# First try loading as a registered model
750+
if "model_cache" not in os.listdir():
751+
os.makedirs("model_cache", exist_ok=True)
750752
dst_path = f"model_cache/{model_id}"
751753
if model_id in os.listdir("model_cache"):
752-
loaded_model = mlflow.pyfunc.load_model(dst_path)
754+
try:
755+
loaded_model = mlflow.pyfunc.load_model(dst_path + "/intent_model")
756+
except mlflow.exceptions.MlflowException as e:
757+
raise HTTPException(status_code=500, detail=str(e))
753758
else:
754759
os.makedirs(dst_path, exist_ok=True)
755760
try:

0 commit comments

Comments
 (0)