From c725aeb192a4c968efde7609b64de9674620cc8d Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Mon, 27 Apr 2026 13:04:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9=E8=AF=9D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=89=81=E5=B9=B3=E5=8C=96+=E5=90=AF=E7=94=A8=E8=81=94?= =?UTF-8?q?=E7=BD=91=E6=90=9C=E7=B4=A2=E7=A7=BB=E5=88=B0=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对话配置改为单配置: - 只有一个默认配置,所有用户共用 - 去掉添加/删除配置按钮和逻辑 - 直接编辑保存配置 配置参数扁平化: - enable_search 启用联网搜索开关 - LLM配置、可用工具、历史记录数、Temperature、系统提示词 启用联网搜索开关: - 从系统设置移到对话配置页面 - 开关自动添加/移除 search 工具 系统设置简化: - 去掉启用联网搜索开关 - 提示用户去对话配置页面设置 --- backend/app.py | 79 ++++++---------- www/admin.js | 248 +++++++++++++++++-------------------------------- 2 files changed, 113 insertions(+), 214 deletions(-) diff --git a/backend/app.py b/backend/app.py index 25ccfb0..5c2ad10 100644 --- a/backend/app.py +++ b/backend/app.py @@ -102,11 +102,12 @@ def init_db(): config_id TEXT NOT NULL UNIQUE, name TEXT NOT NULL, llm_config_id INTEGER, + enable_search INTEGER DEFAULT 1, enable_tools TEXT, max_history INTEGER DEFAULT 20, temperature REAL DEFAULT 0.7, system_prompt TEXT, - is_default INTEGER DEFAULT 0, + is_default INTEGER DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (llm_config_id) REFERENCES llm_configs(id) @@ -423,67 +424,41 @@ def delete_agent(agent_id): # ==================== 对话配置管理 ==================== @app.route('/api/admin/chat', methods=['GET']) -def get_chat_configs(): - """获取对话配置""" +def get_chat_config(): + """获取对话配置(只有一个默认配置)""" conn = get_db() cursor = conn.cursor() - cursor.execute('SELECT * FROM chat_configs ORDER BY is_default DESC') - configs = [dict(row) for row in cursor.fetchall()] + cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1') + config = cursor.fetchone() + + if not config: + # 如果没有配置,创建默认配置 + cursor.execute(''' + INSERT INTO chat_configs (config_id, name, llm_config_id, enable_search, enable_tools, max_history, temperature, is_default) + VALUES ('default', '默认配置', 1, 1, 'search', 20, 0.7, 1) + ''') + conn.commit() + cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1') + config = cursor.fetchone() + conn.close() - return jsonify(configs) + return jsonify(dict(config) if config else {}) -@app.route('/api/admin/chat', methods=['POST']) -def add_chat_config(): - """添加对话配置""" - data = request.json - conn = get_db() - cursor = conn.cursor() - cursor.execute(''' - INSERT INTO chat_configs (config_id, name, llm_config_id, enable_tools, max_history, temperature, system_prompt) - VALUES (?, ?, ?, ?, ?, ?, ?) - ''', (data['config_id'], data['name'], data.get('llm_config_id'), data.get('enable_tools', ''), - data.get('max_history', 20), data.get('temperature', 0.7), data.get('system_prompt', ''))) - conn.commit() - conn.close() - return jsonify({'success': True}) - - -@app.route('/api/admin/chat/', methods=['PUT']) -def update_chat_config(config_id): +@app.route('/api/admin/chat', methods=['PUT']) +def update_chat_config(): """更新对话配置""" data = request.json conn = get_db() cursor = conn.cursor() cursor.execute(''' - UPDATE chat_configs SET name=?, llm_config_id=?, enable_tools=?, max_history=?, - temperature=?, system_prompt=?, updated_at=CURRENT_TIMESTAMP WHERE config_id=? - ''', (data['name'], data.get('llm_config_id'), data.get('enable_tools', ''), - data.get('max_history', 20), data.get('temperature', 0.7), - data.get('system_prompt', ''), config_id)) - conn.commit() - conn.close() - return jsonify({'success': True}) - - -@app.route('/api/admin/chat/', methods=['DELETE']) -def delete_chat_config(config_id): - """删除对话配置""" - conn = get_db() - cursor = conn.cursor() - cursor.execute('DELETE FROM chat_configs WHERE config_id=?', (config_id,)) - conn.commit() - conn.close() - return jsonify({'success': True}) - - -@app.route('/api/admin/chat//default', methods=['POST']) -def set_default_chat(config_id): - """设置默认对话配置""" - conn = get_db() - cursor = conn.cursor() - cursor.execute('UPDATE chat_configs SET is_default=0') - cursor.execute('UPDATE chat_configs SET is_default=1 WHERE config_id=?', (config_id,)) + UPDATE chat_configs SET + llm_config_id=?, enable_search=?, enable_tools=?, max_history=?, + temperature=?, system_prompt=?, updated_at=CURRENT_TIMESTAMP + WHERE is_default=1 + ''', (data.get('llm_config_id', 1), data.get('enable_search', 1), + data.get('enable_tools', 'search'), data.get('max_history', 20), + data.get('temperature', 0.7), data.get('system_prompt', ''))) conn.commit() conn.close() return jsonify({'success': True}) diff --git a/www/admin.js b/www/admin.js index c5abc12..068c2c1 100644 --- a/www/admin.js +++ b/www/admin.js @@ -586,186 +586,113 @@ async function deleteAgent(agentId) { // ==================== 对话配置页面 ==================== async function loadChatConfigPage(content) { - chatConfigs = await fetchAPI('/api/admin/chat'); llmConfigs = await fetchAPI('/api/admin/llm'); toolConfigs = await fetchAPI('/api/admin/tools'); + const chatConfig = await fetchAPI('/api/admin/chat'); content.innerHTML = `

