修复config 不同步的问题

This commit is contained in:
Wenjie Zhang 2024-10-24 13:09:59 +08:00
parent 1115bf18b2
commit f0984191ae
6 changed files with 25 additions and 24 deletions

View File

@ -21,7 +21,7 @@ services:
- NEO4J_USERNAME=neo4j - NEO4J_USERNAME=neo4j
- NEO4J_PASSWORD=0123456789 - NEO4J_PASSWORD=0123456789
- MILVUS_URI=http://milvus:19530 - 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: web:
build: build:

View File

@ -4,7 +4,7 @@ base = APIRouter()
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from fastapi import Request from fastapi import Request, Body
from src.core import HistoryManager from src.core import HistoryManager
from src.utils.logging_config import setup_logger from src.utils.logging_config import setup_logger
from src.core.startup import startup from src.core.startup import startup
@ -20,9 +20,8 @@ def get_config():
return startup.config return startup.config
@base.post("/config") @base.post("/config")
async def update_config(request: Request): async def update_config(key = Body(...), value = Body(...)):
request_data = await request.json() startup.config[key] = value
startup.config.update(request_data)
startup.config.save() startup.config.save()
return startup.config return startup.config

View File

@ -33,26 +33,19 @@ const layoutSettings = reactive({
}) })
const getRemoteConfig = () => { const getRemoteConfig = () => {
fetch('/api/config').then(res => res.json()).then(data => { configStore.refreshConfig()
console.log(data)
configStore.setConfig(data)
})
} }
const getRemoteDatabase = () => { const getRemoteDatabase = () => {
if (!configStore.config.enable_knowledge_base) { if (!configStore.config.enable_knowledge_base) {
return return
} }
fetch('/api/data').then(res => res.json()).then(data => { databaseStore.refreshDatabase()
console.log("database", data)
databaseStore.setDatabase(data.databases)
})
} }
onMounted(() => { onMounted(() => {
getRemoteConfig() getRemoteConfig()
getRemoteDatabase() getRemoteDatabase()
configStore.refreshConfig()
}) })
// 使 vue3 setup composition API // 使 vue3 setup composition API

View File

@ -22,11 +22,15 @@ export const useConfigStore = defineStore('config', () => {
config.value[key] = value config.value[key] = value
fetch('/api/config', { fetch('/api/config', {
method: 'POST', method: 'POST',
body: JSON.stringify(config.value), body: JSON.stringify({ key, value }),
headers: {
'Content-Type': 'application/json'
}
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
console.log('Success:', data) console.debug('Success:', data)
setConfig(data)
}) })
} }
@ -34,6 +38,7 @@ export const useConfigStore = defineStore('config', () => {
fetch('/api/config') fetch('/api/config')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
console.log("config", data)
setConfig(data) setConfig(data)
}) })
} }

View File

@ -7,5 +7,12 @@ export const useDatabaseStore = defineStore('database', () => {
db.value = newDatabase 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 }
}) })

View File

@ -231,8 +231,7 @@ const handleChange = (key, e) => {
return return
} }
console.log('Change', key, e) //
if (key == 'enable_reranker' if (key == 'enable_reranker'
|| key == 'enable_knowledge_graph' || key == 'enable_knowledge_graph'
|| key == 'enable_knowledge_base' || key == 'enable_knowledge_base'
@ -283,14 +282,12 @@ const handleAddCustomModel = async () => {
customModel.visible = false customModel.visible = false
await configStore.setConfigValue('custom_models', configStore.config.custom_models) await configStore.setConfigValue('custom_models', configStore.config.custom_models)
configStore.refreshConfig()
message.success('添加自定义模型成功') message.success('添加自定义模型成功')
} }
const handleDeleteCustomModel = (name) => { const handleDeleteCustomModel = (name) => {
configStore.config.custom_models = configStore.config.custom_models.filter(item => item.name != name) const updatedModels = configStore.config.custom_models.filter(item => item.name !== name);
configStore.setConfigValue('custom_models', configStore.config.custom_models) configStore.setConfigValue('custom_models', updatedModels);
configStore.refreshConfig()
} }
const handleEditCustomModel = (item) => { const handleEditCustomModel = (item) => {
@ -567,4 +564,4 @@ const sendRestart = () => {
} }
} }
</style> </style>