refac/fix: base model cache

This commit is contained in:
Timothy Jaeryang Baek 2025-07-07 11:30:27 +04:00
parent 31c63d8898
commit 05a9b72670

View file

@ -82,10 +82,13 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
and request.app.state.BASE_MODELS and request.app.state.BASE_MODELS
and (request.app.state.config.ENABLE_BASE_MODELS_CACHE and not refresh) and (request.app.state.config.ENABLE_BASE_MODELS_CACHE and not refresh)
): ):
models = request.app.state.BASE_MODELS base_models = request.app.state.BASE_MODELS
else: else:
models = await get_all_base_models(request, user=user) base_models = await get_all_base_models(request, user=user)
request.app.state.BASE_MODELS = models request.app.state.BASE_MODELS = base_models
# deep copy the base models to avoid modifying the original list
models = [model.copy() for model in base_models]
# If there are no models, return an empty list # If there are no models, return an empty list
if len(models) == 0: if len(models) == 0:
@ -145,6 +148,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
custom_models = Models.get_all_models() custom_models = Models.get_all_models()
for custom_model in custom_models: for custom_model in custom_models:
if custom_model.base_model_id is None: if custom_model.base_model_id is None:
# Applied directly to a base model
for model in models: for model in models:
if custom_model.id == model["id"] or ( if custom_model.id == model["id"] or (
model.get("owned_by") == "ollama" model.get("owned_by") == "ollama"