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
4651db8c
Commit
4651db8c
authored
Apr 21, 2024
by
Timothy J. Baek
Browse files
refac: litellm model name validation
parent
5997774a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
backend/apps/litellm/main.py
backend/apps/litellm/main.py
+18
-8
No files found.
backend/apps/litellm/main.py
View file @
4651db8c
...
@@ -12,7 +12,7 @@ import json
...
@@ -12,7 +12,7 @@ import json
import
time
import
time
import
requests
import
requests
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
,
ConfigDict
from
typing
import
Optional
,
List
from
typing
import
Optional
,
List
from
utils.utils
import
get_verified_user
,
get_current_user
,
get_admin_user
from
utils.utils
import
get_verified_user
,
get_current_user
,
get_admin_user
...
@@ -25,6 +25,7 @@ log.setLevel(SRC_LOG_LEVELS["LITELLM"])
...
@@ -25,6 +25,7 @@ log.setLevel(SRC_LOG_LEVELS["LITELLM"])
from
config
import
MODEL_FILTER_ENABLED
,
MODEL_FILTER_LIST
,
DATA_DIR
from
config
import
MODEL_FILTER_ENABLED
,
MODEL_FILTER_LIST
,
DATA_DIR
from
litellm.utils
import
get_llm_provider
import
asyncio
import
asyncio
import
subprocess
import
subprocess
...
@@ -165,6 +166,8 @@ class LiteLLMConfigForm(BaseModel):
...
@@ -165,6 +166,8 @@ class LiteLLMConfigForm(BaseModel):
model_list
:
Optional
[
List
[
dict
]]
=
None
model_list
:
Optional
[
List
[
dict
]]
=
None
router_settings
:
Optional
[
dict
]
=
None
router_settings
:
Optional
[
dict
]
=
None
model_config
=
ConfigDict
(
protected_namespaces
=
())
@
app
.
post
(
"/config/update"
)
@
app
.
post
(
"/config/update"
)
async
def
update_config
(
form_data
:
LiteLLMConfigForm
,
user
=
Depends
(
get_admin_user
)):
async
def
update_config
(
form_data
:
LiteLLMConfigForm
,
user
=
Depends
(
get_admin_user
)):
...
@@ -236,21 +239,28 @@ class AddLiteLLMModelForm(BaseModel):
...
@@ -236,21 +239,28 @@ class AddLiteLLMModelForm(BaseModel):
model_name
:
str
model_name
:
str
litellm_params
:
dict
litellm_params
:
dict
model_config
=
ConfigDict
(
protected_namespaces
=
())
@
app
.
post
(
"/model/new"
)
@
app
.
post
(
"/model/new"
)
async
def
add_model_to_config
(
async
def
add_model_to_config
(
form_data
:
AddLiteLLMModelForm
,
user
=
Depends
(
get_admin_user
)
form_data
:
AddLiteLLMModelForm
,
user
=
Depends
(
get_admin_user
)
):
):
# TODO: Validate model form
try
:
get_llm_provider
(
model
=
form_data
.
model_name
)
app
.
state
.
CONFIG
[
"model_list"
].
append
(
form_data
.
model_dump
())
app
.
state
.
CONFIG
[
"model_list"
].
append
(
form_data
.
model_dump
())
with
open
(
LITELLM_CONFIG_DIR
,
"w"
)
as
file
:
yaml
.
dump
(
app
.
state
.
CONFIG
,
file
)
with
open
(
LITELLM_CONFIG_DIR
,
"w"
)
as
file
:
await
restart_litellm
()
yaml
.
dump
(
app
.
state
.
CONFIG
,
file
)
await
restart_litellm
()
return
{
"message"
:
MESSAGES
.
MODEL_ADDED
(
form_data
.
model_name
)}
except
Exception
as
e
:
return
{
"message"
:
MESSAGES
.
MODEL_ADDED
(
form_data
.
model_name
)}
print
(
e
)
raise
HTTPException
(
status_code
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
detail
=
str
(
e
)
)
class
DeleteLiteLLMModelForm
(
BaseModel
):
class
DeleteLiteLLMModelForm
(
BaseModel
):
...
...
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