对话配置

-
-
- - - - - - - - - - - - - - ${chatConfigs.map(c => ` - - - - - - - - - - `).join('')} - -
配置名称LLM可用工具历史记录数Temperature状态操作
${c.name} ${c.is_default ? '默认' : ''}${llmConfigs.find(l => l.id === c.llm_config_id)?.name || '未指定'}${c.enable_tools || '无'}${c.max_history || 20}${c.temperature || 0.7}${c.is_default ? '✅ 默认' : '-'} -
- - ${!c.is_default ? `` : ''} - -
-
+
+

+ 此配置对所有用户的普通对话生效,修改后立即生效。 +

+ +
+ + +
+ +
+ + 开启后对话可联网搜索实时信息 +
+ +
+ + + 已配置工具: ${toolConfigs.map(t => t.tool_id).join(', ')} +
+ +
+ + + 发送给模型的对话历史条数 +
+ +
+ + + 0-2之间,越高越随机创造性,越低越稳定精确 +
+ +
+ + +
+ +
-

对话配置说明

-

- 对话配置用于控制普通对话的各项参数。可以选择使用的大模型接口、启用的工具、历史记录数量等。 - 前端 APP 会自动使用默认配置进行对话。 -

+

参数说明

+
+
+ 🧠 LLM配置 +

选择对话使用的大模型接口

+
+
+ 🔍 启用联网搜索 +

用户可在对话中开启联网搜索

+
+
+ 🔧 可用工具 +

对话中可使用的工具列表

+
+
+ 📜 历史记录数 +

发送多少条历史对话给模型

+
+
`; } -function showAddChatConfigModal() { - showModal('添加对话配置', ` -
- - -
-
- - -
-
- - -
-
- - - 可用工具: ${toolConfigs.map(t => t.tool_id).join(', ')} -
-
- - -
-
- - -
-
- - -
- - `); -} - -function showEditChatConfigModal(configId) { - const config = chatConfigs.find(c => c.config_id === configId); - if (!config) return; +function toggleEnableSearch() { + const enableSearch = document.getElementById('chatEnableSearch').checked; + const toolsInput = document.getElementById('chatEnableTools'); - showModal('编辑对话配置', ` -
- - -
-
- - -
-
- - -
-
- - - 可用工具: ${toolConfigs.map(t => t.tool_id).join(', ')} -
-
- - -
-
- - -
-
- - -
- - `); + // 自动添加/移除 search 工具 + let tools = toolsInput.value.split(',').filter(t => t.trim()); + if (enableSearch) { + if (!tools.includes('search')) { + tools.push('search'); + } + } else { + tools = tools.filter(t => t !== 'search'); + } + toolsInput.value = tools.join(','); } async function saveChatConfig() { const data = { - config_id: document.getElementById('chatConfigId').value, - name: document.getElementById('chatConfigName').value, llm_config_id: parseInt(document.getElementById('chatLLMConfig').value), + enable_search: document.getElementById('chatEnableSearch').checked ? 1 : 0, enable_tools: document.getElementById('chatEnableTools').value, max_history: parseInt(document.getElementById('chatMaxHistory').value), temperature: parseFloat(document.getElementById('chatTemperature').value), system_prompt: document.getElementById('chatSystemPrompt').value }; - if (!data.config_id || !data.name) { - showToast('请填写完整信息'); - return; - } - - await fetchAPI('/api/admin/chat', 'POST', data); - closeModal(); - showToast('添加成功'); - loadPage('chat'); -} - -async function updateChatConfig(configId) { - const data = { - name: document.getElementById('chatConfigName').value, - llm_config_id: parseInt(document.getElementById('chatLLMConfig').value), - enable_tools: document.getElementById('chatEnableTools').value, - max_history: parseInt(document.getElementById('chatMaxHistory').value), - temperature: parseFloat(document.getElementById('chatTemperature').value), - system_prompt: document.getElementById('chatSystemPrompt').value - }; - - await fetchAPI(`/api/admin/chat/${configId}`, 'PUT', data); - closeModal(); - showToast('更新成功'); - loadPage('chat'); -} - -async function setDefaultChatConfig(configId) { - await fetchAPI(`/api/admin/chat/${configId}/default`, 'POST'); - showToast('已设为默认'); - loadPage('chat'); -} - -async function deleteChatConfig(configId) { - if (!confirm('确定删除此配置?')) return; - await fetchAPI(`/api/admin/chat/${configId}`, 'DELETE'); - showToast('删除成功'); + await fetchAPI('/api/admin/chat', 'PUT', data); + showToast('保存成功'); loadPage('chat'); } @@ -1013,13 +940,6 @@ async function loadSystemPage(content) {
-
- -
-

游客使用限制

@@ -1046,6 +966,12 @@ async function loadSystemPage(content) {
+ +
+

+ 💡 提示:启用联网搜索等对话相关配置请前往"对话配置"页面设置 +

+
`; } @@ -1053,7 +979,6 @@ async function saveSystemConfig() { const data = { app_name: document.getElementById('appName').value, app_version: document.getElementById('appVersion').value, - enable_search: document.getElementById('enableSearch').checked ? 'true' : 'false', guest_chat_sessions: document.getElementById('guestChatSessions').value, guest_chat_messages: document.getElementById('guestChatMessages').value, guest_agent_messages: document.getElementById('guestAgentMessages').value, @@ -1062,7 +987,6 @@ async function saveSystemConfig() { await fetchAPI('/api/admin/system', 'POST', data); showToast('保存成功'); - loadPage('system'); } // ==================== 工具函数 ====================