fix: 对话配置扁平化+启用联网搜索移到对话配置

对话配置改为单配置:
- 只有一个默认配置,所有用户共用
- 去掉添加/删除配置按钮和逻辑
- 直接编辑保存配置

配置参数扁平化:
- enable_search 启用联网搜索开关
- LLM配置、可用工具、历史记录数、Temperature、系统提示词

启用联网搜索开关:
- 从系统设置移到对话配置页面
- 开关自动添加/移除 search 工具

系统设置简化:
- 去掉启用联网搜索开关
- 提示用户去对话配置页面设置
This commit is contained in:
2026-04-27 13:04:03 +08:00
parent 423f3aa717
commit c725aeb192
2 changed files with 113 additions and 214 deletions

View File

@@ -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/<config_id>', 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/<config_id>', 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/<config_id>/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})