Skip to content

Commit dc885f7

Browse files
hotfix predict endpoint caching
1 parent a087210 commit dc885f7

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ clean:
4747
find . -type d -name ".pytest_cache" -exec rm -rf {} +
4848
find . -type d -name ".ruff_cache" -exec rm -rf {} +
4949
find . -type f -name "*.pyc" -delete
50+
rm -rf model_cache
51+
rm -rf mlruns
5052
- docker rmi $(IMAGE_NAME)
5153

5254
install:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "intent-service"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
description = "Intent classification service"
55
readme = "README.md"
66
requires-python = ">=3.10"

src/api/endpoints.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,17 @@ async def predict(model_id: str, text: str) -> dict:
751751
os.makedirs("model_cache", exist_ok=True)
752752
dst_path = f"model_cache/{model_id}"
753753
if model_id in os.listdir("model_cache"):
754+
if "intent_model" in os.listdir(dst_path):
755+
dst_path = dst_path + "/intent_model"
754756
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))
757+
loaded_model = mlflow.pyfunc.load_model(dst_path)
758+
except mlflow.exceptions.MlflowException:
759+
os.rmdir(dst_path)
760+
raise HTTPException(
761+
status_code=404,
762+
detail=f"No model found with ID {model_id} (tried both registered models and runs)",
763+
)
764+
758765
else:
759766
os.makedirs(dst_path, exist_ok=True)
760767
try:
@@ -770,6 +777,7 @@ async def predict(model_id: str, text: str) -> dict:
770777
dst_path=dst_path,
771778
)
772779
except mlflow.exceptions.MlflowException:
780+
os.rmdir(dst_path)
773781
raise HTTPException(
774782
status_code=404,
775783
detail=f"No model found with ID {model_id} (tried both registered models and runs)",

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)