diff --git a/backend/main.py b/backend/main.py index 103627ff1..714080830 100644 --- a/backend/main.py +++ b/backend/main.py @@ -464,10 +464,37 @@ 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)): +@app.get("/api/pipelines/list") +async def get_pipelines_list(user=Depends(get_admin_user)): models = await get_all_models() - pipelines = [model for model in models if "pipeline" in model] + urlIdxs = list(set([model["urlIdx"] for model in models if "pipeline" in model])) + + return { + "data": [ + { + "url": openai_app.state.config.OPENAI_API_BASE_URLS[urlIdx], + "idx": urlIdx, + } + for urlIdx in urlIdxs + ] + } + + +@app.get("/api/pipelines") +async def get_pipelines(urlIdx: Optional[int] = None, user=Depends(get_admin_user)): + models = await get_all_models() + + print(urlIdx) + + if urlIdx is None: + pipelines = [model for model in models if "pipeline" in model] + else: + pipelines = [ + model + for model in models + if "pipeline" in model and model["urlIdx"] == urlIdx + ] + return {"data": pipelines} diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index ffa5c6bbb..b7f5fabb2 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -49,10 +49,44 @@ export const getModels = async (token: string = '') => { return models; }; -export const getPipelines = async (token: string = '') => { +export const getPipelinesList = async (token: string = '') => { let error = null; - const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines`, { + const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/list`, { + 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 getPipelines = async (token: string, urlIdx?: string) => { + let error = null; + + const searchParams = new URLSearchParams(); + if (urlIdx) { + searchParams.append('urlIdx', urlIdx); + } + + const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines?${searchParams.toString()}`, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/lib/components/admin/Settings/Pipelines.svelte b/src/lib/components/admin/Settings/Pipelines.svelte index 60905e99c..3e7f5ee75 100644 --- a/src/lib/components/admin/Settings/Pipelines.svelte +++ b/src/lib/components/admin/Settings/Pipelines.svelte @@ -1,31 +1,33 @@ @@ -83,95 +98,140 @@ }} >
- {#if pipelines !== null && pipelines.length > 0} + {#if PIPELINES_LIST !== null}
- {$i18n.t('Pipelines')} + {$i18n.t('Manage Pipelines')}
-
- {#if pipelines.length > 0} + + {#if PIPELINES_LIST.length > 0} +
-
+
- {/if} - -
{$i18n.t('Valves')}
- -
- {#if pipelines[selectedPipelineIdx].pipeline.valves} - {#if valves} - {#each Object.keys(valves_spec.properties) as property, idx} -
-
-
- {valves_spec.properties[property].title} -
- - -
- - {#if (valves[property] ?? null) !== null} -
-
- -
-
- {/if} -
- {/each} - {:else} - - {/if} - {:else} -
No valves
- {/if}
-
- {:else if pipelines !== null && pipelines.length === 0} -
Pipelines Not Detected
+ {/if} + +
+ + {#if pipelines !== null} + {#if pipelines.length > 0} +
+
+ {$i18n.t('Pipelines Valves')} +
+
+
+ {#if pipelines.length > 0} +
+
+ +
+
+ {/if} + +
+ {#if pipelines[selectedPipelineIdx].pipeline.valves} + {#if valves} + {#each Object.keys(valves_spec.properties) as property, idx} +
+
+
+ {valves_spec.properties[property].title} +
+ + +
+ + {#if (valves[property] ?? null) !== null} +
+
+ +
+
+ {/if} +
+ {/each} + {:else} + + {/if} + {:else} +
No valves
+ {/if} +
+
+ {:else if pipelines.length === 0} +
Pipelines Not Detected
+ {/if} + {:else} +
+
+ +
+
+ {/if} {:else} -
+
{/if}
+