feat: add UI support for updating model info

This commit is contained in:
Jun Siang Cheah
2024-05-09 23:49:54 +08:00
parent 0dbddebcb0
commit 02a4412dfc
16 changed files with 336 additions and 41 deletions

View File

@@ -283,7 +283,7 @@ async def get_models(user=Depends(get_current_user)):
def add_custom_info_to_model(model: dict):
model["custom_info"] = next(
(item for item in app.state.MODEL_CONFIG if item["name"] == model["id"]), {}
(item for item in app.state.MODEL_CONFIG if item["id"] == model["id"]), {}
)

View File

@@ -176,7 +176,7 @@ async def get_all_models():
def add_custom_info_to_model(model: dict):
model["custom_info"] = next(
(item for item in app.state.MODEL_CONFIG if item["name"] == model["model"]), {}
(item for item in app.state.MODEL_CONFIG if item["id"] == model["model"]), {}
)

View File

@@ -230,7 +230,7 @@ async def get_all_models():
def add_custom_info_to_model(model: dict):
model["custom_info"] = next(
(item for item in app.state.MODEL_CONFIG if item["name"] == model["id"]), {}
(item for item in app.state.MODEL_CONFIG if item["id"] == model["id"]), {}
)

View File

@@ -58,6 +58,7 @@ from config import (
SRC_LOG_LEVELS,
WEBHOOK_URL,
ENABLE_ADMIN_EXPORT,
MODEL_CONFIG,
)
from constants import ERROR_MESSAGES
@@ -97,6 +98,8 @@ app = FastAPI(docs_url="/docs" if ENV == "dev" else None, redoc_url=None)
app.state.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER
app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST
app.state.MODEL_CONFIG = MODEL_CONFIG
app.state.WEBHOOK_URL = WEBHOOK_URL
origins = ["*"]
@@ -311,12 +314,19 @@ async def update_model_config(
litellm_app.state.MODEL_CONFIG = data.get("litellm", [])
return {
app.state.MODEL_CONFIG = {
"ollama": ollama_app.state.MODEL_CONFIG,
"openai": openai_app.state.MODEL_CONFIG,
"litellm": litellm_app.state.MODEL_CONFIG,
}
return {"models": app.state.MODEL_CONFIG}
@app.get("/api/config/models")
async def get_model_config(user=Depends(get_admin_user)):
return {"models": app.state.MODEL_CONFIG}
@app.get("/api/webhook")
async def get_webhook_url(user=Depends(get_admin_user)):