mirror of
https://github.com/open-webui/open-webui
synced 2024-11-21 23:57:51 +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_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], {}
|
||||
|
@ -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)
|
||||
|
@ -524,7 +524,7 @@
|
||||
}}
|
||||
/>
|
||||
|
||||
<Modal size="md" bind:show>
|
||||
<Modal size="sm" bind:show>
|
||||
<div>
|
||||
<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">
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
|
@ -341,7 +341,7 @@
|
||||
</button>
|
||||
</Tooltip>
|
||||
{:else}
|
||||
{#if $user?.role === 'admin'}
|
||||
{#if $user?.role === 'admin' || model.user_id === $user?.id}
|
||||
<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"
|
||||
type="button"
|
||||
|
@ -24,6 +24,7 @@
|
||||
export let onSubmit: Function;
|
||||
export let model = null;
|
||||
export let edit = false;
|
||||
export let preset = true;
|
||||
|
||||
let loading = false;
|
||||
let success = false;
|
||||
@ -382,7 +383,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if !edit || model.preset}
|
||||
{#if preset}
|
||||
<div class="my-1">
|
||||
<div class=" text-sm font-semibold mb-1">{$i18n.t('Base Model (From)')}</div>
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
@ -31,6 +31,9 @@
|
||||
: null
|
||||
},
|
||||
params: { ...modelInfo.params }
|
||||
}).catch((error) => {
|
||||
toast.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (res) {
|
||||
|
Loading…
Reference in New Issue
Block a user