feat: save UI config changes to config.json

This commit is contained in:
Jun Siang Cheah
2024-05-10 13:36:10 +08:00
parent 9a95767062
commit 058eb76568
11 changed files with 611 additions and 336 deletions

View File

@@ -58,6 +58,8 @@ from config import (
SRC_LOG_LEVELS,
WEBHOOK_URL,
ENABLE_ADMIN_EXPORT,
config_get,
config_set,
)
from constants import ERROR_MESSAGES
@@ -243,9 +245,11 @@ async def get_app_config():
"version": VERSION,
"auth": WEBUI_AUTH,
"default_locale": default_locale,
"images": images_app.state.ENABLED,
"default_models": webui_app.state.DEFAULT_MODELS,
"default_prompt_suggestions": webui_app.state.DEFAULT_PROMPT_SUGGESTIONS,
"images": config_get(images_app.state.ENABLED),
"default_models": config_get(webui_app.state.DEFAULT_MODELS),
"default_prompt_suggestions": config_get(
webui_app.state.DEFAULT_PROMPT_SUGGESTIONS
),
"trusted_header_auth": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER),
"admin_export_enabled": ENABLE_ADMIN_EXPORT,
}
@@ -254,8 +258,8 @@ async def get_app_config():
@app.get("/api/config/model/filter")
async def get_model_filter_config(user=Depends(get_admin_user)):
return {
"enabled": app.state.ENABLE_MODEL_FILTER,
"models": app.state.MODEL_FILTER_LIST,
"enabled": config_get(app.state.ENABLE_MODEL_FILTER),
"models": config_get(app.state.MODEL_FILTER_LIST),
}
@@ -268,28 +272,28 @@ class ModelFilterConfigForm(BaseModel):
async def update_model_filter_config(
form_data: ModelFilterConfigForm, user=Depends(get_admin_user)
):
app.state.ENABLE_MODEL_FILTER = form_data.enabled
app.state.MODEL_FILTER_LIST = form_data.models
config_set(app.state.ENABLE_MODEL_FILTER, form_data.enabled)
config_set(app.state.MODEL_FILTER_LIST, form_data.models)
ollama_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER
ollama_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST
ollama_app.state.ENABLE_MODEL_FILTER = config_get(app.state.ENABLE_MODEL_FILTER)
ollama_app.state.MODEL_FILTER_LIST = config_get(app.state.MODEL_FILTER_LIST)
openai_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER
openai_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST
openai_app.state.ENABLE_MODEL_FILTER = config_get(app.state.ENABLE_MODEL_FILTER)
openai_app.state.MODEL_FILTER_LIST = config_get(app.state.MODEL_FILTER_LIST)
litellm_app.state.ENABLE_MODEL_FILTER = app.state.ENABLE_MODEL_FILTER
litellm_app.state.MODEL_FILTER_LIST = app.state.MODEL_FILTER_LIST
litellm_app.state.ENABLE_MODEL_FILTER = config_get(app.state.ENABLE_MODEL_FILTER)
litellm_app.state.MODEL_FILTER_LIST = config_get(app.state.MODEL_FILTER_LIST)
return {
"enabled": app.state.ENABLE_MODEL_FILTER,
"models": app.state.MODEL_FILTER_LIST,
"enabled": config_get(app.state.ENABLE_MODEL_FILTER),
"models": config_get(app.state.MODEL_FILTER_LIST),
}
@app.get("/api/webhook")
async def get_webhook_url(user=Depends(get_admin_user)):
return {
"url": app.state.WEBHOOK_URL,
"url": config_get(app.state.WEBHOOK_URL),
}
@@ -299,12 +303,12 @@ class UrlForm(BaseModel):
@app.post("/api/webhook")
async def update_webhook_url(form_data: UrlForm, user=Depends(get_admin_user)):
app.state.WEBHOOK_URL = form_data.url
config_set(app.state.WEBHOOK_URL, form_data.url)
webui_app.state.WEBHOOK_URL = app.state.WEBHOOK_URL
webui_app.state.WEBHOOK_URL = config_get(app.state.WEBHOOK_URL)
return {
"url": app.state.WEBHOOK_URL,
"url": config_get(app.state.WEBHOOK_URL),
}