mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac: user valves
This commit is contained in:
parent
807a8be299
commit
b77848244b
8 changed files with 84 additions and 29 deletions
|
|
@ -86,6 +86,10 @@ async def get_function_models(request):
|
||||||
try:
|
try:
|
||||||
function_module = get_function_module_by_id(request, pipe.id)
|
function_module = get_function_module_by_id(request, pipe.id)
|
||||||
|
|
||||||
|
has_user_valves = False
|
||||||
|
if hasattr(function_module, "UserValves"):
|
||||||
|
has_user_valves = True
|
||||||
|
|
||||||
# Check if function is a manifold
|
# Check if function is a manifold
|
||||||
if hasattr(function_module, "pipes"):
|
if hasattr(function_module, "pipes"):
|
||||||
sub_pipes = []
|
sub_pipes = []
|
||||||
|
|
@ -124,6 +128,7 @@ async def get_function_models(request):
|
||||||
"created": pipe.created_at,
|
"created": pipe.created_at,
|
||||||
"owned_by": "openai",
|
"owned_by": "openai",
|
||||||
"pipe": pipe_flag,
|
"pipe": pipe_flag,
|
||||||
|
"has_user_valves": has_user_valves,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
@ -141,6 +146,7 @@ async def get_function_models(request):
|
||||||
"created": pipe.created_at,
|
"created": pipe.created_at,
|
||||||
"owned_by": "openai",
|
"owned_by": "openai",
|
||||||
"pipe": pipe_flag,
|
"pipe": pipe_flag,
|
||||||
|
"has_user_valves": has_user_valves,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,7 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||||
"icon": function.meta.manifest.get("icon_url", None)
|
"icon": function.meta.manifest.get("icon_url", None)
|
||||||
or getattr(module, "icon_url", None)
|
or getattr(module, "icon_url", None)
|
||||||
or getattr(module, "icon", None),
|
or getattr(module, "icon", None),
|
||||||
|
"has_user_valves": hasattr(module, "UserValves"),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@
|
||||||
|
|
||||||
import { getSuggestionRenderer } from '../common/RichTextInput/suggestions';
|
import { getSuggestionRenderer } from '../common/RichTextInput/suggestions';
|
||||||
import CommandSuggestionList from './MessageInput/CommandSuggestionList.svelte';
|
import CommandSuggestionList from './MessageInput/CommandSuggestionList.svelte';
|
||||||
|
import Knobs from '../icons/Knobs.svelte';
|
||||||
|
import ValvesModal from '../workspace/common/ValvesModal.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -112,6 +114,10 @@
|
||||||
let inputVariables = {};
|
let inputVariables = {};
|
||||||
let inputVariableValues = {};
|
let inputVariableValues = {};
|
||||||
|
|
||||||
|
let showValvesModal = false;
|
||||||
|
let selectedValvesType = 'tool'; // 'tool' or 'function'
|
||||||
|
let selectedValvesItemId = null;
|
||||||
|
|
||||||
$: onChange({
|
$: onChange({
|
||||||
prompt,
|
prompt,
|
||||||
files: files
|
files: files
|
||||||
|
|
@ -932,6 +938,16 @@
|
||||||
onSave={inputVariablesModalCallback}
|
onSave={inputVariablesModalCallback}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ValvesModal
|
||||||
|
bind:show={showValvesModal}
|
||||||
|
userValves={true}
|
||||||
|
type={selectedValvesType}
|
||||||
|
id={selectedValvesItemId ?? null}
|
||||||
|
on:save={async () => {
|
||||||
|
await tick();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{#if loaded}
|
{#if loaded}
|
||||||
<div class="w-full font-primary">
|
<div class="w-full font-primary">
|
||||||
<div class=" mx-auto inset-x-0 bg-transparent flex justify-center">
|
<div class=" mx-auto inset-x-0 bg-transparent flex justify-center">
|
||||||
|
|
@ -1449,6 +1465,12 @@
|
||||||
bind:webSearchEnabled
|
bind:webSearchEnabled
|
||||||
bind:imageGenerationEnabled
|
bind:imageGenerationEnabled
|
||||||
bind:codeInterpreterEnabled
|
bind:codeInterpreterEnabled
|
||||||
|
onShowValves={(e) => {
|
||||||
|
const { type, id } = e;
|
||||||
|
selectedValvesType = type;
|
||||||
|
selectedValvesItemId = id;
|
||||||
|
showValvesModal = true;
|
||||||
|
}}
|
||||||
onClose={async () => {
|
onClose={async () => {
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
|
|
@ -1465,6 +1487,24 @@
|
||||||
</IntegrationsMenu>
|
</IntegrationsMenu>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if selectedModelIds.length === 1 && $models.find((m) => m.id === selectedModelIds[0])?.has_user_valves}
|
||||||
|
<div class="ml-1 flex gap-1.5">
|
||||||
|
<Tooltip content={$i18n.t('Valves')} placement="top">
|
||||||
|
<button
|
||||||
|
id="model-valves-button"
|
||||||
|
class="bg-transparent hover:bg-gray-100 text-gray-700 dark:text-white dark:hover:bg-gray-800 rounded-full size-8 flex justify-center items-center outline-hidden focus:outline-hidden"
|
||||||
|
on:click={() => {
|
||||||
|
selectedValvesType = 'function';
|
||||||
|
selectedValvesItemId = selectedModelIds[0]?.split('.')[0];
|
||||||
|
showValvesModal = true;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Knobs className="size-4" strokeWidth="1.5" />
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="ml-1 flex gap-1.5">
|
<div class="ml-1 flex gap-1.5">
|
||||||
{#if (selectedToolIds ?? []).length > 0}
|
{#if (selectedToolIds ?? []).length > 0}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
import Terminal from '$lib/components/icons/Terminal.svelte';
|
import Terminal from '$lib/components/icons/Terminal.svelte';
|
||||||
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
||||||
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
||||||
import ValvesModal from '$lib/components/workspace/common/ValvesModal.svelte';
|
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -41,16 +40,12 @@
|
||||||
export let showCodeInterpreterButton = false;
|
export let showCodeInterpreterButton = false;
|
||||||
export let codeInterpreterEnabled = false;
|
export let codeInterpreterEnabled = false;
|
||||||
|
|
||||||
|
export let onShowValves: Function;
|
||||||
export let onClose: Function;
|
export let onClose: Function;
|
||||||
|
|
||||||
let show = false;
|
let show = false;
|
||||||
let tab = '';
|
let tab = '';
|
||||||
|
|
||||||
let showValvesModal = false;
|
|
||||||
|
|
||||||
let selectedValvesType = 'tool';
|
|
||||||
let selectedValvesItemId = null;
|
|
||||||
|
|
||||||
let tools = null;
|
let tools = null;
|
||||||
|
|
||||||
$: if (show) {
|
$: if (show) {
|
||||||
|
|
@ -96,16 +91,6 @@
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ValvesModal
|
|
||||||
bind:show={showValvesModal}
|
|
||||||
userValves={true}
|
|
||||||
type={selectedValvesType}
|
|
||||||
id={selectedValvesItemId ?? null}
|
|
||||||
on:save={async () => {
|
|
||||||
await tick();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
bind:show
|
bind:show
|
||||||
on:change={(e) => {
|
on:change={(e) => {
|
||||||
|
|
@ -192,6 +177,27 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if filter?.has_user_valves}
|
||||||
|
<div class=" shrink-0">
|
||||||
|
<Tooltip content={$i18n.t('Valves')}>
|
||||||
|
<button
|
||||||
|
class="self-center w-fit text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition rounded-full"
|
||||||
|
type="button"
|
||||||
|
on:click={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
onShowValves({
|
||||||
|
type: 'function',
|
||||||
|
id: filter.id
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Knobs />
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class=" shrink-0">
|
<div class=" shrink-0">
|
||||||
<Switch
|
<Switch
|
||||||
state={selectedFilterIds.includes(filter.id)}
|
state={selectedFilterIds.includes(filter.id)}
|
||||||
|
|
@ -364,9 +370,10 @@
|
||||||
on:click={(e) => {
|
on:click={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
selectedValvesType = 'tool';
|
onShowValves({
|
||||||
selectedValvesItemId = toolId;
|
type: 'tool',
|
||||||
showValvesModal = true;
|
id: toolId
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Knobs />
|
<Knobs />
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
|
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
|
||||||
import ChatPlus from '../icons/ChatPlus.svelte';
|
import ChatPlus from '../icons/ChatPlus.svelte';
|
||||||
import ChatCheck from '../icons/ChatCheck.svelte';
|
import ChatCheck from '../icons/ChatCheck.svelte';
|
||||||
|
import Knobs from '../icons/Knobs.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -210,7 +211,7 @@
|
||||||
aria-label="Controls"
|
aria-label="Controls"
|
||||||
>
|
>
|
||||||
<div class=" m-auto self-center">
|
<div class=" m-auto self-center">
|
||||||
<AdjustmentsHorizontal className=" size-5" strokeWidth="1" />
|
<Knobs className=" size-5" strokeWidth="1" />
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
@ -255,7 +256,7 @@
|
||||||
|
|
||||||
<div class="absolute top-[100%] left-0 right-0 h-fit">
|
<div class="absolute top-[100%] left-0 right-0 h-fit">
|
||||||
{#if !history.currentId && !$chatId && ($banners.length > 0 || ($config?.license_metadata?.type ?? null) === 'trial' || (($config?.license_metadata?.seats ?? null) !== null && $config?.user_count > $config?.license_metadata?.seats))}
|
{#if !history.currentId && !$chatId && ($banners.length > 0 || ($config?.license_metadata?.type ?? null) === 'trial' || (($config?.license_metadata?.seats ?? null) !== null && $config?.user_count > $config?.license_metadata?.seats))}
|
||||||
<div class=" w-full z-30 mt-4">
|
<div class=" w-full z-30">
|
||||||
<div class=" flex flex-col gap-1 w-full">
|
<div class=" flex flex-col gap-1 w-full">
|
||||||
{#if ($config?.license_metadata?.type ?? null) === 'trial'}
|
{#if ($config?.license_metadata?.type ?? null) === 'trial'}
|
||||||
<Banner
|
<Banner
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
>
|
>
|
||||||
<!-- Top horizontal knob (left biased) -->
|
<!-- Top horizontal knob (left biased) -->
|
||||||
<line x1="3" y1="8" x2="6" y2="8" stroke-linecap="round" />
|
<line x1="2" y1="7.5" x2="6" y2="7.5" stroke-linecap="round" />
|
||||||
<line x1="12" y1="8" x2="21" y2="8" stroke-linecap="round" />
|
<line x1="12" y1="7.5" x2="22" y2="7.5" stroke-linecap="round" />
|
||||||
<circle cx="9" cy="8" r="2.5" stroke="currentColor" fill="none" />
|
<circle cx="9" cy="7.5" r="3" stroke="currentColor" fill="none" />
|
||||||
|
|
||||||
<!-- Bottom horizontal knob (right biased) -->
|
<!-- Bottom horizontal knob (right biased) -->
|
||||||
<line x1="3" y1="16" x2="12" y2="16" stroke-linecap="round" />
|
<line x1="2" y1="16.5" x2="12" y2="16.5" stroke-linecap="round" />
|
||||||
<line x1="18" y1="16" x2="21" y2="16" stroke-linecap="round" />
|
<line x1="18" y1="16.5" x2="22" y2="16.5" stroke-linecap="round" />
|
||||||
<circle cx="15" cy="16" r="2.5" stroke="currentColor" fill="none" />
|
<circle cx="15" cy="16.5" r="3" stroke="currentColor" fill="none" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@
|
||||||
|
|
||||||
{#if mounted}
|
{#if mounted}
|
||||||
{#key func?.content}
|
{#key func?.content}
|
||||||
<div class="px-[16px]">
|
<div class="px-[16px] h-full">
|
||||||
<FunctionEditor
|
<FunctionEditor
|
||||||
id={func?.id ?? ''}
|
id={func?.id ?? ''}
|
||||||
name={func?.name ?? ''}
|
name={func?.name ?? ''}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if func}
|
{#if func}
|
||||||
<div class="px-[16px]">
|
<div class="px-[16px] h-full">
|
||||||
<FunctionEditor
|
<FunctionEditor
|
||||||
edit={true}
|
edit={true}
|
||||||
id={func.id}
|
id={func.id}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue