Skip to content

Commit 9cf8874

Browse files
committed
docs: update readme.md
1 parent eef0dfc commit 9cf8874

File tree

5 files changed

+99
-3
lines changed

5 files changed

+99
-3
lines changed

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 zhayujie
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# 简介
2+
3+
本项目是基于ChatGPT模型实现的微信聊天机器人,通过[revChatGPT](https://github.com/acheong08/ChatGPT) 访问 ChatGPT接口,使用 [itchat](https://github.com/littlecodersh/ItChat) 实现微信消息的接收和发送。已实现的功能如下:
4+
5+
- [x] **基础功能:** 接收私聊及群组中的微信消息,使用ChatGPT生成回复内容,完成自动回复
6+
- [x] **规则定制化:** 支持私聊中按指定规则触发自动回复,支持对群组设置自动回复白名单
7+
- [x] **会话上下文:** 支持用户维度的上下文保存和过期清理
8+
- [x] **Session刷新:** 支持ChatGPT session的定时刷新保鲜
9+
- [x] **多账号:** 支持多微信账号同时运行
10+
11+
12+
# 快速开始
13+
14+
## 准备
15+
### 1.网页版微信
16+
17+
本方案中实现微信消息的收发依赖了网页版微信的登录,可以尝试登录 <https://wx.qq.com/>,如果能够成功登录就可以开始后面的步骤了。
18+
19+
### 2.运行环境
20+
21+
操作系统支持 Linux、MacOS、Windows,并需安装 `Python3.6` 及以上版本。推荐使用Linux服务器,可以托管在后台长期运行。
22+
23+
### 3.项目安装
24+
25+
克隆本项目代码:
26+
27+
```bash
28+
https://github.com/zhayujie/chatgpt-on-wechat
29+
```
30+
31+
安装所需依赖:
32+
33+
```bash
34+
pip3 install revChatGPT
35+
pip3 install itchat
36+
```
37+
38+
39+
## 配置
40+
41+
配置文件在根目录的 `config.json` 中,示例文件及各配置项解析如下:
42+
43+
```json
44+
{
45+
// TODO
46+
}
47+
```
48+
49+
其中 token的设置需要在openAI网页端获取:
50+
51+
- 打开 <https://chat.openai.com/chat> 并登录,可使用测试账号 ([email protected], 密码yy123123),账号来源为该[文章](https://www.bilibili.com/read/cv20257021)
52+
- F12 进入开发者控制台
53+
- 选择Application -> Cookies,将 session-token 中的值填入配置中
54+
55+
![](https://blog.cos.zhayujie.com/bot/chatgpt-token.png)
56+
57+
58+
## 运行
59+
60+
1.如果是开发机本地调试,直接执行:
61+
62+
```
63+
python3 app.py
64+
```
65+
终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了。
66+
67+
68+
2.如果是服务器部署,则使用nohup在后台运行:
69+
70+
```
71+
nohup python3 app.py &
72+
```
73+
74+
## 使用
75+

bot/chatgpt/chat_gpt_bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
config = {
77
"Authorization": "<Your Bearer Token Here>", # This is optional
8-
"session_token": "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..n8p94letJscz9y64.vgWOg1sSU7Wkoxbs81kTB_9rGgXQVmc6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PMtEEXz1IwiGAJ21z8Z77EOrL3vOWUnq3Y1sAPD9PBzaPC8_wezBIXQqI6Ufa6D38xPdZnkoaxMd3PRFu91s9qMoYO4OZ1WfjbQJi51T4M76y1K73eBLGwVgWRguEs8Yqr2F-ctZ-BiSEa2RfOwYcmT5uRbFzZnQCtj32JTNMSIFGQ5It5bR0nPh5BK6LjK2_kbQny6dZ9d_KrBcl15REEKM9XhZOSGWRRwAmf_4iVsy6ceqXMuYMbEGL7xnw6tmBWzuuN21_1RnxY8JS8CtzjPC4LAIRgN7VE4M6LbEcQJiaw9hVsUzLueoP-CCtjBeqQ1ylsaz6C4rOpDISATG-jAQ66FE9P0YHXQXOAip4Bf7KO-IvSvZF_dKv2_RMdAE53dlpup5oCWqPk8qAVNgZXIT6LN8MiqRDVfObQDa-uElVtX8ll7ItOUXRoXUJfxabE6oW.bDrh_KN_-hbGsWTk_0z35g"
99
}
1010
chatbot = Chatbot(config)
1111
user_session = dict()

channel/wechat/wechat_channel.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def handler_group_msg(msg):
2121
WechatChannel().handle_group(msg)
2222

2323

24-
group_white_list = ['学就完事了', '小宝群', '全天乱斗模式', '戒赌吧', '命苦还要快乐', '攒钱让姐妹当小三的组织',
25-
'快乐家人', '技术沙龙', '流动性混子', '计算机学习交流', '如何评价']
24+
group_white_list = ['测试群1', '测试群2']
2625

2726

2827
class WechatChannel(Channel):

config.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"bot_": "123"
3+
}

0 commit comments

Comments
 (0)