Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
2d596d73
Commit
2d596d73
authored
May 28, 2024
by
Timothy J. Baek
Browse files
feat: valves full integration
parent
7c271734
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
35 deletions
+137
-35
backend/main.py
backend/main.py
+44
-9
src/lib/apis/index.ts
src/lib/apis/index.ts
+6
-1
src/lib/components/admin/Settings/Pipelines.svelte
src/lib/components/admin/Settings/Pipelines.svelte
+87
-20
src/lib/components/admin/SettingsModal.svelte
src/lib/components/admin/SettingsModal.svelte
+0
-5
No files found.
backend/main.py
View file @
2d596d73
...
@@ -477,6 +477,7 @@ async def get_pipeline_valves(pipeline_id: str, user=Depends(get_admin_user)):
...
@@ -477,6 +477,7 @@ async def get_pipeline_valves(pipeline_id: str, user=Depends(get_admin_user)):
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
urlIdx
=
pipeline
[
"urlIdx"
]
...
@@ -495,12 +496,23 @@ async def get_pipeline_valves(pipeline_id: str, user=Depends(get_admin_user)):
...
@@ -495,12 +496,23 @@ async def get_pipeline_valves(pipeline_id: str, user=Depends(get_admin_user)):
# Handle connection error here
# Handle connection error here
print
(
f
"Connection error:
{
e
}
"
)
print
(
f
"Connection error:
{
e
}
"
)
detail
=
"Pipeline not found"
if
r
is
not
None
:
try
:
res
=
r
.
json
()
if
"detail"
in
res
:
detail
=
res
[
"detail"
]
except
:
pass
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
(
detail
=
"Pipeline not found"
,
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
)
return
{
"data"
:
pipeline
[
"pipeline"
][
"valves"
]}
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
status
.
HTTP_404_NOT_FOUND
,
...
@@ -514,6 +526,7 @@ async def get_pipeline_valves_spec(pipeline_id: str, user=Depends(get_admin_user
...
@@ -514,6 +526,7 @@ async def get_pipeline_valves_spec(pipeline_id: str, user=Depends(get_admin_user
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
urlIdx
=
pipeline
[
"urlIdx"
]
...
@@ -532,12 +545,21 @@ async def get_pipeline_valves_spec(pipeline_id: str, user=Depends(get_admin_user
...
@@ -532,12 +545,21 @@ async def get_pipeline_valves_spec(pipeline_id: str, user=Depends(get_admin_user
# Handle connection error here
# Handle connection error here
print
(
f
"Connection error:
{
e
}
"
)
print
(
f
"Connection error:
{
e
}
"
)
detail
=
"Pipeline not found"
if
r
is
not
None
:
try
:
res
=
r
.
json
()
if
"detail"
in
res
:
detail
=
res
[
"detail"
]
except
:
pass
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
(
detail
=
"Pipeline not found"
,
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
)
return
{
"data"
:
pipeline
[
"pipeline"
][
"valves"
]}
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
status
.
HTTP_404_NOT_FOUND
,
...
@@ -554,6 +576,7 @@ async def update_pipeline_valves(
...
@@ -554,6 +576,7 @@ async def update_pipeline_valves(
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
urlIdx
=
pipeline
[
"urlIdx"
]
...
@@ -576,9 +599,21 @@ async def update_pipeline_valves(
...
@@ -576,9 +599,21 @@ async def update_pipeline_valves(
# Handle connection error here
# Handle connection error here
print
(
f
"Connection error:
{
e
}
"
)
print
(
f
"Connection error:
{
e
}
"
)
detail
=
"Pipeline not found"
if
r
is
not
None
:
try
:
res
=
r
.
json
()
if
"detail"
in
res
:
detail
=
res
[
"detail"
]
except
:
pass
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
(
detail
=
"Pipeline not found"
,
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
)
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
...
...
src/lib/apis/index.ts
View file @
2d596d73
...
@@ -156,7 +156,12 @@ export const updatePipelineValves = async (
...
@@ -156,7 +156,12 @@ export const updatePipelineValves = async (
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
error
=
err
;
if
(
'
detail
'
in
err
)
{
error
=
err
.
detail
;
}
else
{
error
=
err
;
}
return
null
;
return
null
;
});
});
...
...
src/lib/components/admin/Settings/Pipelines.svelte
View file @
2d596d73
<script lang="ts">
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { getContext, onMount } from 'svelte';
import { getContext, onMount
, tick
} from 'svelte';
import type { Writable } from 'svelte/store';
import type { Writable } from 'svelte/store';
import type { i18n as i18nType } from 'i18next';
import type { i18n as i18nType } from 'i18next';
import { stringify } from 'postcss';
import { stringify } from 'postcss';
import { getPipelineValves, getPipelines } from '$lib/apis';
import {
getPipelineValves,
getPipelineValvesSpec,
updatePipelineValves,
getPipelines
} from '$lib/apis';
import Spinner from '$lib/components/common/Spinner.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { toast } from 'svelte-sonner';
const i18n: Writable<i18nType> = getContext('i18n');
const i18n: Writable<i18nType> = getContext('i18n');
export let saveHandler: Function;
export let saveHandler: Function;
let pipelines = null;
let pipelines = null;
let valves = null;
let valves = null;
let valves_spec = null;
let selectedPipelineIdx = null;
const updateHandler = async () => {
const pipeline = pipelines[selectedPipelineIdx];
let selectedPipelineIdx = 0;
if (pipeline && (pipeline?.pipeline?.valves ?? false)) {
const res = await updatePipelineValves(localStorage.token, pipeline.id, valves).catch(
(error) => {
toast.error(error);
}
);
$: if (
if (res) {
pipelines !== null &&
toast.success('Valves updated successfully');
pipelines.length > 0 &&
saveHandler();
pipelines[selectedPipelineIdx] !== undefined &&
}
pipelines[selectedPipelineIdx].pipeline.valves
} else {
) {
toast.error('No valves to update');
(async () => {
}
valves = await getPipelineValves(localStorage.token, pipelines[selectedPipelineIdx].id);
};
})();
}
onMount(async () => {
onMount(async () => {
pipelines = await getPipelines(localStorage.token);
pipelines = await getPipelines(localStorage.token);
if (pipelines.length > 0) {
selectedPipelineIdx = 0;
}
});
});
</script>
</script>
<form
<form
class="flex flex-col h-full justify-between space-y-3 text-sm"
class="flex flex-col h-full justify-between space-y-3 text-sm"
on:submit|preventDefault={async () => {
on:submit|preventDefault={async () => {
sav
eHandler();
updat
eHandler();
}}
}}
>
>
<div class=" space-y-2 pr-1.5 overflow-y-scroll max-h-80 h-full">
<div class=" space-y-2 pr-1.5 overflow-y-scroll max-h-80 h-full">
...
@@ -47,17 +67,30 @@
...
@@ -47,17 +67,30 @@
{$i18n.t('Pipelines')}
{$i18n.t('Pipelines')}
</div>
</div>
</div>
</div>
<div class="space-y-
2
">
<div class="space-y-
1
">
{#if pipelines.length > 0}
{#if pipelines.length > 0}
<div class="flex gap-2">
<div class="flex gap-2">
<div class="flex-1 pb-1">
<div class="flex-1 pb-1">
<select
<select
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={selectedPipelineIdx}
bind:value={selectedPipelineIdx}
placeholder={$i18n.t('Select an Ollama instance')}
placeholder={$i18n.t('Select a pipeline')}
on:change={async () => {
await tick();
valves_spec = await getPipelineValvesSpec(
localStorage.token,
pipelines[selectedPipelineIdx].id
);
valves = await getPipelineValves(
localStorage.token,
pipelines[selectedPipelineIdx].id
);
}}
>
>
{#each pipelines as pipeline, idx}
{#each pipelines as pipeline, idx}
<option value={idx} class="bg-gray-100 dark:bg-gray-700">{pipeline.name}</option>
<option value={idx} class="bg-gray-100 dark:bg-gray-700"
>{pipeline.name} ({pipeline.pipeline.type ?? 'pipe'})</option
>
{/each}
{/each}
</select>
</select>
</div>
</div>
...
@@ -66,11 +99,45 @@
...
@@ -66,11 +99,45 @@
<div class="text-sm font-medium">{$i18n.t('Valves')}</div>
<div class="text-sm font-medium">{$i18n.t('Valves')}</div>
<div class="space-y-
2
">
<div class="space-y-
1
">
{#if pipelines[selectedPipelineIdx].pipeline.valves}
{#if pipelines[selectedPipelineIdx].pipeline.valves}
{#if valves}
{#if valves}
{#each Object.keys(valves) as valve, idx}
{#each Object.keys(valves_spec.properties) as property, idx}
<div>{valve}</div>
<div class=" py-0.5 w-full justify-between">
<div class="flex w-full justify-between">
<div class=" self-center text-xs font-medium">
{valves_spec.properties[property].title}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
type="button"
on:click={() => {
valves[property] = (valves[property] ?? null) === null ? '' : null;
}}
>
{#if (valves[property] ?? null) === null}
<span class="ml-2 self-center"> {$i18n.t('None')} </span>
{:else}
<span class="ml-2 self-center"> {$i18n.t('Custom')} </span>
{/if}
</button>
</div>
{#if (valves[property] ?? null) !== null}
<div class="flex mt-0.5 space-x-2">
<div class=" flex-1">
<input
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
type="text"
placeholder={valves_spec.properties[property].title}
bind:value={valves[property]}
autocomplete="off"
/>
</div>
</div>
{/if}
</div>
{/each}
{/each}
{:else}
{:else}
<Spinner className="size-5" />
<Spinner className="size-5" />
...
...
src/lib/components/admin/SettingsModal.svelte
View file @
2d596d73
...
@@ -185,35 +185,30 @@
...
@@ -185,35 +185,30 @@
{#if selectedTab === 'general'}
{#if selectedTab === 'general'}
<General
<General
saveHandler={() => {
saveHandler={() => {
show = false;
toast.success($i18n.t('Settings saved successfully!'));
toast.success($i18n.t('Settings saved successfully!'));
}}
}}
/>
/>
{:else if selectedTab === 'users'}
{:else if selectedTab === 'users'}
<Users
<Users
saveHandler={() => {
saveHandler={() => {
show = false;
toast.success($i18n.t('Settings saved successfully!'));
toast.success($i18n.t('Settings saved successfully!'));
}}
}}
/>
/>
{:else if selectedTab === 'db'}
{:else if selectedTab === 'db'}
<Database
<Database
saveHandler={() => {
saveHandler={() => {
show = false;
toast.success($i18n.t('Settings saved successfully!'));
toast.success($i18n.t('Settings saved successfully!'));
}}
}}
/>
/>
{:else if selectedTab === 'banners'}
{:else if selectedTab === 'banners'}
<Banners
<Banners
saveHandler={() => {
saveHandler={() => {
show = false;
toast.success($i18n.t('Settings saved successfully!'));
toast.success($i18n.t('Settings saved successfully!'));
}}
}}
/>
/>
{:else if selectedTab === 'pipelines'}
{:else if selectedTab === 'pipelines'}
<Pipelines
<Pipelines
saveHandler={() => {
saveHandler={() => {
show = false;
toast.success($i18n.t('Settings saved successfully!'));
toast.success($i18n.t('Settings saved successfully!'));
}}
}}
/>
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment