diff --git a/bingchat/README.md b/bingchat/README.md index e4fcab0..d8a2c95 100644 --- a/bingchat/README.md +++ b/bingchat/README.md @@ -1,3 +1,5 @@ -# New Bing Bot +# New Bing 微信小程序 + +接口来自[new-bing](../new-bing)项目 diff --git a/bingchat/pages/index/index.js b/bingchat/pages/index/index.js index 2716d15..31de5fe 100644 --- a/bingchat/pages/index/index.js +++ b/bingchat/pages/index/index.js @@ -319,7 +319,7 @@ Page({ var robContent = '' var num_in_conversation = -1 if (!data['final']) { - robContent = data['data'] + robContent = data['data'] + ' ...' } else { robContent = that.processData(data['data'], suggests, that.data.lastContent) num_in_conversation = data['data']['data']['num_in_conversation'] diff --git a/new-bing/README.md b/new-bing/README.md index d60cd7e..6027b20 100644 --- a/new-bing/README.md +++ b/new-bing/README.md @@ -1,14 +1,23 @@ -[登录 bing 账号](https://login.live.com/), 使用[Cookie-Editor 扩展](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm)将 cookie 以 json 格式导出,保存为`cookie.json`文件,同时将`COOKIE_FILE`环境变量的值指向该文件。 +## New Bing 接口 + +包括http和websocket两种协议的接口,可根据实际情况选用 ## 部署 +[登录 bing 账号](https://login.live.com/), 使用[Cookie-Editor 扩展](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm)将 cookie 以 json 格式导出,保存为`cookie.json`文件,同时将`COOKIE_FILE`环境变量的值指向该文件。 + ``` -1.新建cookies目录,将cookie.json放入该目录,支持3个cookie,可分别命名为cookie.json,cookie1.json,cookie2.json -2.cp env.example env # 根据实际情况修改 -3.bash start.sh 0.0.1 -4.curl -X POST 'http://127.0.0.1:8000/chat' -H 'content-type: application/json' --data '{"q":"你是谁?","t":1,"sid":"1"}' 验证是否成功 +1.git clone https://github.com/bujnlc8/gptbing +2.cd gptbing/new-bing +3.mkdir cookies && mv cookie.json cookies # 支持3个cookie,可分别命名为cookie.json,cookie1.json,cookie2.json +4.cp env.example env # 根据实际情况修改 +5.bash start.sh 0.0.3 +6.curl -X POST 'http://127.0.0.1:8000/chat' -H 'content-type: application/json' --data '{"q":"你是谁?","t":1,"sid":"1"}' # 验证是否成功 ``` -**⚠️ 目前中国大陆的IP会返回404,自备代理** 见[https://github.com/acheong08/EdgeGPT/issues/178](https://github.com/acheong08/EdgeGPT/issues/178) +## 说明 `EdgeGPT.py`文件 fork 至[https://github.com/acheong08/EdgeGPT](https://github.com/acheong08/EdgeGPT),并做了些许修改,在此表示感谢! + + +**⚠️ 目前中国大陆的IP会返回404,自备代理** 见[https://github.com/acheong08/EdgeGPT/issues/178](https://github.com/acheong08/EdgeGPT/issues/178) diff --git a/new-bing/app.py b/new-bing/app.py index 016eb8b..74b2f05 100644 --- a/new-bing/app.py +++ b/new-bing/app.py @@ -49,14 +49,27 @@ def reset_cookie(): LOCK.release() +def make_response_data(status, text, suggests, message, num_in_conversation=-1): + return { + 'data': { + 'status': status, + 'text': text, + 'suggests': suggests, + 'message': message, + 'num_in_conversation': num_in_conversation, + }, + 'cookie': os.environ.get('COOKIE_FILE'), + } + + @app.websocket('/chat') -async def ws_chat(request, ws): +async def ws_chat(_, ws): while True: - data = raw_json.loads(await ws.recv()) - logger.warn('Receive data: %s', data) - sid = data['sid'] - q = data['q'] try: + data = raw_json.loads(await ws.recv()) + logger.warn('Receive data: %s', data) + sid = data['sid'] + q = data['q'] async for response in get_bot(sid).ask_stream(q, conversation_style=ConversationStyle.creative): final, res = response if final: @@ -76,21 +89,10 @@ async def ws_chat(request, ws): })) except Exception as e: logger.error(e) - await ws.send( - raw_json.dumps({ - 'final': True, - 'data': { - 'data': { - 'status': 'Error', - 'text': str(e), - 'suggests': [q], - 'message': str(e), - 'num_in_conversation': -1, - }, - 'cookie': os.environ.get('COOKIE_FILE'), - } - }) - ) + await ws.send(raw_json.dumps({ + 'final': True, + 'data': make_response_data('Error', str(e), [], str(e)) + })) def get_bot(sid): @@ -141,17 +143,10 @@ async def process_data(res, q, sid, auto_reset=None): msg = res['item']['result']['message'] if 'message' in res['item']['result'] else '' if auto_reset and ('New topic' in text or 'has expired' in msg): await get_bot(sid).reset() - return { - 'data': { - 'status': status, - 'text': text, - 'suggests': suggests, - 'message': msg, - 'num_in_conversation': res['item']['throttling']['numUserMessagesInConversation'] - if 'throttling' in res['item'] else -1, - }, - 'cookie': os.environ.get('COOKIE_FILE'), - } + return make_response_data( + status, text, suggests, msg, + res['item']['throttling']['numUserMessagesInConversation'] if 'throttling' in res['item'] else -1 + ) @app.post('/chat') diff --git a/wechatbot/README.md b/wechatbot/README.md index ace9f51..6268232 100644 --- a/wechatbot/README.md +++ b/wechatbot/README.md @@ -1,15 +1,16 @@ -# wechatbot -最近ChatGPT异常火爆,想到将其接入到个人微信是件比较有趣的事,所以有了这个项目。项目基于[openwechat](https://github.com/eatmoreapple/openwechat)开发,支持ChatGPT和New Bing[依赖于new-bing项目](../new-bing) +## 微信机器人 -### 目前实现了以下功能 +最近ChatGPT异常火爆,想到将其接入到个人微信是件比较有趣的事,所以有了这个项目。项目基于[openwechat](https://github.com/eatmoreapple/openwechat)开发,支持ChatGPT和New Bing,其中New Bing[依赖于new-bing项目](../new-bing)提供的http接口。 + +## 目前实现了以下功能 + 群聊@回复 + 私聊回复 + 自动通过回复 -# 注册openai +## 注册openai ChatGPT注册可以参考[这里](https://juejin.cn/post/7173447848292253704) -# 安装使用 +## 部署 ``` # 获取项目 @@ -18,14 +19,21 @@ git clone https://github.com/bujnlc8/gptbing # 进入项目目录 cd gptbing/wechatbot -# 复制配置文件 -copy config.dev.json config.json +# 复制配置文件, 改成实际的值,注意去掉#注释 +copy config.json.example config.json # 启动项目 go run main.go + +或者docker部署 + +bash start.sh 0.0.2 # 代理地址根据实际情况修改,运行之后`docker logs wechatbot`会打印出登录地址 + ``` -本项目fork至[https://github.com/djun/wechatbot](https://github.com/djun/wechatbot),修改使之支持`ChatGPT`和`New bing`,在此致谢! +## 说明 + +本项目fork至[https://github.com/djun/wechatbot](https://github.com/djun/wechatbot),修改使之支持`ChatGPT`和`New Bing`,在此致谢! **⚠️ 有一定的几率导致被微信封号,请谨慎使用,由此导致的封号,本人概不负责** diff --git a/wechatbot/config.json.example b/wechatbot/config.json.example index e105e78..b75b407 100644 --- a/wechatbot/config.json.example +++ b/wechatbot/config.json.example @@ -1,5 +1,5 @@ { - "api_key": "", - "auto_pass": true, - "bing_chat_url": "" + "api_key": "", # chatgpt api key + "auto_pass": true, # 是否自动通过好友申请 + "bing_chat_url": "" # New Bing 聊天接口 } diff --git a/wechatbot/start.sh b/wechatbot/start.sh new file mode 100644 index 0000000..b626a52 --- /dev/null +++ b/wechatbot/start.sh @@ -0,0 +1,9 @@ +docker pull yy194131/chatgpt:$1 + +count=$(docker ps -a | grep wechatbot | wc -l) +if [ $count -gt 0 ]; then + docker stop wechatbot && docker rm wechatbot +fi + +# 代理地址改成实际的地址 +docker run --name wechatbot -d -e https_proxy=代理地址 -v $(pwd)/config.json:/app/config.json yy194131/chatgpt:$1