diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 9e02393d9..d704238b4 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -522,8 +522,11 @@ async def generate_chat_completion( payload = apply_model_params_to_body_openai(params, payload) payload = apply_model_system_prompt_to_body(params, payload, user) - model = app.state.MODELS[payload.get("model")] - idx = model["urlIdx"] + try: + model = app.state.MODELS[payload.get("model")] + idx = model["urlIdx"] + except Exception as e: + raise HTTPException(status_code=404, detail="Model not found") api_config = app.state.config.OPENAI_API_CONFIGS.get( app.state.config.OPENAI_API_BASE_URLS[idx], {} diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 53dc01cf8..aa3e0437a 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1005,66 +1005,57 @@ async def get_all_models(): } ) - for model in models: - action_ids = [] - if "action_ids" in model: - action_ids = model["action_ids"] - del model["action_ids"] + # Process action_ids to get the actions + def get_action_items_from_module(module): + actions = [] + if hasattr(module, "actions"): + actions = module.actions + return [ + { + "id": f"{module.id}.{action['id']}", + "name": action.get("name", f"{module.name} ({action['id']})"), + "description": module.meta.description, + "icon_url": action.get( + "icon_url", module.meta.manifest.get("icon_url", None) + ), + } + for action in actions + ] + else: + return [ + { + "id": module.id, + "name": module.name, + "description": module.meta.description, + "icon_url": module.meta.manifest.get("icon_url", None), + } + ] - action_ids = action_ids + global_action_ids - action_ids = list(set(action_ids)) + def get_function_module_by_id(function_id): + if function_id in webui_app.state.FUNCTIONS: + function_module = webui_app.state.FUNCTIONS[function_id] + else: + function_module, _, _ = load_function_module_by_id(function_id) + webui_app.state.FUNCTIONS[function_id] = function_module + + for model in models: action_ids = [ - action_id for action_id in action_ids if action_id in enabled_action_ids + action_id + for action_id in list(set(model.pop("action_ids", []) + global_action_ids)) + if action_id in enabled_action_ids ] model["actions"] = [] for action_id in action_ids: - action = Functions.get_function_by_id(action_id) - if action is None: + action_function = Functions.get_function_by_id(action_id) + if action_function is None: raise Exception(f"Action not found: {action_id}") - if action_id in webui_app.state.FUNCTIONS: - function_module = webui_app.state.FUNCTIONS[action_id] - else: - function_module, _, _ = load_function_module_by_id(action_id) - webui_app.state.FUNCTIONS[action_id] = function_module - - __webui__ = False - if hasattr(function_module, "__webui__"): - __webui__ = function_module.__webui__ - - if hasattr(function_module, "actions"): - actions = function_module.actions - model["actions"].extend( - [ - { - "id": f"{action_id}.{_action['id']}", - "name": _action.get( - "name", f"{action.name} ({_action['id']})" - ), - "description": action.meta.description, - "icon_url": _action.get( - "icon_url", action.meta.manifest.get("icon_url", None) - ), - **({"__webui__": __webui__} if __webui__ else {}), - } - for _action in actions - ] - ) - else: - model["actions"].append( - { - "id": action_id, - "name": action.name, - "description": action.meta.description, - "icon_url": action.meta.manifest.get("icon_url", None), - **({"__webui__": __webui__} if __webui__ else {}), - } - ) + function_module = get_function_module_by_id(action_id) + model["actions"].extend(get_action_items_from_module(function_module)) app.state.MODELS = {model["id"]: model for model in models} webui_app.state.MODELS = app.state.MODELS - return models @@ -1163,6 +1154,10 @@ async def generate_chat_completions( "selected_model_id": selected_model_id, } + if model_id.startswith("open-webui-"): + model_id = model_id[len("open-webui-") :] + form_data["model"] = model_id + if model.get("pipe"): # Below does not require bypass_filter because this is the only route the uses this function and it is already bypassing the filter return await generate_function_chat_completion(form_data, user=user) diff --git a/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte b/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte index 06736fae7..42e436c15 100644 --- a/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte +++ b/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte @@ -524,7 +524,7 @@ }} /> - +
diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 6db343b68..ed6628d52 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -1125,19 +1125,17 @@ showRateComment = false; regenerateResponse(message); - (model?.actions ?? []) - .filter((action) => action?.__webui__ ?? false) - .forEach((action) => { - dispatch('action', { - id: action.id, - event: { - id: 'regenerate-response', - data: { - messageId: message.id - } + (model?.actions ?? []).forEach((action) => { + dispatch('action', { + id: action.id, + event: { + id: 'regenerate-response', + data: { + messageId: message.id } - }); + } }); + }); }} > {:else} - {#if $user?.role === 'admin'} + {#if $user?.role === 'admin' || model.user_id === $user?.id}
- {#if !edit || model.preset} + {#if preset}
{$i18n.t('Base Model (From)')}
diff --git a/src/lib/components/workspace/common/AccessPermissionsModal.svelte b/src/lib/components/workspace/common/AccessPermissionsModal.svelte index 37bbf08e0..5491f0d7e 100644 --- a/src/lib/components/workspace/common/AccessPermissionsModal.svelte +++ b/src/lib/components/workspace/common/AccessPermissionsModal.svelte @@ -39,7 +39,7 @@
-
{$i18n.t('General access')}
+
{$i18n.t('Visibility')}
diff --git a/src/routes/(app)/workspace/models/create/+page.svelte b/src/routes/(app)/workspace/models/create/+page.svelte index 948c04419..e90dd0052 100644 --- a/src/routes/(app)/workspace/models/create/+page.svelte +++ b/src/routes/(app)/workspace/models/create/+page.svelte @@ -31,6 +31,9 @@ : null }, params: { ...modelInfo.params } + }).catch((error) => { + toast.error(error); + return null; }); if (res) {