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
340b399f
Commit
340b399f
authored
May 29, 2024
by
Timothy J. Baek
Browse files
refac: pipelines
parent
12e60d8e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
182 additions
and
155 deletions
+182
-155
backend/main.py
backend/main.py
+110
-119
src/lib/apis/index.ts
src/lib/apis/index.ts
+51
-26
src/lib/components/admin/Settings/Pipelines.svelte
src/lib/components/admin/Settings/Pipelines.svelte
+21
-10
No files found.
backend/main.py
View file @
340b399f
...
...
@@ -568,37 +568,52 @@ async def delete_pipeline(form_data: DeletePipelineForm, user=Depends(get_admin_
@
app
.
get
(
"/api/pipelines"
)
async
def
get_pipelines
(
urlIdx
:
Optional
[
int
]
=
None
,
user
=
Depends
(
get_admin_user
)):
models
=
await
get_all_models
()
r
=
None
try
:
urlIdx
print
(
urlIdx
)
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
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
]
headers
=
{
"Authorization"
:
f
"Bearer
{
key
}
"
}
r
=
requests
.
get
(
f
"
{
url
}
/pipelines"
,
headers
=
headers
)
return
{
"data"
:
pipelines
}
r
.
raise_for_status
()
data
=
r
.
json
()
return
{
**
data
}
except
Exception
as
e
:
# Handle connection error here
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
(
status_code
=
(
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
@
app
.
get
(
"/api/pipelines/{pipeline_id}/valves"
)
async
def
get_pipeline_valves
(
pipeline_id
:
str
,
user
=
Depends
(
get_admin_user
)):
async
def
get_pipeline_valves
(
urlIdx
:
Optional
[
int
],
pipeline_id
:
str
,
user
=
Depends
(
get_admin_user
)
):
models
=
await
get_all_models
()
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
urlIdx
]
headers
=
{
"Authorization"
:
f
"Bearer
{
key
}
"
}
r
=
requests
.
get
(
f
"
{
url
}
/
{
pipeline
[
'id'
]
}
/valves"
,
headers
=
headers
)
r
=
requests
.
get
(
f
"
{
url
}
/
{
pipeline
_id
}
/valves"
,
headers
=
headers
)
r
.
raise_for_status
()
data
=
r
.
json
()
...
...
@@ -619,34 +634,24 @@ async def get_pipeline_valves(pipeline_id: str, user=Depends(get_admin_user)):
pass
raise
HTTPException
(
status_code
=
(
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
status_code
=
(
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"Pipeline not found"
,
)
@
app
.
get
(
"/api/pipelines/{pipeline_id}/valves/spec"
)
async
def
get_pipeline_valves_spec
(
pipeline_id
:
str
,
user
=
Depends
(
get_admin_user
)):
async
def
get_pipeline_valves_spec
(
urlIdx
:
Optional
[
int
],
pipeline_id
:
str
,
user
=
Depends
(
get_admin_user
)
):
models
=
await
get_all_models
()
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
urlIdx
]
headers
=
{
"Authorization"
:
f
"Bearer
{
key
}
"
}
r
=
requests
.
get
(
f
"
{
url
}
/
{
pipeline
[
'id'
]
}
/valves/spec"
,
headers
=
headers
)
r
=
requests
.
get
(
f
"
{
url
}
/
{
pipeline
_id
}
/valves/spec"
,
headers
=
headers
)
r
.
raise_for_status
()
data
=
r
.
json
()
...
...
@@ -666,37 +671,28 @@ async def get_pipeline_valves_spec(pipeline_id: str, user=Depends(get_admin_user
pass
raise
HTTPException
(
status_code
=
(
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
status_code
=
(
r
.
status_code
if
r
is
not
None
else
status
.
HTTP_404_NOT_FOUND
),
detail
=
detail
,
)
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"Pipeline not found"
,
)
@
app
.
post
(
"/api/pipelines/{pipeline_id}/valves/update"
)
async
def
update_pipeline_valves
(
pipeline_id
:
str
,
form_data
:
dict
,
user
=
Depends
(
get_admin_user
)
urlIdx
:
Optional
[
int
],
pipeline_id
:
str
,
form_data
:
dict
,
user
=
Depends
(
get_admin_user
),
):
models
=
await
get_all_models
()
if
pipeline_id
in
app
.
state
.
MODELS
and
"pipeline"
in
app
.
state
.
MODELS
[
pipeline_id
]:
pipeline
=
app
.
state
.
MODELS
[
pipeline_id
]
r
=
None
try
:
urlIdx
=
pipeline
[
"urlIdx"
]
url
=
openai_app
.
state
.
config
.
OPENAI_API_BASE_URLS
[
urlIdx
]
key
=
openai_app
.
state
.
config
.
OPENAI_API_KEYS
[
urlIdx
]
headers
=
{
"Authorization"
:
f
"Bearer
{
key
}
"
}
r
=
requests
.
post
(
f
"
{
url
}
/
{
pipeline
[
'id'
]
}
/valves/update"
,
f
"
{
url
}
/
{
pipeline
_id
}
/valves/update"
,
headers
=
headers
,
json
=
{
**
form_data
},
)
...
...
@@ -725,11 +721,6 @@ async def update_pipeline_valves(
),
detail
=
detail
,
)
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"Pipeline not found"
,
)
@
app
.
get
(
"/api/config"
)
...
...
src/lib/apis/index.ts
View file @
340b399f
...
...
@@ -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`
,
{
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`
,
{
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,11 +259,19 @@ 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`
,
{
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
'
,
...
...
@@ -255,7 +279,8 @@ export const updatePipelineValves = async (
...(
token
&&
{
authorization
:
`Bearer
${
token
}
`
})
},
body
:
JSON
.
stringify
(
valves
)
})
}
)
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
...
...
src/lib/components/admin/Settings/Pipelines.svelte
View file @
340b399f
...
...
@@ -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) => {
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">
...
...
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