diff --git a/works/ai-chat-app/backend/app.py b/works/ai-chat-app/backend/app.py index 30b3913..236b847 100644 --- a/works/ai-chat-app/backend/app.py +++ b/works/ai-chat-app/backend/app.py @@ -46,6 +46,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, @@ -53,6 +55,16 @@ def init_db(): ) ''') + # 兼容旧数据库:添加缺失的字段 + try: + cursor.execute('ALTER TABLE llm_configs ADD COLUMN enable_thinking INTEGER DEFAULT 0') + except: + pass + try: + cursor.execute('ALTER TABLE llm_configs ADD COLUMN enable_vision INTEGER DEFAULT 0') + except: + pass + # 智能体配置表 cursor.execute(''' CREATE TABLE IF NOT EXISTS agents ( @@ -601,10 +613,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() @@ -619,9 +632,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}) diff --git a/works/ai-chat-app/www/admin.js b/works/ai-chat-app/www/admin.js index 6ecafd3..a215d65 100644 --- a/works/ai-chat-app/www/admin.js +++ b/works/ai-chat-app/www/admin.js @@ -414,8 +414,9 @@ async function loadLLMPage(content) { 名称 提供商 模型 + 思考模式 + 视觉能力 API URL - 状态 操作 @@ -425,8 +426,9 @@ async function loadLLMPage(content) { ${c.name} ${c.is_default ? '默认' : ''} ${c.provider} ${c.model} + ${c.enable_thinking ? '✅ 支持' : '❌ 不支持'} + ${c.enable_vision ? '✅ 支持' : '❌ 不支持'} ${c.api_url} - ${c.is_active ? '✅ 启用' : '❌ 禁用'}
@@ -477,6 +479,18 @@ function showAddLLMModal() {
+
+ + 模型是否支持原生思考功能(如DeepSeek的think标签) +
+
+ + 模型是否支持图片输入和分析 +
`); } @@ -519,6 +533,18 @@ function showEditLLMModal(id) { +
+ + 模型是否支持原生思考功能(如DeepSeek的think标签) +
+
+ + 模型是否支持图片输入和分析 +
`); } @@ -531,7 +557,9 @@ async function saveLLM() { api_key: document.getElementById('llmApiKey').value, model: document.getElementById('llmModel').value, max_tokens: parseInt(document.getElementById('llmMaxTokens').value), - temperature: parseFloat(document.getElementById('llmTemperature').value) + temperature: parseFloat(document.getElementById('llmTemperature').value), + enable_thinking: document.getElementById('llmEnableThinking').checked ? 1 : 0, + enable_vision: document.getElementById('llmEnableVision').checked ? 1 : 0 }; if (!data.name || !data.api_url || !data.api_key || !data.model) { @@ -553,7 +581,9 @@ async function updateLLM(id) { api_key: document.getElementById('llmApiKey').value, model: document.getElementById('llmModel').value, max_tokens: parseInt(document.getElementById('llmMaxTokens').value), - temperature: parseFloat(document.getElementById('llmTemperature').value) + temperature: parseFloat(document.getElementById('llmTemperature').value), + enable_thinking: document.getElementById('llmEnableThinking').checked ? 1 : 0, + enable_vision: document.getElementById('llmEnableVision').checked ? 1 : 0 }; await fetchAPI(`/api/admin/llm/${id}`, 'PUT', data);