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
1bfcd801
Commit
1bfcd801
authored
Mar 18, 2024
by
Timothy J. Baek
Browse files
fix: multiple openai issue
parent
e414b9ea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
23 deletions
+31
-23
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+9
-9
backend/apps/openai/main.py
backend/apps/openai/main.py
+18
-12
backend/config.py
backend/config.py
+4
-2
No files found.
backend/apps/ollama/main.py
View file @
1bfcd801
...
@@ -98,6 +98,7 @@ def merge_models_lists(model_lists):
...
@@ -98,6 +98,7 @@ def merge_models_lists(model_lists):
merged_models
=
{}
merged_models
=
{}
for
idx
,
model_list
in
enumerate
(
model_lists
):
for
idx
,
model_list
in
enumerate
(
model_lists
):
if
model_list
is
not
None
:
for
model
in
model_list
:
for
model
in
model_list
:
digest
=
model
[
"digest"
]
digest
=
model
[
"digest"
]
if
digest
not
in
merged_models
:
if
digest
not
in
merged_models
:
...
@@ -116,11 +117,10 @@ async def get_all_models():
...
@@ -116,11 +117,10 @@ async def get_all_models():
print
(
"get_all_models"
)
print
(
"get_all_models"
)
tasks
=
[
fetch_url
(
f
"
{
url
}
/api/tags"
)
for
url
in
app
.
state
.
OLLAMA_BASE_URLS
]
tasks
=
[
fetch_url
(
f
"
{
url
}
/api/tags"
)
for
url
in
app
.
state
.
OLLAMA_BASE_URLS
]
responses
=
await
asyncio
.
gather
(
*
tasks
)
responses
=
await
asyncio
.
gather
(
*
tasks
)
responses
=
list
(
filter
(
lambda
x
:
x
is
not
None
,
responses
))
models
=
{
models
=
{
"models"
:
merge_models_lists
(
"models"
:
merge_models_lists
(
map
(
lambda
response
:
response
[
"models"
],
responses
)
map
(
lambda
response
:
response
[
"models"
]
if
response
else
None
,
responses
)
)
)
}
}
...
...
backend/apps/openai/main.py
View file @
1bfcd801
...
@@ -168,6 +168,7 @@ def merge_models_lists(model_lists):
...
@@ -168,6 +168,7 @@ def merge_models_lists(model_lists):
merged_list
=
[]
merged_list
=
[]
for
idx
,
models
in
enumerate
(
model_lists
):
for
idx
,
models
in
enumerate
(
model_lists
):
if
models
is
not
None
and
"error"
not
in
models
:
merged_list
.
extend
(
merged_list
.
extend
(
[
[
{
**
model
,
"urlIdx"
:
idx
}
{
**
model
,
"urlIdx"
:
idx
}
...
@@ -190,15 +191,20 @@ async def get_all_models():
...
@@ -190,15 +191,20 @@ async def get_all_models():
fetch_url
(
f
"
{
url
}
/models"
,
app
.
state
.
OPENAI_API_KEYS
[
idx
])
fetch_url
(
f
"
{
url
}
/models"
,
app
.
state
.
OPENAI_API_KEYS
[
idx
])
for
idx
,
url
in
enumerate
(
app
.
state
.
OPENAI_API_BASE_URLS
)
for
idx
,
url
in
enumerate
(
app
.
state
.
OPENAI_API_BASE_URLS
)
]
]
responses
=
await
asyncio
.
gather
(
*
tasks
)
responses
=
await
asyncio
.
gather
(
*
tasks
)
responses
=
list
(
filter
(
lambda
x
:
x
is
not
None
and
"error"
not
in
x
,
responses
)
)
models
=
{
models
=
{
"data"
:
merge_models_lists
(
"data"
:
merge_models_lists
(
list
(
map
(
lambda
response
:
response
[
"data"
],
responses
))
list
(
map
(
lambda
response
:
response
[
"data"
]
if
response
else
None
,
responses
,
)
)
)
)
}
}
print
(
models
)
app
.
state
.
MODELS
=
{
model
[
"id"
]:
model
for
model
in
models
[
"data"
]}
app
.
state
.
MODELS
=
{
model
[
"id"
]:
model
for
model
in
models
[
"data"
]}
return
models
return
models
...
...
backend/config.py
View file @
1bfcd801
...
@@ -250,8 +250,10 @@ OPENAI_API_BASE_URLS = (
...
@@ -250,8 +250,10 @@ OPENAI_API_BASE_URLS = (
OPENAI_API_BASE_URLS
if
OPENAI_API_BASE_URLS
!=
""
else
OPENAI_API_BASE_URL
OPENAI_API_BASE_URLS
if
OPENAI_API_BASE_URLS
!=
""
else
OPENAI_API_BASE_URL
)
)
OPENAI_API_BASE_URLS
=
[
url
.
strip
()
for
url
in
OPENAI_API_BASE_URLS
.
split
(
";"
)]
OPENAI_API_BASE_URLS
=
[
url
.
strip
()
if
url
!=
""
else
"https://api.openai.com/v1"
for
url
in
OPENAI_API_BASE_URLS
.
split
(
";"
)
]
####################################
####################################
# WEBUI
# WEBUI
...
...
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