From 0bef1b44c03f44c6540feb9203e81e076bb578e2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 28 May 2024 12:04:19 -0700 Subject: [PATCH] feat: pipeline valves --- backend/main.py | 7 +++ src/lib/apis/index.ts | 29 ++++++++++ .../admin/Settings/Pipelines.svelte | 55 +++++++++++++++++++ src/lib/components/admin/SettingsModal.svelte | 38 +++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/lib/components/admin/Settings/Pipelines.svelte diff --git a/backend/main.py b/backend/main.py index 0e5924574..648bedea0 100644 --- a/backend/main.py +++ b/backend/main.py @@ -464,6 +464,13 @@ async def get_models(user=Depends(get_verified_user)): return {"data": models} +@app.get("/api/pipelines") +async def get_pipelines(user=Depends(get_admin_user)): + models = await get_all_models() + pipelines = [model for model in models if "pipeline" in model] + return {"data": pipelines} + + @app.get("/api/config") async def get_app_config(): # Checking and Handling the Absence of 'ui' in CONFIG_DATA diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index dc51abd52..3d6e51684 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -49,6 +49,35 @@ export const getModels = async (token: string = '') => { return models; }; +export const getPipelines = async (token: string = '') => { + let error = null; + + const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines`, { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + console.log(err); + error = err; + return null; + }); + + if (error) { + throw error; + } + + let pipelines = res?.data ?? []; + return pipelines; +}; + export const getBackendConfig = async () => { let error = null; diff --git a/src/lib/components/admin/Settings/Pipelines.svelte b/src/lib/components/admin/Settings/Pipelines.svelte new file mode 100644 index 000000000..b1b34ecca --- /dev/null +++ b/src/lib/components/admin/Settings/Pipelines.svelte @@ -0,0 +1,55 @@ + + +
{ + saveHandler(); + }} +> +
+
+
+
+ {$i18n.t('Pipeline Valves')} +
+
+
+ {#each pipelines as pipeline} +
+ {JSON.stringify(pipeline)} +
+ {/each} +
+
+
+
+ +
+
diff --git a/src/lib/components/admin/SettingsModal.svelte b/src/lib/components/admin/SettingsModal.svelte index 38a2602b6..6da1bda6f 100644 --- a/src/lib/components/admin/SettingsModal.svelte +++ b/src/lib/components/admin/SettingsModal.svelte @@ -8,6 +8,7 @@ import Banners from '$lib/components/admin/Settings/Banners.svelte'; import { toast } from 'svelte-sonner'; + import Pipelines from './Settings/Pipelines.svelte'; const i18n = getContext('i18n'); @@ -149,6 +150,36 @@
{$i18n.t('Banners')}
+ +
{#if selectedTab === 'general'} @@ -179,6 +210,13 @@ toast.success($i18n.t('Settings saved successfully!')); }} /> + {:else if selectedTab === 'pipelines'} + { + show = false; + toast.success($i18n.t('Settings saved successfully!')); + }} + /> {/if}