From f0984191aed4bd5b0a4fbe5ecffe55dce3fd6014 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Thu, 24 Oct 2024 13:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dconfig=20=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/docker-compose.dev.yml | 2 +- src/routers/base_router.py | 7 +++---- web/src/layouts/AppLayout.vue | 11 ++--------- web/src/stores/config.js | 9 +++++++-- web/src/stores/database.js | 9 ++++++++- web/src/views/SettingView.vue | 11 ++++------- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index e53ab96b..740985b6 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -21,7 +21,7 @@ services: - NEO4J_USERNAME=neo4j - NEO4J_PASSWORD=0123456789 - MILVUS_URI=http://milvus:19530 - command: gunicorn src.main:app --bind 0.0.0.0:5000 --reload --workers 10 --worker-class uvicorn.workers.UvicornWorker + command: uvicorn src.main:app --host 0.0.0.0 --port 5000 --reload web: build: diff --git a/src/routers/base_router.py b/src/routers/base_router.py index 31ac506c..7d9b0f21 100644 --- a/src/routers/base_router.py +++ b/src/routers/base_router.py @@ -4,7 +4,7 @@ base = APIRouter() from fastapi import FastAPI, HTTPException from fastapi.responses import JSONResponse -from fastapi import Request +from fastapi import Request, Body from src.core import HistoryManager from src.utils.logging_config import setup_logger from src.core.startup import startup @@ -20,9 +20,8 @@ def get_config(): return startup.config @base.post("/config") -async def update_config(request: Request): - request_data = await request.json() - startup.config.update(request_data) +async def update_config(key = Body(...), value = Body(...)): + startup.config[key] = value startup.config.save() return startup.config diff --git a/web/src/layouts/AppLayout.vue b/web/src/layouts/AppLayout.vue index 09902290..95267855 100644 --- a/web/src/layouts/AppLayout.vue +++ b/web/src/layouts/AppLayout.vue @@ -33,26 +33,19 @@ const layoutSettings = reactive({ }) const getRemoteConfig = () => { - fetch('/api/config').then(res => res.json()).then(data => { - console.log(data) - configStore.setConfig(data) - }) + configStore.refreshConfig() } const getRemoteDatabase = () => { if (!configStore.config.enable_knowledge_base) { return } - fetch('/api/data').then(res => res.json()).then(data => { - console.log("database", data) - databaseStore.setDatabase(data.databases) - }) + databaseStore.refreshDatabase() } onMounted(() => { getRemoteConfig() getRemoteDatabase() - configStore.refreshConfig() }) // 打印当前页面的路由信息,使用 vue3 的 setup composition API diff --git a/web/src/stores/config.js b/web/src/stores/config.js index 2e704a6b..578f1fbf 100644 --- a/web/src/stores/config.js +++ b/web/src/stores/config.js @@ -22,11 +22,15 @@ export const useConfigStore = defineStore('config', () => { config.value[key] = value fetch('/api/config', { method: 'POST', - body: JSON.stringify(config.value), + body: JSON.stringify({ key, value }), + headers: { + 'Content-Type': 'application/json' + } }) .then(response => response.json()) .then(data => { - console.log('Success:', data) + console.debug('Success:', data) + setConfig(data) }) } @@ -34,6 +38,7 @@ export const useConfigStore = defineStore('config', () => { fetch('/api/config') .then(response => response.json()) .then(data => { + console.log("config", data) setConfig(data) }) } diff --git a/web/src/stores/database.js b/web/src/stores/database.js index aadb3f51..6a5bf10a 100644 --- a/web/src/stores/database.js +++ b/web/src/stores/database.js @@ -7,5 +7,12 @@ export const useDatabaseStore = defineStore('database', () => { db.value = newDatabase } - return { db, setDatabase } + function refreshDatabase() { + fetch('/api/data').then(res => res.json()).then(data => { + console.log("database", data) + setDatabase(data.databases) + }) + } + + return { db, setDatabase, refreshDatabase } }) \ No newline at end of file diff --git a/web/src/views/SettingView.vue b/web/src/views/SettingView.vue index 26597935..17f6002d 100644 --- a/web/src/views/SettingView.vue +++ b/web/src/views/SettingView.vue @@ -231,8 +231,7 @@ const handleChange = (key, e) => { return } - console.log('Change', key, e) - + // 这些都是需要重启的配置 if (key == 'enable_reranker' || key == 'enable_knowledge_graph' || key == 'enable_knowledge_base' @@ -283,14 +282,12 @@ const handleAddCustomModel = async () => { customModel.visible = false await configStore.setConfigValue('custom_models', configStore.config.custom_models) - configStore.refreshConfig() message.success('添加自定义模型成功') } const handleDeleteCustomModel = (name) => { - configStore.config.custom_models = configStore.config.custom_models.filter(item => item.name != name) - configStore.setConfigValue('custom_models', configStore.config.custom_models) - configStore.refreshConfig() + const updatedModels = configStore.config.custom_models.filter(item => item.name !== name); + configStore.setConfigValue('custom_models', updatedModels); } const handleEditCustomModel = (item) => { @@ -567,4 +564,4 @@ const sendRestart = () => { } } - \ No newline at end of file +