From 7a2c15d9124df3ab177abcb2ed93f9387a1f84d9 Mon Sep 17 00:00:00 2001 From: 6vision Date: Wed, 5 Jun 2024 00:44:08 +0800 Subject: [PATCH 1/6] Update model list --- README.md | 2 +- bot/baidu/baidu_wenxin.py | 11 +++++--- common/const.py | 56 ++++++++++++++++++++++++++++----------- config.py | 4 +-- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 33e8a47..5f73eba 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ pip3 install -r requirements-optional.txt **4.其他配置** -+ `model`: 模型名称,目前支持 `gpt-3.5-turbo`, `gpt-4o`, `gpt-4-turbo`, `gpt-4`, `wenxin` , `claude` , `gemini`, `glm-4`, `xunfei`, `moonshot` ++ `model`: 模型名称,目前支持 `gpt-3.5-turbo`, `gpt-4o`, `gpt-4-turbo`, `gpt-4`, `wenxin` , `claude` , `gemini`, `glm-4`, `xunfei`, `moonshot`等,全部模型名称参考`common/const.py`文件 + `temperature`,`frequency_penalty`,`presence_penalty`: Chat API接口参数,详情参考[OpenAI官方文档。](https://platform.openai.com/docs/api-reference/chat) + `proxy`:由于目前 `openai` 接口国内无法访问,需配置代理客户端的地址,详情参考 [#351](https://github.com/zhayujie/chatgpt-on-wechat/issues/351) + 对于图像生成,在满足个人或群组触发条件外,还需要额外的关键词前缀来触发,对应配置 `image_create_prefix ` diff --git a/bot/baidu/baidu_wenxin.py b/bot/baidu/baidu_wenxin.py index 81b5748..0e91668 100644 --- a/bot/baidu/baidu_wenxin.py +++ b/bot/baidu/baidu_wenxin.py @@ -1,6 +1,8 @@ # encoding:utf-8 -import requests, json +import requests +import json +from common import const from bot.bot import Bot from bot.session_manager import SessionManager from bridge.context import ContextType @@ -16,9 +18,12 @@ class BaiduWenxinBot(Bot): def __init__(self): super().__init__() - wenxin_model = conf().get("baidu_wenxin_model") or "eb-instant" - if conf().get("model") and conf().get("model") == "wenxin-4": + wenxin_model = conf().get("baidu_wenxin_model") or "completions" + if conf().get("model") and conf().get("model") == const.WEN_XIN: + wenxin_model = "completions" + if conf().get("model") and conf().get("model") == const.WEN_XIN_4: wenxin_model = "completions_pro" + self.sessions = SessionManager(BaiduWenxinSession, model=wenxin_model) def reply(self, query, context=None): diff --git a/common/const.py b/common/const.py index 2c8d01e..abbb626 100644 --- a/common/const.py +++ b/common/const.py @@ -1,18 +1,16 @@ # bot_type OPEN_AI = "openAI" CHATGPT = "chatGPT" -BAIDU = "baidu" +BAIDU = "baidu" # 百度文心一言模型 XUNFEI = "xunfei" CHATGPTONAZURE = "chatGPTOnAzure" LINKAI = "linkai" -CLAUDEAI = "claude" -CLAUDEAPI= "claudeAPI" -QWEN = "qwen" +CLAUDEAI = "claude" # 使用cookie的历史模型 +CLAUDEAPI= "claudeAPI" # 通过Claude api调用模型 +QWEN = "qwen" # 旧版通义模型 + +QWEN_DASHSCOPE = "dashscope" # 通义新版sdk和api key -QWEN_DASHSCOPE = "dashscope" -QWEN_TURBO = "qwen-turbo" -QWEN_PLUS = "qwen-plus" -QWEN_MAX = "qwen-max" GEMINI = "gemini" ZHIPU_AI = "glm-4" @@ -22,22 +20,48 @@ MOONSHOT = "moonshot" # model CLAUDE3 = "claude-3-opus-20240229" GPT35 = "gpt-3.5-turbo" -GPT4 = "gpt-4" +GPT35_0125 = "gpt-3.5-turbo-0125" +GPT35_1106 = "gpt-3.5-turbo-1106" + GPT_4o = "gpt-4o" -LINKAI_35 = "linkai-3.5" -LINKAI_4_TURBO = "linkai-4-turbo" -LINKAI_4o = "linkai-4o" -GPT4_TURBO_PREVIEW = "gpt-4-turbo-2024-04-09" +GPT4_TURBO = "gpt-4-turbo" +GPT4_TURBO_PREVIEW = "gpt-4-turbo-preview" GPT4_TURBO_04_09 = "gpt-4-turbo-2024-04-09" GPT4_TURBO_01_25 = "gpt-4-0125-preview" +GPT4_TURBO_11_06 = "gpt-4-1106-preview" GPT4_VISION_PREVIEW = "gpt-4-vision-preview" + +GPT4 = "gpt-4" +GPT4_32k = "gpt-4-32k" +GPT4_06_13 = "gpt-4-0613" +GPT4_32k_06_13 = "gpt-4-32k-0613" + WHISPER_1 = "whisper-1" TTS_1 = "tts-1" TTS_1_HD = "tts-1-hd" -MODEL_LIST = ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "wenxin", "wenxin-4", "xunfei", "claude", "claude-3-opus-20240229", "gpt-4-turbo", - "gpt-4-turbo-preview", "gpt-4-1106-preview", GPT4_TURBO_PREVIEW, GPT4_TURBO_01_25, GPT_4o, QWEN, GEMINI, ZHIPU_AI, MOONSHOT, - QWEN_TURBO, QWEN_PLUS, QWEN_MAX, LINKAI_35, LINKAI_4_TURBO, LINKAI_4o] +WEN_XIN = "wenxin" +WEN_XIN_4 = "wenxin-4" + +QWEN_TURBO = "qwen-turbo" +QWEN_PLUS = "qwen-plus" +QWEN_MAX = "qwen-max" + +LINKAI_35 = "linkai-3.5" +LINKAI_4_TURBO = "linkai-4-turbo" +LINKAI_4o = "linkai-4o" + + +MODEL_LIST = [ + GPT35, GPT35_0125, GPT35_1106, "gpt-3.5-turbo-16k", + GPT_4o, GPT4_TURBO, GPT4_TURBO_PREVIEW, GPT4_TURBO_01_25, GPT4_TURBO_11_06, GPT4, GPT4_32k, GPT4_06_13, GPT4_32k_06_13, + WEN_XIN, WEN_XIN_4, + XUNFEI, GEMINI, ZHIPU_AI, MOONSHOT, + "claude", "claude-3-haiku", "claude-3-sonnet", "claude-3-opus", "claude-3-opus-20240229", + "moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k", + LINKAI_35, LINKAI_4_TURBO, LINKAI_4o, + QWEN, QWEN_TURBO, QWEN_PLUS, QWEN_MAX + ] # channel FEISHU = "feishu" diff --git a/config.py b/config.py index 6556203..bff03bb 100644 --- a/config.py +++ b/config.py @@ -17,7 +17,7 @@ available_setting = { "open_ai_api_base": "https://api.openai.com/v1", "proxy": "", # openai使用的代理 # chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称 - "model": "gpt-3.5-turbo", # 还支持 gpt-4, gpt-4-turbo, wenxin, xunfei, qwen + "model": "gpt-3.5-turbo", # 支持ChatGPT、Claude、Gemini、文心一言、通义千问、Kimi、讯飞星火、智谱、LinkAI等模型,模型具体名称详见common/const.py文件列出的模型 "use_azure_chatgpt": False, # 是否使用azure的chatgpt "azure_deployment_id": "", # azure 模型部署名称 "azure_api_version": "", # azure api版本 @@ -83,7 +83,7 @@ available_setting = { "qwen_agent_key": "", "qwen_app_id": "", "qwen_node_id": "", # 流程编排模型用到的id,如果没有用到qwen_node_id,请务必保持为空字符串 - # 阿里灵积模型api key + # 阿里灵积(通义新版sdk)模型api key "dashscope_api_key": "", # Google Gemini Api Key "gemini_api_key": "", From 5de8e94bb49998c8f4429e329390c67aed2d6dd3 Mon Sep 17 00:00:00 2001 From: 6vision Date: Wed, 5 Jun 2024 01:25:03 +0800 Subject: [PATCH 2/6] update readme --- README.md | 2 +- bot/baidu/baidu_wenxin.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5f73eba..ee76b04 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ pip3 install -r requirements-optional.txt **4.其他配置** -+ `model`: 模型名称,目前支持 `gpt-3.5-turbo`, `gpt-4o`, `gpt-4-turbo`, `gpt-4`, `wenxin` , `claude` , `gemini`, `glm-4`, `xunfei`, `moonshot`等,全部模型名称参考`common/const.py`文件 ++ `model`: 模型名称,目前支持 `gpt-3.5-turbo`, `gpt-4o`, `gpt-4-turbo`, `gpt-4`, `wenxin` , `claude` , `gemini`, `glm-4`, `xunfei`, `moonshot`等,全部模型名称参考[common/const.py](https://github.com/zhayujie/chatgpt-on-wechat/blob/master/common/const.py)文件 + `temperature`,`frequency_penalty`,`presence_penalty`: Chat API接口参数,详情参考[OpenAI官方文档。](https://platform.openai.com/docs/api-reference/chat) + `proxy`:由于目前 `openai` 接口国内无法访问,需配置代理客户端的地址,详情参考 [#351](https://github.com/zhayujie/chatgpt-on-wechat/issues/351) + 对于图像生成,在满足个人或群组触发条件外,还需要额外的关键词前缀来触发,对应配置 `image_create_prefix ` diff --git a/bot/baidu/baidu_wenxin.py b/bot/baidu/baidu_wenxin.py index 0e91668..ff78e75 100644 --- a/bot/baidu/baidu_wenxin.py +++ b/bot/baidu/baidu_wenxin.py @@ -18,11 +18,14 @@ class BaiduWenxinBot(Bot): def __init__(self): super().__init__() - wenxin_model = conf().get("baidu_wenxin_model") or "completions" - if conf().get("model") and conf().get("model") == const.WEN_XIN: - wenxin_model = "completions" - if conf().get("model") and conf().get("model") == const.WEN_XIN_4: - wenxin_model = "completions_pro" + wenxin_model = conf().get("baidu_wenxin_model") + if wenxin_model is not None: + wenxin_model = conf().get("baidu_wenxin_model") or "eb-instant" + else: + if conf().get("model") and conf().get("model") == const.WEN_XIN: + wenxin_model = "completions" + elif conf().get("model") and conf().get("model") == const.WEN_XIN_4: + wenxin_model = "completions_pro" self.sessions = SessionManager(BaiduWenxinSession, model=wenxin_model) From c2b01cc95763e88fa60f0a750257cfaec0833e03 Mon Sep 17 00:00:00 2001 From: 6vision Date: Wed, 5 Jun 2024 17:10:08 +0800 Subject: [PATCH 3/6] Add configuration to plugin configuration template. --- plugins/config.json.template | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/config.json.template b/plugins/config.json.template index 95a59bc..a491fe5 100644 --- a/plugins/config.json.template +++ b/plugins/config.json.template @@ -40,5 +40,22 @@ "max_file_size": 5000, "type": ["FILE", "SHARING"] } + }, + "hello":{ + "group_welc_fixed_msg": { + "群聊1": "群聊1的固定欢迎语", + "群聊2": "群聊2的固定欢迎语" + }, + "group_welc_prompt": "请你随机使用一种风格说一句问候语来欢迎新用户\"{nickname}\"加入群聊。", + + "group_exit_prompt": "请你随机使用一种风格跟其他群用户说他违反规则\"{nickname}\"退出群聊。", + + "patpat_prompt": "请你随机使用一种风格介绍你自己,并告诉用户输入#help可以查看帮助信息。", + + "use_character_desc": false + }, + "Apilot"{ + "alapi_token": "xxx", + "morning_news_text_enabled": false } } From 1da7991c656aee4ea3ca7d93e1960f4da494812e Mon Sep 17 00:00:00 2001 From: 6vision Date: Sat, 8 Jun 2024 00:09:05 +0800 Subject: [PATCH 4/6] fix --- plugins/config.json.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/config.json.template b/plugins/config.json.template index a491fe5..f4915d6 100644 --- a/plugins/config.json.template +++ b/plugins/config.json.template @@ -41,7 +41,7 @@ "type": ["FILE", "SHARING"] } }, - "hello":{ + "hello": { "group_welc_fixed_msg": { "群聊1": "群聊1的固定欢迎语", "群聊2": "群聊2的固定欢迎语" @@ -54,7 +54,7 @@ "use_character_desc": false }, - "Apilot"{ + "Apilot": { "alapi_token": "xxx", "morning_news_text_enabled": false } From ca8e06e5621b751943eb28ba94010f69ec67d18e Mon Sep 17 00:00:00 2001 From: 6vision Date: Thu, 13 Jun 2024 16:43:03 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=AC=A6=E5=90=88openai?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=A0=BC=E5=BC=8F=E7=9A=84=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=EF=BC=8C=E6=A0=B9=E7=9B=AE=E5=BD=95=E7=9A=84?= =?UTF-8?q?config.json=E9=87=8C=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE"bot=5F?= =?UTF-8?q?type":=20"chatGPT"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bridge/bridge.py | 62 ++++++++++++++++++++++++++---------------------- config.py | 1 + 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/bridge/bridge.py b/bridge/bridge.py index 6733701..596c67c 100644 --- a/bridge/bridge.py +++ b/bridge/bridge.py @@ -19,38 +19,42 @@ class Bridge(object): "translate": conf().get("translate", "baidu"), } # 这边取配置的模型 - model_type = conf().get("model") or const.GPT35 - if model_type in ["text-davinci-003"]: - self.btype["chat"] = const.OPEN_AI - if conf().get("use_azure_chatgpt", False): - self.btype["chat"] = const.CHATGPTONAZURE - if model_type in ["wenxin", "wenxin-4"]: - self.btype["chat"] = const.BAIDU - if model_type in ["xunfei"]: - self.btype["chat"] = const.XUNFEI - if model_type in [const.QWEN]: - self.btype["chat"] = const.QWEN - if model_type in [const.QWEN_TURBO, const.QWEN_PLUS, const.QWEN_MAX]: - self.btype["chat"] = const.QWEN_DASHSCOPE - if model_type in [const.GEMINI]: - self.btype["chat"] = const.GEMINI - if model_type in [const.ZHIPU_AI]: - self.btype["chat"] = const.ZHIPU_AI - if model_type and model_type.startswith("claude-3"): - self.btype["chat"] = const.CLAUDEAPI + bot_type = conf().get("bot_type") + if bot_type: + self.btype["chat"] = bot_type + else: + model_type = conf().get("model") or const.GPT35 + if model_type in ["text-davinci-003"]: + self.btype["chat"] = const.OPEN_AI + if conf().get("use_azure_chatgpt", False): + self.btype["chat"] = const.CHATGPTONAZURE + if model_type in ["wenxin", "wenxin-4"]: + self.btype["chat"] = const.BAIDU + if model_type in ["xunfei"]: + self.btype["chat"] = const.XUNFEI + if model_type in [const.QWEN]: + self.btype["chat"] = const.QWEN + if model_type in [const.QWEN_TURBO, const.QWEN_PLUS, const.QWEN_MAX]: + self.btype["chat"] = const.QWEN_DASHSCOPE + if model_type in [const.GEMINI]: + self.btype["chat"] = const.GEMINI + if model_type in [const.ZHIPU_AI]: + self.btype["chat"] = const.ZHIPU_AI + if model_type and model_type.startswith("claude-3"): + self.btype["chat"] = const.CLAUDEAPI - if model_type in ["claude"]: - self.btype["chat"] = const.CLAUDEAI + if model_type in ["claude"]: + self.btype["chat"] = const.CLAUDEAI - if model_type in ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"]: - self.btype["chat"] = const.MOONSHOT + if model_type in ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"]: + self.btype["chat"] = const.MOONSHOT - if conf().get("use_linkai") and conf().get("linkai_api_key"): - self.btype["chat"] = const.LINKAI - if not conf().get("voice_to_text") or conf().get("voice_to_text") in ["openai"]: - self.btype["voice_to_text"] = const.LINKAI - if not conf().get("text_to_voice") or conf().get("text_to_voice") in ["openai", const.TTS_1, const.TTS_1_HD]: - self.btype["text_to_voice"] = const.LINKAI + if conf().get("use_linkai") and conf().get("linkai_api_key"): + self.btype["chat"] = const.LINKAI + if not conf().get("voice_to_text") or conf().get("voice_to_text") in ["openai"]: + self.btype["voice_to_text"] = const.LINKAI + if not conf().get("text_to_voice") or conf().get("text_to_voice") in ["openai", const.TTS_1, const.TTS_1_HD]: + self.btype["text_to_voice"] = const.LINKAI self.bots = {} self.chat_bots = {} diff --git a/config.py b/config.py index bff03bb..600091e 100644 --- a/config.py +++ b/config.py @@ -18,6 +18,7 @@ available_setting = { "proxy": "", # openai使用的代理 # chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称 "model": "gpt-3.5-turbo", # 支持ChatGPT、Claude、Gemini、文心一言、通义千问、Kimi、讯飞星火、智谱、LinkAI等模型,模型具体名称详见common/const.py文件列出的模型 + "bot_type": "", # 可选配置,使用兼容openai格式的三方服务时候,需填"chatGPT"。bot具体名称详见common/const.py文件列出的bot_type,如不填根据model名称判断, "use_azure_chatgpt": False, # 是否使用azure的chatgpt "azure_deployment_id": "", # azure 模型部署名称 "azure_api_version": "", # azure api版本 From c41ec13984be203e78af1e778c0bd9670ed6a48c Mon Sep 17 00:00:00 2001 From: 6vision Date: Sat, 15 Jun 2024 16:34:32 +0800 Subject: [PATCH 6/6] fix terminal channel --- channel/terminal/terminal_channel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/channel/terminal/terminal_channel.py b/channel/terminal/terminal_channel.py index 9a413dc..9b64eb4 100644 --- a/channel/terminal/terminal_channel.py +++ b/channel/terminal/terminal_channel.py @@ -78,6 +78,7 @@ class TerminalChannel(ChatChannel): prompt = trigger_prefixs[0] + prompt # 给没触发的消息加上触发前缀 context = self._compose_context(ContextType.TEXT, prompt, msg=TerminalMessage(msg_id, prompt)) + context["isgroup"] = False if context: self.produce(context) else: