From f2e3d69d8ae7c1a7d74fb419b0aae058459a70b6 Mon Sep 17 00:00:00 2001 From: vision Date: Thu, 11 May 2023 15:49:55 +0800 Subject: [PATCH 1/4] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新闻类工具整合后,工具名称变更了,调整一下位置,更能引起注意 --- plugins/tool/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/tool/README.md b/plugins/tool/README.md index 8bd6949ae..feff6400d 100644 --- a/plugins/tool/README.md +++ b/plugins/tool/README.md @@ -57,6 +57,8 @@ $tool reset: 重置工具。 ### 6. news 新闻类工具集合 +> news更新:0.4版本对新闻类工具做了整合,配置文件只要加入`news`一个工具名就会自动加载所有新闻类工具 + #### 6.1. news-api * ###### 从全球 80,000 多个信息源中获取当前和历史新闻文章 @@ -75,7 +77,7 @@ $tool reset: 重置工具。 > 该工具需要解决browser tool 的google-chrome依赖安装 -> news更新:0.4版本对news工具做了整合,只要加入news一个工具就会自动加载所有新闻类工具 + ### 7. bing-search * ###### bing搜索引擎,从此你不用再烦恼搜索要用哪些关键词 @@ -129,7 +131,7 @@ $tool reset: 重置工具。 ``` 注:config.json文件非必须,未创建仍可使用本tool;带*工具需在kwargs填入对应api-key键值对 -- `tools`:本插件初始化时加载的工具, 上述标题即是对应工具名称,带*工具必须在kwargs中配置相应api-key +- `tools`:本插件初始化时加载的工具, 上述一级标题即是对应工具名称,带*工具必须在kwargs中配置相应api-key - `kwargs`:工具执行时的配置,一般在这里存放**api-key**,或环境配置 - `debug`: 输出chatgpt-tool-hub额外信息用于调试 - `request_timeout`: 访问openai接口的超时时间,默认与wechat-on-chatgpt配置一致,可单独配置 From 3e92d076184933ff48368b38e4a8bf10e3c6f432 Mon Sep 17 00:00:00 2001 From: taoguoliang <852765192@qq.com> Date: Sun, 7 May 2023 15:22:24 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(=E5=91=BD=E4=BB=A4):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0set=5Fgpt=5Fmodel=E3=80=81set=5Fgpt=5Fmodel=E3=80=81se?= =?UTF-8?q?t=5Fgpt=5Fmodel=20=E5=87=A0=E4=B8=AA=E5=91=BD=E4=BB=A4=E7=9A=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/chatgpt/chat_gpt_bot.py | 2 +- channel/chat_channel.py | 1 + plugins/godcmd/godcmd.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index b46751abf..c5bef2a78 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -66,7 +66,7 @@ def reply(self, query, context=None): logger.debug("[CHATGPT] session query={}".format(session.messages)) api_key = context.get("openai_api_key") - + self.args['model'] = context.get('gpt_model') or "gpt-3.5-turbo" # if context.get('stream'): # # reply in stream # return self.reply_text_stream(query, new_query, session_id) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index a9b90f2aa..795787b2b 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -50,6 +50,7 @@ def _compose_context(self, ctype: ContextType, content, **kwargs): cmsg = context["msg"] user_data = conf().get_user_data(cmsg.from_user_id) context["openai_api_key"] = user_data.get("openai_api_key") + context["gpt_model"] = user_data.get("gpt_model") if context.get("isgroup", False): group_name = cmsg.other_user_nickname group_id = cmsg.other_user_id diff --git a/plugins/godcmd/godcmd.py b/plugins/godcmd/godcmd.py index ecfb0c026..eee579a2a 100644 --- a/plugins/godcmd/godcmd.py +++ b/plugins/godcmd/godcmd.py @@ -41,6 +41,18 @@ "alias": ["reset_openai_api_key"], "desc": "重置为默认的api_key", }, + "set_gpt_model": { + "alias": ["set_gpt_model"], + "desc": "设置你的私有模型", + }, + "reset_gpt_model": { + "alias": ["reset_gpt_model"], + "desc": "重置你的私有模型", + }, + "gpt_model": { + "alias": ["gpt_model"], + "desc": "查询你使用的模型", + }, "id": { "alias": ["id", "用户"], "desc": "获取用户id", # wechaty和wechatmp的用户id不会变化,可用于绑定管理员 @@ -264,6 +276,26 @@ def on_handle_context(self, e_context: EventContext): ok, result = True, "你的OpenAI私有api_key已清除" except Exception as e: ok, result = False, "你没有设置私有api_key" + elif cmd == "set_gpt_model": + if len(args) == 1: + user_data = conf().get_user_data(user) + user_data["gpt_model"] = args[0] + ok, result = True, "你的GPT模型已设置为" + args[0] + else: + ok, result = False, "请提供一个GPT模型" + elif cmd == "gpt_model": + user_data = conf().get_user_data(user) + model = conf().get('model') + if 'gpt_model' in user_data: + model = user_data['gpt_model'] + ok, result = True, "你的GPT模型为" + str(model) + elif cmd == "reset_gpt_model": + try: + user_data = conf().get_user_data(user) + user_data.pop("gpt_model") + ok, result = True, "你的GPT模型已重置" + except Exception as e: + ok, result = False, "你没有设置私有GPT模型" elif cmd == "reset": if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]: bot.sessions.clear_session(session_id) From 0e8195ae6111b61e7a7b0d0decde3a8595ca399c Mon Sep 17 00:00:00 2001 From: lichengzhe <38408577@qq.com> Date: Mon, 15 May 2023 13:55:14 +0800 Subject: [PATCH 3/4] Bad Gateway exception retry --- bot/chatgpt/chat_gpt_bot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index b46751abf..d48bf3815 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -134,12 +134,17 @@ def reply_text(self, session: ChatGPTSession, api_key=None, retry_count=0) -> di result["content"] = "我没有收到你的消息" if need_retry: time.sleep(5) + elif isinstance(e, openai.error.APIError:): + logger.warn("[CHATGPT] Bad Gateway: {}".format(e)) + result["content"] = "请再问我一次" + if need_retry: + time.sleep(10) elif isinstance(e, openai.error.APIConnectionError): logger.warn("[CHATGPT] APIConnectionError: {}".format(e)) need_retry = False result["content"] = "我连接不到你的网络" else: - logger.warn("[CHATGPT] Exception: {}".format(e)) + logger.exception("[CHATGPT] Exception: {}".format(e)) need_retry = False self.sessions.clear_session(session.session_id) From 2d7dd71a3dc6ec2cbdbf828e6138ab380d790866 Mon Sep 17 00:00:00 2001 From: lichengzhe <38408577@qq.com> Date: Mon, 15 May 2023 14:04:55 +0800 Subject: [PATCH 4/4] Bad Gateway exception retry --- bot/chatgpt/chat_gpt_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index d48bf3815..6391b0b59 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -134,7 +134,7 @@ def reply_text(self, session: ChatGPTSession, api_key=None, retry_count=0) -> di result["content"] = "我没有收到你的消息" if need_retry: time.sleep(5) - elif isinstance(e, openai.error.APIError:): + elif isinstance(e, openai.error.APIError): logger.warn("[CHATGPT] Bad Gateway: {}".format(e)) result["content"] = "请再问我一次" if need_retry: