Compare commits

..

2 Commits

Author SHA1 Message Date
d4b1f3dfff fix: 自动拼接/chat/completions到API URL 2026-04-29 00:30:47 +08:00
dc2e822ea9 fix: 普通对话使用后台配置的LLM 2026-04-28 22:53:22 +08:00
2 changed files with 19 additions and 7 deletions

View File

@@ -1345,10 +1345,20 @@ def get_frontend_config():
conn = get_db()
cursor = conn.cursor()
# 获取默认LLM配置
cursor.execute('SELECT * FROM llm_configs WHERE is_default=1 AND is_active=1 LIMIT 1')
# 获取默认对话配置
cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1')
chat_config = cursor.fetchone()
# 根据对话配置中的 llm_config_id 获取对应的 LLM 配置
llm_config_id = chat_config['llm_config_id'] if chat_config else 1
cursor.execute('SELECT * FROM llm_configs WHERE id=?', (llm_config_id,))
llm = cursor.fetchone()
# 如果找不到对应的LLM配置使用默认的
if not llm:
cursor.execute('SELECT * FROM llm_configs WHERE is_default=1 LIMIT 1')
llm = cursor.fetchone()
# 获取默认工具配置(搜索等)
cursor.execute('SELECT * FROM tool_configs WHERE is_default=1 AND is_active=1')
tools = [dict(row) for row in cursor.fetchall()]
@@ -1361,10 +1371,6 @@ def get_frontend_config():
cursor.execute('SELECT agent_id, name, avatar, category, description, system_prompt, heat, tags, enable_tools FROM agents WHERE is_online=1 AND is_active=1')
agents = [dict(row) for row in cursor.fetchall()]
# 获取默认对话配置
cursor.execute('SELECT * FROM chat_configs WHERE is_default=1 LIMIT 1')
chat_config = cursor.fetchone()
# 获取系统配置
cursor.execute('SELECT key, value FROM system_configs')
system = {row['key']: row['value'] for row in cursor.fetchall()}

View File

@@ -140,7 +140,13 @@ async function loadBackendConfig() {
// 将后台 LLM 配置赋值到 CONFIG
if (backendConfig.llm) {
CONFIG.apiUrl = backendConfig.llm.api_url;
// 自动拼接 /chat/completions如果不是完整URL
let apiUrl = backendConfig.llm.api_url;
if (apiUrl && !apiUrl.includes('/chat/completions')) {
// 确保URL以/结尾再拼接,或直接拼接
apiUrl = apiUrl.endsWith('/') ? apiUrl + 'chat/completions' : apiUrl + '/chat/completions';
}
CONFIG.apiUrl = apiUrl;
CONFIG.apiKey = backendConfig.llm.api_key;
CONFIG.model = backendConfig.llm.model;
CONFIG.maxTokens = backendConfig.llm.max_tokens || 2048;