mirror of
https://github.com/open-webui/open-webui
synced 2025-05-15 11:06:15 +00:00
refac
This commit is contained in:
parent
bf2087c67b
commit
a0f1164af7
@ -522,8 +522,11 @@ async def generate_chat_completion(
|
|||||||
payload = apply_model_params_to_body_openai(params, payload)
|
payload = apply_model_params_to_body_openai(params, payload)
|
||||||
payload = apply_model_system_prompt_to_body(params, payload, user)
|
payload = apply_model_system_prompt_to_body(params, payload, user)
|
||||||
|
|
||||||
|
try:
|
||||||
model = app.state.MODELS[payload.get("model")]
|
model = app.state.MODELS[payload.get("model")]
|
||||||
idx = model["urlIdx"]
|
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(
|
api_config = app.state.config.OPENAI_API_CONFIGS.get(
|
||||||
app.state.config.OPENAI_API_BASE_URLS[idx], {}
|
app.state.config.OPENAI_API_BASE_URLS[idx], {}
|
||||||
|
@ -1005,66 +1005,57 @@ async def get_all_models():
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for model in models:
|
# Process action_ids to get the actions
|
||||||
action_ids = []
|
def get_action_items_from_module(module):
|
||||||
if "action_ids" in model:
|
actions = []
|
||||||
action_ids = model["action_ids"]
|
if hasattr(module, "actions"):
|
||||||
del model["action_ids"]
|
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
|
def get_function_module_by_id(function_id):
|
||||||
action_ids = list(set(action_ids))
|
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_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"] = []
|
model["actions"] = []
|
||||||
for action_id in action_ids:
|
for action_id in action_ids:
|
||||||
action = Functions.get_function_by_id(action_id)
|
action_function = Functions.get_function_by_id(action_id)
|
||||||
if action is None:
|
if action_function is None:
|
||||||
raise Exception(f"Action not found: {action_id}")
|
raise Exception(f"Action not found: {action_id}")
|
||||||
|
|
||||||
if action_id in webui_app.state.FUNCTIONS:
|
function_module = get_function_module_by_id(action_id)
|
||||||
function_module = webui_app.state.FUNCTIONS[action_id]
|
model["actions"].extend(get_action_items_from_module(function_module))
|
||||||
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 {}),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
app.state.MODELS = {model["id"]: model for model in models}
|
app.state.MODELS = {model["id"]: model for model in models}
|
||||||
webui_app.state.MODELS = app.state.MODELS
|
webui_app.state.MODELS = app.state.MODELS
|
||||||
|
|
||||||
return models
|
return models
|
||||||
|
|
||||||
|
|
||||||
@ -1163,6 +1154,10 @@ async def generate_chat_completions(
|
|||||||
"selected_model_id": selected_model_id,
|
"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"):
|
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
|
# 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)
|
return await generate_function_chat_completion(form_data, user=user)
|
||||||
|
@ -524,7 +524,7 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Modal size="md" bind:show>
|
<Modal size="sm" bind:show>
|
||||||
<div>
|
<div>
|
||||||
<div class=" flex justify-between dark:text-gray-100 px-5 pt-4 pb-2">
|
<div class=" flex justify-between dark:text-gray-100 px-5 pt-4 pb-2">
|
||||||
<div class=" text-lg font-medium self-center font-primary">
|
<div class=" text-lg font-medium self-center font-primary">
|
||||||
|
@ -1125,9 +1125,7 @@
|
|||||||
showRateComment = false;
|
showRateComment = false;
|
||||||
regenerateResponse(message);
|
regenerateResponse(message);
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? []).forEach((action) => {
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
|
||||||
.forEach((action) => {
|
|
||||||
dispatch('action', {
|
dispatch('action', {
|
||||||
id: action.id,
|
id: action.id,
|
||||||
event: {
|
event: {
|
||||||
|
@ -341,7 +341,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{:else}
|
{:else}
|
||||||
{#if $user?.role === 'admin'}
|
{#if $user?.role === 'admin' || model.user_id === $user?.id}
|
||||||
<a
|
<a
|
||||||
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
export let onSubmit: Function;
|
export let onSubmit: Function;
|
||||||
export let model = null;
|
export let model = null;
|
||||||
export let edit = false;
|
export let edit = false;
|
||||||
|
export let preset = true;
|
||||||
|
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let success = false;
|
let success = false;
|
||||||
@ -382,7 +383,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if !edit || model.preset}
|
{#if preset}
|
||||||
<div class="my-1">
|
<div class="my-1">
|
||||||
<div class=" text-sm font-semibold mb-1">{$i18n.t('Base Model (From)')}</div>
|
<div class=" text-sm font-semibold mb-1">{$i18n.t('Base Model (From)')}</div>
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class=" text-sm font-semibold mb-2">{$i18n.t('General access')}</div>
|
<div class=" text-sm font-semibold mb-2">{$i18n.t('Visibility')}</div>
|
||||||
|
|
||||||
<div class="flex gap-2.5 items-center">
|
<div class="flex gap-2.5 items-center">
|
||||||
<div>
|
<div>
|
||||||
|
@ -31,6 +31,9 @@
|
|||||||
: null
|
: null
|
||||||
},
|
},
|
||||||
params: { ...modelInfo.params }
|
params: { ...modelInfo.params }
|
||||||
|
}).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
Loading…
Reference in New Issue
Block a user