mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 21:57:14 +08:00
fix: rename zhipu bot_type, persist bot_type in web config, fix re.sub escape error
- Rename ZHIPU_AI bot type from glm-4 to zhipu to avoid confusion with model names - Add bot_type persistence in web config to fix provider dropdown resetting on refresh - Change OpenAI provider key to chatGPT to match bot_factory routing - Add DEEPSEEK constant and route it to ChatGPTBot (OpenAI-compatible API) - Keep backward compatibility for legacy bot_type glm-4 in bot_factory - Fix re.sub bad escape error on Windows paths by using lambda replacement - Remove unused pydantic import in minimax_bot.py Made-with: Cursor
This commit is contained in:
@@ -166,7 +166,8 @@ class Agent:
|
|||||||
# Find and replace the runtime section
|
# Find and replace the runtime section
|
||||||
import re
|
import re
|
||||||
pattern = r'\n## 运行时信息\s*\n.*?(?=\n##|\Z)'
|
pattern = r'\n## 运行时信息\s*\n.*?(?=\n##|\Z)'
|
||||||
updated_prompt = re.sub(pattern, new_runtime_section.rstrip('\n'), prompt, flags=re.DOTALL)
|
_repl = new_runtime_section.rstrip('\n')
|
||||||
|
updated_prompt = re.sub(pattern, lambda m: _repl, prompt, flags=re.DOTALL)
|
||||||
|
|
||||||
return updated_prompt
|
return updated_prompt
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -195,7 +196,9 @@ class Agent:
|
|||||||
|
|
||||||
if has_old_block:
|
if has_old_block:
|
||||||
replacement = new_block or "<available_skills>\n</available_skills>"
|
replacement = new_block or "<available_skills>\n</available_skills>"
|
||||||
prompt = re.sub(old_block_pattern, replacement, prompt, flags=re.DOTALL)
|
# Use lambda to prevent re.sub from interpreting backslashes in replacement
|
||||||
|
# (e.g. Windows paths like \LinkAI would be treated as bad escape sequences)
|
||||||
|
prompt = re.sub(old_block_pattern, lambda m: replacement, prompt, flags=re.DOTALL)
|
||||||
elif new_block:
|
elif new_block:
|
||||||
skills_header = "以下是可用技能:"
|
skills_header = "以下是可用技能:"
|
||||||
idx = prompt.find(skills_header)
|
idx = prompt.find(skills_header)
|
||||||
@@ -224,7 +227,7 @@ class Agent:
|
|||||||
|
|
||||||
# Replace existing tooling section
|
# Replace existing tooling section
|
||||||
pattern = r'## 工具系统\s*\n.*?(?=\n## |\Z)'
|
pattern = r'## 工具系统\s*\n.*?(?=\n## |\Z)'
|
||||||
updated = re.sub(pattern, new_section, prompt, count=1, flags=re.DOTALL)
|
updated = re.sub(pattern, lambda m: new_section, prompt, count=1, flags=re.DOTALL)
|
||||||
return updated
|
return updated
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to rebuild tool list section: {e}")
|
logger.warning(f"Failed to rebuild tool list section: {e}")
|
||||||
|
|||||||
@@ -908,7 +908,9 @@ function initConfigView(data) {
|
|||||||
const providerOpts = Object.entries(configProviders).map(([pid, p]) => ({ value: pid, label: p.label }));
|
const providerOpts = Object.entries(configProviders).map(([pid, p]) => ({ value: pid, label: p.label }));
|
||||||
|
|
||||||
// if use_linkai is enabled, always select linkai as the provider
|
// if use_linkai is enabled, always select linkai as the provider
|
||||||
const detected = data.use_linkai ? 'linkai' : detectProvider(configCurrentModel);
|
// Otherwise prefer bot_type from config, fall back to model-based detection
|
||||||
|
const detected = data.use_linkai ? 'linkai'
|
||||||
|
: (data.bot_type && configProviders[data.bot_type] ? data.bot_type : detectProvider(configCurrentModel));
|
||||||
cfgProviderValue = detected || (providerOpts[0] ? providerOpts[0].value : '');
|
cfgProviderValue = detected || (providerOpts[0] ? providerOpts[0].value : '');
|
||||||
|
|
||||||
initDropdown(providerEl, providerOpts, cfgProviderValue, onProviderChange);
|
initDropdown(providerEl, providerOpts, cfgProviderValue, onProviderChange);
|
||||||
@@ -1062,6 +1064,14 @@ function saveModelConfig() {
|
|||||||
const updates = { model: model };
|
const updates = { model: model };
|
||||||
const p = configProviders[cfgProviderValue];
|
const p = configProviders[cfgProviderValue];
|
||||||
updates.use_linkai = (cfgProviderValue === 'linkai');
|
updates.use_linkai = (cfgProviderValue === 'linkai');
|
||||||
|
// Save bot_type for bot_factory routing.
|
||||||
|
// Most providers use their key directly as bot_type.
|
||||||
|
// linkai uses use_linkai flag instead of bot_type.
|
||||||
|
if (cfgProviderValue === 'linkai') {
|
||||||
|
updates.bot_type = '';
|
||||||
|
} else {
|
||||||
|
updates.bot_type = cfgProviderValue;
|
||||||
|
}
|
||||||
if (p && p.api_base_key) {
|
if (p && p.api_base_key) {
|
||||||
const base = document.getElementById('cfg-api-base').value.trim();
|
const base = document.getElementById('cfg-api-base').value.trim();
|
||||||
if (base) updates[p.api_base_key] = base;
|
if (base) updates[p.api_base_key] = base;
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ class ConfigHandler:
|
|||||||
"api_base_default": None,
|
"api_base_default": None,
|
||||||
"models": [const.MINIMAX_M2_5, const.MINIMAX_M2_1, const.MINIMAX_M2_1_LIGHTNING],
|
"models": [const.MINIMAX_M2_5, const.MINIMAX_M2_1, const.MINIMAX_M2_1_LIGHTNING],
|
||||||
}),
|
}),
|
||||||
("glm-4", {
|
("zhipu", {
|
||||||
"label": "智谱AI",
|
"label": "智谱AI",
|
||||||
"api_key_field": "zhipu_ai_api_key",
|
"api_key_field": "zhipu_ai_api_key",
|
||||||
"api_base_key": "zhipu_ai_api_base",
|
"api_base_key": "zhipu_ai_api_base",
|
||||||
@@ -448,7 +448,7 @@ class ConfigHandler:
|
|||||||
"api_base_default": "https://generativelanguage.googleapis.com",
|
"api_base_default": "https://generativelanguage.googleapis.com",
|
||||||
"models": [const.GEMINI_31_PRO_PRE, const.GEMINI_3_FLASH_PRE],
|
"models": [const.GEMINI_31_PRO_PRE, const.GEMINI_3_FLASH_PRE],
|
||||||
}),
|
}),
|
||||||
("openAI", {
|
("chatGPT", {
|
||||||
"label": "OpenAI",
|
"label": "OpenAI",
|
||||||
"api_key_field": "open_ai_api_key",
|
"api_key_field": "open_ai_api_key",
|
||||||
"api_base_key": "open_ai_api_base",
|
"api_base_key": "open_ai_api_base",
|
||||||
@@ -472,7 +472,7 @@ class ConfigHandler:
|
|||||||
])
|
])
|
||||||
|
|
||||||
EDITABLE_KEYS = {
|
EDITABLE_KEYS = {
|
||||||
"model", "use_linkai",
|
"model", "bot_type", "use_linkai",
|
||||||
"open_ai_api_base", "claude_api_base", "gemini_api_base",
|
"open_ai_api_base", "claude_api_base", "gemini_api_base",
|
||||||
"zhipu_ai_api_base", "moonshot_base_url", "ark_base_url",
|
"zhipu_ai_api_base", "moonshot_base_url", "ark_base_url",
|
||||||
"open_ai_api_key", "claude_api_key", "gemini_api_key",
|
"open_ai_api_key", "claude_api_key", "gemini_api_key",
|
||||||
@@ -522,6 +522,7 @@ class ConfigHandler:
|
|||||||
"use_agent": use_agent,
|
"use_agent": use_agent,
|
||||||
"title": title,
|
"title": title,
|
||||||
"model": local_config.get("model", ""),
|
"model": local_config.get("model", ""),
|
||||||
|
"bot_type": local_config.get("bot_type", ""),
|
||||||
"use_linkai": bool(local_config.get("use_linkai", False)),
|
"use_linkai": bool(local_config.get("use_linkai", False)),
|
||||||
"channel_type": local_config.get("channel_type", ""),
|
"channel_type": local_config.get("channel_type", ""),
|
||||||
"agent_max_context_tokens": local_config.get("agent_max_context_tokens", 50000),
|
"agent_max_context_tokens": local_config.get("agent_max_context_tokens", 50000),
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ CLAUDEAPI= "claudeAPI"
|
|||||||
QWEN = "qwen" # 旧版千问接入
|
QWEN = "qwen" # 旧版千问接入
|
||||||
QWEN_DASHSCOPE = "dashscope" # 新版千问接入(百炼)
|
QWEN_DASHSCOPE = "dashscope" # 新版千问接入(百炼)
|
||||||
GEMINI = "gemini"
|
GEMINI = "gemini"
|
||||||
ZHIPU_AI = "glm-4"
|
ZHIPU_AI = "zhipu"
|
||||||
MOONSHOT = "moonshot"
|
MOONSHOT = "moonshot"
|
||||||
MiniMax = "minimax"
|
MiniMax = "minimax"
|
||||||
|
DEEPSEEK = "deepseek"
|
||||||
MODELSCOPE = "modelscope"
|
MODELSCOPE = "modelscope"
|
||||||
|
|
||||||
# 模型列表
|
# 模型列表
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ def create_bot(bot_type):
|
|||||||
from models.baidu.baidu_wenxin import BaiduWenxinBot
|
from models.baidu.baidu_wenxin import BaiduWenxinBot
|
||||||
return BaiduWenxinBot()
|
return BaiduWenxinBot()
|
||||||
|
|
||||||
elif bot_type == const.CHATGPT:
|
elif bot_type in (const.CHATGPT, const.DEEPSEEK): # DeepSeek uses OpenAI-compatible API
|
||||||
# ChatGPT 网页端web接口
|
|
||||||
from models.chatgpt.chat_gpt_bot import ChatGPTBot
|
from models.chatgpt.chat_gpt_bot import ChatGPTBot
|
||||||
return ChatGPTBot()
|
return ChatGPTBot()
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ def create_bot(bot_type):
|
|||||||
from models.gemini.google_gemini_bot import GoogleGeminiBot
|
from models.gemini.google_gemini_bot import GoogleGeminiBot
|
||||||
return GoogleGeminiBot()
|
return GoogleGeminiBot()
|
||||||
|
|
||||||
elif bot_type == const.ZHIPU_AI:
|
elif bot_type == const.ZHIPU_AI or bot_type == "glm-4": # "glm-4" kept for backward compatibility
|
||||||
from models.zhipuai.zhipuai_bot import ZHIPUAIBot
|
from models.zhipuai.zhipuai_bot import ZHIPUAIBot
|
||||||
return ZHIPUAIBot()
|
return ZHIPUAIBot()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from pydantic.types import T
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from models.bot import Bot
|
from models.bot import Bot
|
||||||
|
|||||||
Reference in New Issue
Block a user