mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: pipelines
This commit is contained in:
@@ -184,17 +184,25 @@ export const getPipelines = async (token: string, urlIdx?: string) => {
|
||||
return pipelines;
|
||||
};
|
||||
|
||||
export const getPipelineValves = async (token: string = '', pipeline_id: string) => {
|
||||
export const getPipelineValves = async (token: string, pipeline_id: string, urlIdx: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
const searchParams = new URLSearchParams();
|
||||
if (urlIdx) {
|
||||
searchParams.append('urlIdx', urlIdx);
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves?${searchParams.toString()}`,
|
||||
{
|
||||
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();
|
||||
@@ -212,17 +220,25 @@ export const getPipelineValves = async (token: string = '', pipeline_id: string)
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getPipelineValvesSpec = async (token: string = '', pipeline_id: string) => {
|
||||
export const getPipelineValvesSpec = async (token: string, pipeline_id: string, urlIdx: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/spec`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
const searchParams = new URLSearchParams();
|
||||
if (urlIdx) {
|
||||
searchParams.append('urlIdx', urlIdx);
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/spec?${searchParams.toString()}`,
|
||||
{
|
||||
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();
|
||||
@@ -243,19 +259,28 @@ export const getPipelineValvesSpec = async (token: string = '', pipeline_id: str
|
||||
export const updatePipelineValves = async (
|
||||
token: string = '',
|
||||
pipeline_id: string,
|
||||
valves: object
|
||||
valves: object,
|
||||
urlIdx: string
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/update`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify(valves)
|
||||
})
|
||||
const searchParams = new URLSearchParams();
|
||||
if (urlIdx) {
|
||||
searchParams.append('urlIdx', urlIdx);
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
`${WEBUI_BASE_URL}/api/pipelines/${pipeline_id}/valves/update?${searchParams.toString()}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify(valves)
|
||||
}
|
||||
)
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
|
||||
@@ -39,16 +39,19 @@
|
||||
const updateHandler = async () => {
|
||||
const pipeline = pipelines[selectedPipelineIdx];
|
||||
|
||||
if (pipeline && (pipeline?.pipeline?.valves ?? false)) {
|
||||
if (pipeline && (pipeline?.valves ?? false)) {
|
||||
if (valves?.pipelines ?? false) {
|
||||
valves.pipelines = valves.pipelines.split(',').map((v) => v.trim());
|
||||
}
|
||||
|
||||
const res = await updatePipelineValves(localStorage.token, pipeline.id, valves).catch(
|
||||
(error) => {
|
||||
toast.error(error);
|
||||
}
|
||||
);
|
||||
const res = await updatePipelineValves(
|
||||
localStorage.token,
|
||||
pipeline.id,
|
||||
valves,
|
||||
selectedPipelinesUrlIdx
|
||||
).catch((error) => {
|
||||
toast.error(error);
|
||||
});
|
||||
|
||||
if (res) {
|
||||
toast.success('Valves updated successfully');
|
||||
@@ -65,8 +68,16 @@
|
||||
valves = null;
|
||||
valves_spec = null;
|
||||
|
||||
valves_spec = await getPipelineValvesSpec(localStorage.token, pipelines[idx].id);
|
||||
valves = await getPipelineValves(localStorage.token, pipelines[idx].id);
|
||||
valves_spec = await getPipelineValvesSpec(
|
||||
localStorage.token,
|
||||
pipelines[idx].id,
|
||||
selectedPipelinesUrlIdx
|
||||
);
|
||||
valves = await getPipelineValves(
|
||||
localStorage.token,
|
||||
pipelines[idx].id,
|
||||
selectedPipelinesUrlIdx
|
||||
);
|
||||
|
||||
if (valves?.pipelines ?? false) {
|
||||
valves.pipelines = valves.pipelines.join(',');
|
||||
@@ -269,7 +280,7 @@
|
||||
>
|
||||
{#each pipelines as pipeline, idx}
|
||||
<option value={idx} class="bg-gray-100 dark:bg-gray-700"
|
||||
>{pipeline.name} ({pipeline.pipeline.type ?? 'pipe'})</option
|
||||
>{pipeline.name} ({pipeline.type ?? 'pipe'})</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
@@ -299,7 +310,7 @@
|
||||
{/if}
|
||||
|
||||
<div class="space-y-1">
|
||||
{#if pipelines[selectedPipelineIdx].pipeline.valves}
|
||||
{#if pipelines[selectedPipelineIdx].valves}
|
||||
{#if valves}
|
||||
{#each Object.keys(valves_spec.properties) as property, idx}
|
||||
<div class=" py-0.5 w-full justify-between">
|
||||
|
||||
Reference in New Issue
Block a user