feat: 大模型配置增加思考模式和视觉能力选项
- 数据库新增 enable_thinking 和 enable_vision 字段 - 后台管理表格显示思考🧠和视觉👁️能力状态 - 添加/编辑表单增加开关按钮选择 - 兼容旧数据库自动添加新字段
This commit is contained in:
@@ -54,6 +54,8 @@ def init_db():
|
||||
model TEXT NOT NULL,
|
||||
max_tokens INTEGER DEFAULT 2048,
|
||||
temperature REAL DEFAULT 0.7,
|
||||
enable_thinking INTEGER DEFAULT 0,
|
||||
enable_vision INTEGER DEFAULT 0,
|
||||
is_default INTEGER DEFAULT 0,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -221,6 +223,14 @@ def init_db():
|
||||
'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', 10, 1)
|
||||
''')
|
||||
|
||||
# 检测并添加 llm_configs 新字段(兼容旧数据库)
|
||||
cursor.execute("PRAGMA table_info(llm_configs)")
|
||||
llm_columns = [col[1] for col in cursor.fetchall()]
|
||||
if 'enable_thinking' not in llm_columns:
|
||||
cursor.execute("ALTER TABLE llm_configs ADD COLUMN enable_thinking INTEGER DEFAULT 0")
|
||||
if 'enable_vision' not in llm_columns:
|
||||
cursor.execute("ALTER TABLE llm_configs ADD COLUMN enable_vision INTEGER DEFAULT 0")
|
||||
|
||||
# 初始化默认对话配置
|
||||
cursor.execute('SELECT COUNT(*) FROM chat_configs')
|
||||
if cursor.fetchone()[0] == 0:
|
||||
@@ -1005,10 +1015,11 @@ def add_llm_config():
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO llm_configs (name, provider, api_url, api_key, model, max_tokens, temperature)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO llm_configs (name, provider, api_url, api_key, model, max_tokens, temperature, enable_thinking, enable_vision)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (data['name'], data['provider'], data['api_url'], data['api_key'],
|
||||
data['model'], data.get('max_tokens', 2048), data.get('temperature', 0.7)))
|
||||
data['model'], data.get('max_tokens', 2048), data.get('temperature', 0.7),
|
||||
data.get('enable_thinking', 0), data.get('enable_vision', 0)))
|
||||
conn.commit()
|
||||
config_id = cursor.lastrowid
|
||||
conn.close()
|
||||
@@ -1023,9 +1034,10 @@ def update_llm_config(id):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
UPDATE llm_configs SET name=?, provider=?, api_url=?, api_key=?, model=?,
|
||||
max_tokens=?, temperature=?, updated_at=CURRENT_TIMESTAMP WHERE id=?
|
||||
max_tokens=?, temperature=?, enable_thinking=?, enable_vision=?, updated_at=CURRENT_TIMESTAMP WHERE id=?
|
||||
''', (data['name'], data['provider'], data['api_url'], data['api_key'],
|
||||
data['model'], data.get('max_tokens', 2048), data.get('temperature', 0.7), id))
|
||||
data['model'], data.get('max_tokens', 2048), data.get('temperature', 0.7),
|
||||
data.get('enable_thinking', 0), data.get('enable_vision', 0), id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'success': True})
|
||||
|
||||
Reference in New Issue
Block a user