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
9b3fdb18
Unverified
Commit
9b3fdb18
authored
Jun 02, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Jun 02, 2024
Browse files
Merge pull request #2741 from open-webui/dev
fix: validate lengths for openai urls and keys
parents
d09164b7
27ff3ab1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
backend/apps/openai/main.py
backend/apps/openai/main.py
+21
-0
No files found.
backend/apps/openai/main.py
View file @
9b3fdb18
...
@@ -228,6 +228,27 @@ async def get_all_models(raw: bool = False):
...
@@ -228,6 +228,27 @@ async def get_all_models(raw: bool = False):
)
or
not
app
.
state
.
config
.
ENABLE_OPENAI_API
:
)
or
not
app
.
state
.
config
.
ENABLE_OPENAI_API
:
models
=
{
"data"
:
[]}
models
=
{
"data"
:
[]}
else
:
else
:
# Check if API KEYS length is same than API URLS length
if
len
(
app
.
state
.
config
.
OPENAI_API_KEYS
)
!=
len
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
):
# if there are more keys than urls, remove the extra keys
if
len
(
app
.
state
.
config
.
OPENAI_API_KEYS
)
>
len
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
):
app
.
state
.
config
.
OPENAI_API_KEYS
=
app
.
state
.
config
.
OPENAI_API_KEYS
[
:
len
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
)
]
# if there are more urls than keys, add empty keys
else
:
app
.
state
.
config
.
OPENAI_API_KEYS
+=
[
""
for
_
in
range
(
len
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
)
-
len
(
app
.
state
.
config
.
OPENAI_API_KEYS
)
)
]
tasks
=
[
tasks
=
[
fetch_url
(
f
"
{
url
}
/models"
,
app
.
state
.
config
.
OPENAI_API_KEYS
[
idx
])
fetch_url
(
f
"
{
url
}
/models"
,
app
.
state
.
config
.
OPENAI_API_KEYS
[
idx
])
for
idx
,
url
in
enumerate
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
)
for
idx
,
url
in
enumerate
(
app
.
state
.
config
.
OPENAI_API_BASE_URLS
)
...
...
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