From fa6689ec55151b949dbab4191ec0856766ec3ea9 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Sun, 19 Mar 2023 00:46:56 +0800 Subject: [PATCH 01/21] fix: acquire complete reply content --- channel/wechat/wechat_channel.py | 1 - model/baidu/yiyan_model.py | 33 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 5a215c3..f4a5585 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -13,7 +13,6 @@ from common.log import logger from common import const from config import channel_conf_val import requests -from urllib.parse import urlencode from common.sensitive_word import SensitiveWord diff --git a/model/baidu/yiyan_model.py b/model/baidu/yiyan_model.py index 6d0004a..3029523 100644 --- a/model/baidu/yiyan_model.py +++ b/model/baidu/yiyan_model.py @@ -3,10 +3,9 @@ from model.model import Model from config import model_conf from common import const -from common import log +from common.log import logger import requests import time -import json sessions = {} @@ -17,7 +16,9 @@ class YiyanModel(Model): self.base_url = 'https://yiyan.baidu.com/eb' def reply(self, query, context=None): + logger.info("[BAIDU] query={}".format(query)) user_id = context.get('session_id') or context.get('from_user_id') + context['query'] = query # 1.create session chat_session_id = sessions.get(user_id) @@ -28,8 +29,9 @@ class YiyanModel(Model): context['chat_session_id'] = chat_session_id # 2.create chat - context['query'] = query - self.new_chat(context) + flag = self.new_chat(context) + if not flag: + return "创建会话失败,请稍后再试" # 3.query context['reply'] = '' @@ -40,13 +42,14 @@ class YiyanModel(Model): def new_session(self, context): data = { - "sessionName": "test session", + "sessionName": context['query'], "timestamp": int(time.time() * 1000), "deviceType": "pc" } res = requests.post(url=self.base_url+'/session/new', headers=self._create_header(), json=data) # print(res.headers) context['chat_session_id'] = res.json()['data']['sessionId'] + logger.info("[BAIDU] newSession: id={}".format(context['chat_session_id'])) def new_chat(self, context): @@ -62,10 +65,13 @@ class YiyanModel(Model): "code": 0, "msg": "" } - res = requests.post(url=self.base_url+'/chat/new', headers=headers, json=data) - print(res.text) - context['chat_id'] = res.json()['data']['botChat']['id'] - context['parent_chat_id'] = res.json()['data']['botChat']['parent'] + res = requests.post(url=self.base_url+'/chat/new', headers=headers, json=data).json() + if res['code'] != 0: + logger.error("[BAIDU] New chat error, msg={}", res['msg']) + return False + context['chat_id'] = res['data']['botChat']['id'] + context['parent_chat_id'] = res['data']['botChat']['parent'] + return True def query(self, context, sentence_id, count): @@ -79,10 +85,13 @@ class YiyanModel(Model): "timestamp": 1679068791405, "deviceType": "pc" } - res = requests.post(url=self.base_url + '/chat/query', headers=headers, json=data).json() + res = requests.post(url=self.base_url + '/chat/query', headers=headers, json=data) + logger.debug("[BAIDU] query: sent_id={}, count={}, res={}".format(sentence_id, count, res.text)) + res = res.json() if res['data']['text'] != '': context['reply'] += res['data']['text'] + # logger.debug("[BAIDU] query: sent_id={}, reply={}".format(sentence_id, res['data']['text'])) if res['data']['is_end'] == 1: return @@ -90,9 +99,11 @@ class YiyanModel(Model): if count > 10: return + time.sleep(1) if not res['data']['text']: - time.sleep(1) return self.query(context, sentence_id, count+1) + else: + return self.query(context, sentence_id+1, count+1) def _create_header(self): From 5a6360ad50fc7f60ad68c0fd7fd1584562969ab2 Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 19 Mar 2023 05:59:33 +0800 Subject: [PATCH 02/21] =?UTF-8?q?New=20Bing=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 41 +++++++++++++++++++++++++ channel/http/static/1.js | 2 +- common/const.py | 3 +- config-template.json | 4 ++- model/bing/new_bing_model.py | 58 ++++++++++++++++++++++++++++++++++++ model/model_factory.py | 4 +++ 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 model/bing/new_bing_model.py diff --git a/README.md b/README.md index 5190b77..8a335f6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [x] [ChatGPT (gpt-3.5)](https://github.com/zhayujie/bot-on-anything#1-chatgpt) - [x] [GPT-3.0](https://github.com/zhayujie/bot-on-anything#2gpt-30) - [x] 文心一言 (测试版) + - [x] [New Bing](https://github.com/zhayujie/bot-on-anything#4newbing) **应用:** @@ -140,6 +141,46 @@ pip3 install --upgrade openai 参考: [#154](https://github.com/zhayujie/bot-on-anything/issues/154) + +### 4.NewBing + +使用的是https://github.com/acheong08/EdgeGPT 网页版逆向API + +#### (1) 安装依赖 + +```bash +pip install EdgeGPT --upgrade +``` + +#### (2) 配置项说明 + +```bash +{ + "model": { + "type" : "bing", + + "bing": { + "cookies":[] //edge登录https://www.bing.com/new 获取的json格式name为"_U"的cookies,目前看cookies有效期应该为14天 + } +} +cookie示例: +"cookies":[ + { + "domain": ".bing.com", + "expirationDate": 1680372573.67057, + "hostOnly": false, + "httpOnly": false, + "name": "_U", + "path": "/", + "sameSite": "no_restriction", + "secure": true, + "session": false, + "storeId": null, + "value": "" + } + ] +``` + ## 三、选择应用 ### 1.命令行终端 diff --git a/channel/http/static/1.js b/channel/http/static/1.js index e0da635..8d9fbce 100644 --- a/channel/http/static/1.js +++ b/channel/http/static/1.js @@ -41,7 +41,7 @@ ConvState.prototype.sendMessage = function (msg) { $.ajax({ url: "./chat", type: "POST", - timeout:60000, + timeout:120000, data: JSON.stringify({ "id": _this.id, "msg": msg diff --git a/common/const.py b/common/const.py index 5c10599..ad2a061 100644 --- a/common/const.py +++ b/common/const.py @@ -12,4 +12,5 @@ HTTP = "http" # model OPEN_AI = "openai" CHATGPT = "chatgpt" -BAIDU = "baidu" \ No newline at end of file +BAIDU = "baidu" +BING = "bing" \ No newline at end of file diff --git a/config-template.json b/config-template.json index 3202a99..f1088e2 100644 --- a/config-template.json +++ b/config-template.json @@ -11,7 +11,9 @@ "baidu": { "acs_token": "YOUR ACS TOKEN", "cookie": "YOUR COOKIE" - } + }, + "bing":{ + "cookies":[] }, "channel": { diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py new file mode 100644 index 0000000..947a507 --- /dev/null +++ b/model/bing/new_bing_model.py @@ -0,0 +1,58 @@ +# encoding:utf-8 +import asyncio +from model.model import Model +from config import model_conf_val +from common import log +from EdgeGPT import Chatbot, ConversationStyle + +user_session = dict() +# newBing对话模型逆向网页API + +class BingModel(Model): + + style = ConversationStyle.creative + bot: Chatbot = None + + def __init__(self): + self.bot = Chatbot(cookies=model_conf_val("bing", "cookies")) + + def reply(self, query: str, context=None) -> tuple[str, dict]: + bot = user_session.get(context['from_user_id'], None) + if (bot == None): + bot = self.bot + log.info("[NewBing] query={}".format(query)) + task = bot.ask(query, conversation_style=self.style) + answer = asyncio.run(task) + + # 最新一条回复 + reply = answer["item"]["messages"][-1] + reply_text = reply["text"] + reference = "" + if "sourceAttributions" in reply: + for i, attribution in enumerate(reply["sourceAttributions"]): + display_name = attribution["providerDisplayName"] + url = attribution["seeMoreUrl"] + reference += f"{i+1}、[{display_name}]({url})\n\n" + + if len(reference) > 0: + reference = "***\n"+reference + throttling = answer["item"]["throttling"] + throttling_str = "" + + if throttling["numUserMessagesInConversation"] == throttling["maxNumUserMessagesInConversation"]: + self.reset_chat(context['from_user_id']) + throttling_str = "(对话轮次已达上限,本次聊天已结束,将开启新的对话)" + else: + throttling_str = f"对话轮次: {throttling['numUserMessagesInConversation']}/{throttling['maxNumUserMessagesInConversation']}\n" + + response = f"{reply_text}\n{reference}\n***\n{throttling_str}" + log.info("[NewBing] reply={}", response) + user_session[context['from_user_id']] = bot + return response + else: + self.reset_chat(context['from_user_id']) + log.warn("[NewBing] reply={}", answer) + return "对话被接口拒绝,已开启新的一轮对话。" + + def reset_chat(self, from_user_id): + asyncio.run(user_session.get(from_user_id, None).reset()) diff --git a/model/model_factory.py b/model/model_factory.py index 23d0320..5c5f2ad 100644 --- a/model/model_factory.py +++ b/model/model_factory.py @@ -25,5 +25,9 @@ def create_bot(model_type): from model.baidu.yiyan_model import YiyanModel return YiyanModel() + elif model_type == const.BING: + from model.bing.new_bing_model import BingModel + return BingModel() + raise RuntimeError From a848e94fc04d7df28564af843c0d5fcc0d9f1f3c Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 19 Mar 2023 06:08:54 +0800 Subject: [PATCH 03/21] catch Unauthorized --- model/bing/new_bing_model.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index 947a507..35101b2 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -6,7 +6,7 @@ from common import log from EdgeGPT import Chatbot, ConversationStyle user_session = dict() -# newBing对话模型逆向网页API +# newBing对话模型逆向网页gitAPI class BingModel(Model): @@ -14,7 +14,10 @@ class BingModel(Model): bot: Chatbot = None def __init__(self): - self.bot = Chatbot(cookies=model_conf_val("bing", "cookies")) + try: + self.bot = Chatbot(cookies=model_conf_val("bing", "cookies")) + except Exception as e: + log.exception(e) def reply(self, query: str, context=None) -> tuple[str, dict]: bot = user_session.get(context['from_user_id'], None) From 04f1399b036a1535c82e70d6ea7c7e56fbe147c3 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Sun, 19 Mar 2023 10:50:45 +0800 Subject: [PATCH 04/21] docs: update doc for new bing --- README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8a335f6..79650fd 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ pip3 install --upgrade openai #### (1) 安装依赖 ```bash -pip install EdgeGPT --upgrade +pip3 install EdgeGPT --upgrade ``` #### (2) 配置项说明 @@ -158,27 +158,26 @@ pip install EdgeGPT --upgrade { "model": { "type" : "bing", - "bing": { "cookies":[] //edge登录https://www.bing.com/new 获取的json格式name为"_U"的cookies,目前看cookies有效期应该为14天 } } cookie示例: "cookies":[ - { - "domain": ".bing.com", - "expirationDate": 1680372573.67057, - "hostOnly": false, - "httpOnly": false, - "name": "_U", - "path": "/", - "sameSite": "no_restriction", - "secure": true, - "session": false, - "storeId": null, - "value": "" - } - ] + { + "domain": ".bing.com", + "expirationDate": 1680372573.67057, + "hostOnly": false, + "httpOnly": false, + "name": "_U", + "path": "/", + "sameSite": "no_restriction", + "secure": true, + "session": false, + "storeId": null, + "value": "" + } +] ``` ## 三、选择应用 From c948d2bff96fdb3e91382e865960d073732e712a Mon Sep 17 00:00:00 2001 From: Selier <42491291+selierlin@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:01:01 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B715=E7=A7=92?= =?UTF-8?q?=E5=86=85=E7=9B=B4=E6=8E=A5=E5=9B=9E=E5=A4=8D=EF=BC=8C=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E9=80=9A=E8=BF=87=E7=BB=A7=E7=BB=AD=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/wechat/wechat_mp_channel.py | 59 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/channel/wechat/wechat_mp_channel.py b/channel/wechat/wechat_mp_channel.py index 7279311..4c41ee9 100644 --- a/channel/wechat/wechat_mp_channel.py +++ b/channel/wechat/wechat_mp_channel.py @@ -46,36 +46,49 @@ class WechatSubsribeAccount(Channel): robot.config['HOST'] = '0.0.0.0' robot.run() - def handle(self, msg, count=0): + def handle(self, msg, count=1): + if msg.content == "继续": + return self.get_un_send_content(msg.source) + context = dict() context['from_user_id'] = msg.source - key = msg.source + key = msg.content + '|' + msg.source res = cache.get(key) - if msg.content == "继续": - if not res or res.get("status") == "done": - return "目前不在等待回复状态,请输入对话" - if res.get("status") == "waiting": - return "还在处理中,请稍后再试" - elif res.get("status") == "success": - cache[key] = {"status":"done"} - return res.get("data") - else: - return "目前不在等待回复状态,请输入对话" - elif not res or res.get('status') == "done": + if not res: + cache[key] = {"status": "waiting", "req_times": 1} thread_pool.submit(self._do_send, msg.content, context) + + res = cache.get(key) + logger.info("count={}, res={}".format(count, res)) + if res.get('status') == 'success': + res['status'] = "done" + cache.pop(key) + return res.get("data") + + if cache.get(key)['req_times'] == 3 and count >= 4: + logger.info("微信超时3次") return "已开始处理,请稍等片刻后输入\"继续\"查看回复" - else: - if res.get('status') == "done": - reply = res.get("data") - thread_pool.submit(self._do_send, msg.content, context) - return reply - else: - return "上一句对话正在处理中,请稍后输入\"继续\"查看回复" + + if count <= 5: + time.sleep(1) + if count == 5: + # 第5秒不做返回,防止消息发送出去了但是微信已经中断连接 + return None + return self.handle(msg, count+1) def _do_send(self, query, context): - key = context['from_user_id'] - cache[key] = {"status": "waiting"} + key = query + '|' + context['from_user_id'] reply_text = super().build_reply_content(query, context) logger.info('[WX_Public] reply content: {}'.format(reply_text)) + cache[key]['status'] = "success" + cache[key]['data'] = reply_text - cache[key] = {"status": "success", "data": reply_text} + def get_un_send_content(self, from_user_id): + for key in cache: + if from_user_id in key: + value = cache[key] + if value.get('status') == "success": + cache.pop(key) + return value.get("data") + return "还在处理中,请稍后再试" + return "目前无等待回复信息,请输入对话" From be33d212ea94195c7830e33b98a3e7c664306a71 Mon Sep 17 00:00:00 2001 From: RA Date: Sun, 19 Mar 2023 17:17:49 +0800 Subject: [PATCH 06/21] [new bing]adds quick-reply suggested questions. --- channel/http/static/1.js | 2 +- model/bing/new_bing_model.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/channel/http/static/1.js b/channel/http/static/1.js index 8d9fbce..4a34289 100644 --- a/channel/http/static/1.js +++ b/channel/http/static/1.js @@ -41,7 +41,7 @@ ConvState.prototype.sendMessage = function (msg) { $.ajax({ url: "./chat", type: "POST", - timeout:120000, + timeout:180000, data: JSON.stringify({ "id": _this.id, "msg": msg diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index 35101b2..975a8d9 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -6,8 +6,10 @@ from common import log from EdgeGPT import Chatbot, ConversationStyle user_session = dict() +suggestion_session = dict() # newBing对话模型逆向网页gitAPI + class BingModel(Model): style = ConversationStyle.creative @@ -23,6 +25,15 @@ class BingModel(Model): bot = user_session.get(context['from_user_id'], None) if (bot == None): bot = self.bot + else: + if (len(query) == 1 and query.isdigit() and query != "0"): + suggestion_dict = suggestion_session[context['from_user_id']] + if (suggestion_dict != None): + query = suggestion_dict[int(query)-1] + if (query == None): + return "输入的序号不在建议列表范围中" + else: + query = "在上面的基础上,"+query log.info("[NewBing] query={}".format(query)) task = bot.ask(query, conversation_style=self.style) answer = asyncio.run(task) @@ -39,6 +50,18 @@ class BingModel(Model): if len(reference) > 0: reference = "***\n"+reference + + suggestion = "" + if "suggestedResponses" in reply: + suggestion_dict = dict() + for i, attribution in enumerate(reply["suggestedResponses"]): + suggestion_dict[i] = attribution["text"] + suggestion += f">{i+1}、{attribution['text']}\n\n" + suggestion_session[context['from_user_id']] = suggestion_dict + + if len(suggestion) > 0: + suggestion = "***\n你可以通过输入序号快速追问我以下建议问题:\n\n"+suggestion + throttling = answer["item"]["throttling"] throttling_str = "" @@ -48,7 +71,7 @@ class BingModel(Model): else: throttling_str = f"对话轮次: {throttling['numUserMessagesInConversation']}/{throttling['maxNumUserMessagesInConversation']}\n" - response = f"{reply_text}\n{reference}\n***\n{throttling_str}" + response = f"{reply_text}\n{reference}\n{suggestion}\n***\n{throttling_str}" log.info("[NewBing] reply={}", response) user_session[context['from_user_id']] = bot return response From 1aa002b8f206f215dd6635ff1e58cf0e4f0f089c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sat, 18 Mar 2023 13:00:10 +0800 Subject: [PATCH 07/21] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B0=86=E7=99=BB=E5=BD=95=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=87=BA=E6=9D=A5=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/wechat/wechat_channel.py | 9 ++++++++- config-template.json | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index f4a5585..8a9fdba 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -40,11 +40,18 @@ class WechatChannel(Channel): def startup(self): # login by scan QRCode - itchat.auto_login(enableCmdQR=2, hotReload=True) + if (channel_conf_val(const.WECHAT, 'receive_qrcode_api')): + itchat.auto_login(enableCmdQR=2, hotReload=False, qrCallback=self.login) + else: + itchat.auto_login(enableCmdQR=2, hotReload=False) # start message listener itchat.run() + def login(self, uuid=None, status='0', qrcode=None): + print('uuid:', uuid) + print('status:', status) + print('qrcode_link:', 'https://login.weixin.qq.com/l/'+uuid) def handle(self, msg): logger.debug("[WX]receive msg: " + json.dumps(msg, ensure_ascii=False)) diff --git a/config-template.json b/config-template.json index f1088e2..f678c57 100644 --- a/config-template.json +++ b/config-template.json @@ -28,6 +28,7 @@ }, "wechat": { + "receive_qrcode_api": "" }, "wechat_mp": { From dd7d3c32684ca14b0ebaf80b2ffdffad7a6dd126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 11:45:31 +0800 Subject: [PATCH 08/21] fix itchat bug --- fix-itchat.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 fix-itchat.sh diff --git a/fix-itchat.sh b/fix-itchat.sh new file mode 100755 index 0000000..0fd097b --- /dev/null +++ b/fix-itchat.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -x + +cmd=sed +if [ "$(uname)" == "Darwin" ];then + brew install gnu-sed + cmd=gsed +fi + +echo "current sed command is: $cmd" + +pack_dir="$(pip3 show itchat-uos | grep "Location" | awk '{print $2}')" +file_name="${pack_dir}/itchat/components/login.py" + +sleep15Code="time.sleep(15)" + +cat $file_name | grep $sleep15Code + +if [ "$?" != "0" ];then + echo "fix $sleep15Code" + $cmd -i "/while not isLoggedIn/i\ $sleep15Code" $file_name +else + echo "already fix $sleep15Code" +fi + +sleep3Code="time.sleep(3)" + +cat $file_name | grep $sleep3Code + +if [ "$?" != "0" ];then + echo "fix $sleep3Code" + $cmd -i "s/elif status != '408'/elif status in ['408', '400']/" $file_name + $cmd -i "/if isLoggedIn:/i\ time.sleep(3)" $file_name +else + echo "already fix $sleep3Code" +fi From 107604d7a1ad450fd18819d421d7bde4aab18edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 11:48:02 +0800 Subject: [PATCH 09/21] fix itchat bug --- fix-itchat.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fix-itchat.sh b/fix-itchat.sh index 0fd097b..3d02fe0 100755 --- a/fix-itchat.sh +++ b/fix-itchat.sh @@ -2,6 +2,8 @@ set -x +# @see https://stackoverflow.com/questions/30003570/how-to-use-gnu-sed-on-mac-os-10-10-brew-install-default-names-no-longer-su +# @see https://www.cnblogs.com/fnlingnzb-learner/p/10657285.html cmd=sed if [ "$(uname)" == "Darwin" ];then brew install gnu-sed From 36e05629d6a759afb7a758790e981297f76ff638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:02:39 +0800 Subject: [PATCH 10/21] fix itchat bug --- channel/wechat/wechat_channel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 8a9fdba..63a1454 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -41,9 +41,9 @@ class WechatChannel(Channel): def startup(self): # login by scan QRCode if (channel_conf_val(const.WECHAT, 'receive_qrcode_api')): - itchat.auto_login(enableCmdQR=2, hotReload=False, qrCallback=self.login) + itchat.auto_login(enableCmdQR=2, hotReload=True, qrCallback=self.login) else: - itchat.auto_login(enableCmdQR=2, hotReload=False) + itchat.auto_login(enableCmdQR=2, hotReload=True) # start message listener itchat.run() From 6fccf028f857ee4961f00e2b378c6dd86cfb36bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:04:36 +0800 Subject: [PATCH 11/21] fix itchat bug --- channel/wechat/wechat_channel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 63a1454..ac5cc2f 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -51,6 +51,7 @@ class WechatChannel(Channel): def login(self, uuid=None, status='0', qrcode=None): print('uuid:', uuid) print('status:', status) + # 请将链接转发到外部接口,并在外部自行通过二维码生成库将链接转换为二维码后展示,例如:将下方的 qrcode_link 通过草料二维码进行处理后,再通过手机端扫码登录微信小号 print('qrcode_link:', 'https://login.weixin.qq.com/l/'+uuid) def handle(self, msg): From 5989a45d89b304b0662f14f48e0add88b715386f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:06:13 +0800 Subject: [PATCH 12/21] fix itchat bug --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 79650fd..d4c91ca 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,11 @@ pip3 install --upgrade openai ``` 注:`itchat-uos`使用指定版本1.5.0.dev0,`openai`使用最新版本,需高于0.27.0。 +**修复 itchat-uos bug** +··· +bash fix-itchat.sh +··· + **配置项说明:** From 56f3f0ddceab10bf9dc70b0da810973c849e5a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:30:22 +0800 Subject: [PATCH 13/21] fix error channel_type tips --- channel/channel_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channel/channel_factory.py b/channel/channel_factory.py index 186d445..7b53e80 100644 --- a/channel/channel_factory.py +++ b/channel/channel_factory.py @@ -46,4 +46,4 @@ def create_channel(channel_type): return HttpChannel() else: - raise RuntimeError + raise RuntimeError("unknown channel_type in config.json: " + channel_type) From 085b3b96ad352b517da1944cdf711d8c6eea6513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:38:29 +0800 Subject: [PATCH 14/21] feat: allow http channel not set password to use chatgpt --- channel/http/auth.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/channel/http/auth.py b/channel/http/auth.py index 67b2ec4..3e2756a 100644 --- a/channel/http/auth.py +++ b/channel/http/auth.py @@ -83,6 +83,9 @@ def identify(request): :return: list """ try: + authPassword = channel_conf(const.HTTP).get('http_auth_password') + if (not authPassword): + return True if (request is None): return False authorization = request.cookies.get('Authorization') From 9b35082bc114e6fc21116f13a566e961498fc85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9F=E5=8B=87?= Date: Sun, 19 Mar 2023 21:49:41 +0800 Subject: [PATCH 15/21] fix: contfig-template.json format error --- config-template.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config-template.json b/config-template.json index f678c57..63275f6 100644 --- a/config-template.json +++ b/config-template.json @@ -13,7 +13,8 @@ "cookie": "YOUR COOKIE" }, "bing":{ - "cookies":[] + "cookies":[] + } }, "channel": { From 068f7e4c6565df48a0e87f59c8007a6b6c01f312 Mon Sep 17 00:00:00 2001 From: mouyong Date: Sun, 19 Mar 2023 22:08:16 +0800 Subject: [PATCH 16/21] feat: allow http nopassword --- README.md | 5 +++++ allow-http-nopassword.sh | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 allow-http-nopassword.sh diff --git a/README.md b/README.md index d4c91ca..6d3c026 100644 --- a/README.md +++ b/README.md @@ -480,3 +480,8 @@ pip3 install PyJWT flask 本地运行:`python3 app.py`运行后访问 `http://127.0.0.1:80` 服务器运行:部署后访问 `http://公网域名或IP:端口` + +**允许无密码访问** +``` +bash ./allow-http-nopassword.sh +``` diff --git a/allow-http-nopassword.sh b/allow-http-nopassword.sh new file mode 100644 index 0000000..b0066c4 --- /dev/null +++ b/allow-http-nopassword.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -x + +# @see https://stackoverflow.com/questions/30003570/how-to-use-gnu-sed-on-mac-os-10-10-brew-install-default-names-no-longer-su +# @see https://www.cnblogs.com/fnlingnzb-learner/p/10657285.html +cmd=sed +if [ "$(uname)" == "Darwin" ];then + brew install gnu-sed + cmd=gsed +fi + +echo "current sed command is: $cmd" + +echo "allow http nopasword" +$cmd -i 's/"http_auth_password": "6.67428e-11"/"http_auth_password": ""/' config.json From 0d7b5a5d4006155c77bff91076fd69e8526abac4 Mon Sep 17 00:00:00 2001 From: mouyong Date: Sun, 19 Mar 2023 23:11:14 +0800 Subject: [PATCH 17/21] fix: proxy fail on windows 11 --- app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.py b/app.py index d555e05..e470a45 100644 --- a/app.py +++ b/app.py @@ -3,12 +3,19 @@ import config from channel import channel_factory from common import log +import os if __name__ == '__main__': try: # load config config.load_config() + proxy = config.conf().get("model").get("openai").get("proxy") + if proxy: + os.environ['http_proxy'] = proxy + os.environ['https_proxy'] = proxy + print(os.environ) + model_type = config.conf().get("model").get("type") channel_type = config.conf().get("channel").get("type") From dc9be5222b7cf31e2ae0f4a00d3f6277ef5e1641 Mon Sep 17 00:00:00 2001 From: mouyong Date: Sun, 19 Mar 2023 23:11:40 +0800 Subject: [PATCH 18/21] fix: proxy fail on windows 11 --- app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app.py b/app.py index e470a45..6a047a6 100644 --- a/app.py +++ b/app.py @@ -14,7 +14,6 @@ if __name__ == '__main__': if proxy: os.environ['http_proxy'] = proxy os.environ['https_proxy'] = proxy - print(os.environ) model_type = config.conf().get("model").get("type") channel_type = config.conf().get("channel").get("type") From b966e1a5a9821cd453a1efc8893d7cb30f1b26e3 Mon Sep 17 00:00:00 2001 From: mouyong Date: Sun, 19 Mar 2023 23:18:15 +0800 Subject: [PATCH 19/21] feat: allow empty http password --- allow-http-nopassword.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/allow-http-nopassword.sh b/allow-http-nopassword.sh index b0066c4..7dcee0a 100644 --- a/allow-http-nopassword.sh +++ b/allow-http-nopassword.sh @@ -13,4 +13,4 @@ fi echo "current sed command is: $cmd" echo "allow http nopasword" -$cmd -i 's/"http_auth_password": "6.67428e-11"/"http_auth_password": ""/' config.json +$cmd -i "s/\"http_auth_password\": \".*\"/\"http_auth_password\": \"\"/" config.json From 2ebb03b08ac838cd9ebd83890260a2baad9e24ca Mon Sep 17 00:00:00 2001 From: Chi Zhao Date: Sun, 19 Mar 2023 18:46:33 +0300 Subject: [PATCH 20/21] fix: config-template.json --- config-template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-template.json b/config-template.json index f1088e2..4362dcc 100644 --- a/config-template.json +++ b/config-template.json @@ -14,8 +14,8 @@ }, "bing":{ "cookies":[] + } }, - "channel": { "type": "terminal", "single_chat_prefix": ["bot", "@bot"], From 2caa18129b5d0176a66d0b8c0be0e83f75173a9c Mon Sep 17 00:00:00 2001 From: zhayujie Date: Mon, 20 Mar 2023 00:53:03 +0800 Subject: [PATCH 21/21] Update config-template.json --- config-template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-template.json b/config-template.json index 4362dcc..dba7214 100644 --- a/config-template.json +++ b/config-template.json @@ -14,7 +14,7 @@ }, "bing":{ "cookies":[] - } + } }, "channel": { "type": "terminal",