mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac
This commit is contained in:
parent
1b064a6c85
commit
962e078a9a
2 changed files with 196 additions and 192 deletions
|
|
@ -1248,12 +1248,7 @@ async def get_models(
|
||||||
|
|
||||||
return filtered_models
|
return filtered_models
|
||||||
|
|
||||||
if request.app.state.MODELS and (
|
all_models = await get_all_models(request, refresh=refresh, user=user)
|
||||||
request.app.state.config.ENABLE_MODEL_LIST_CACHE and not refresh
|
|
||||||
):
|
|
||||||
all_models = list(request.app.state.MODELS.values())
|
|
||||||
else:
|
|
||||||
all_models = await get_all_models(request, user=user)
|
|
||||||
|
|
||||||
models = []
|
models = []
|
||||||
for model in all_models:
|
for model in all_models:
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,12 @@ async def get_all_base_models(request: Request, user: UserModel = None):
|
||||||
return function_models + openai_models + ollama_models
|
return function_models + openai_models + ollama_models
|
||||||
|
|
||||||
|
|
||||||
async def get_all_models(request, user: UserModel = None):
|
async def get_all_models(request, refresh: bool = False, user: UserModel = None):
|
||||||
|
if request.app.state.MODELS and (
|
||||||
|
request.app.state.config.ENABLE_MODEL_LIST_CACHE and not refresh
|
||||||
|
):
|
||||||
|
return list(request.app.state.MODELS.values())
|
||||||
|
else:
|
||||||
models = await get_all_base_models(request, user=user)
|
models = await get_all_base_models(request, user=user)
|
||||||
|
|
||||||
# If there are no models, return an empty list
|
# If there are no models, return an empty list
|
||||||
|
|
@ -260,12 +265,16 @@ async def get_all_models(request, user: UserModel = None):
|
||||||
for model in models:
|
for model in models:
|
||||||
action_ids = [
|
action_ids = [
|
||||||
action_id
|
action_id
|
||||||
for action_id in list(set(model.pop("action_ids", []) + global_action_ids))
|
for action_id in list(
|
||||||
|
set(model.pop("action_ids", []) + global_action_ids)
|
||||||
|
)
|
||||||
if action_id in enabled_action_ids
|
if action_id in enabled_action_ids
|
||||||
]
|
]
|
||||||
filter_ids = [
|
filter_ids = [
|
||||||
filter_id
|
filter_id
|
||||||
for filter_id in list(set(model.pop("filter_ids", []) + global_filter_ids))
|
for filter_id in list(
|
||||||
|
set(model.pop("filter_ids", []) + global_filter_ids)
|
||||||
|
)
|
||||||
if filter_id in enabled_filter_ids
|
if filter_id in enabled_filter_ids
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue