Explorar el Código

docs: update readme.md

develop
zhayujie hace 1 año
padre
commit
9cf88744bf
Se han modificado 5 ficheros con 99 adiciones y 3 borrados
  1. +19
    -0
      LICENSE
  2. +75
    -0
      README.md
  3. +1
    -1
      bot/chatgpt/chat_gpt_bot.py
  4. +1
    -2
      channel/wechat/wechat_channel.py
  5. +3
    -0
      config.json

+ 19
- 0
LICENSE Ver fichero

@@ -0,0 +1,19 @@
Copyright (c) 2022 zhayujie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 75
- 0
README.md Ver fichero

@@ -0,0 +1,75 @@
# 简介

本项目是基于ChatGPT模型实现的微信聊天机器人,通过[revChatGPT](https://github.com/acheong08/ChatGPT) 访问 ChatGPT接口,使用 [itchat](https://github.com/littlecodersh/ItChat) 实现微信消息的接收和发送。已实现的功能如下:

- [x] **基础功能:** 接收私聊及群组中的微信消息,使用ChatGPT生成回复内容,完成自动回复
- [x] **规则定制化:** 支持私聊中按指定规则触发自动回复,支持对群组设置自动回复白名单
- [x] **会话上下文:** 支持用户维度的上下文保存和过期清理
- [x] **Session刷新:** 支持ChatGPT session的定时刷新保鲜
- [x] **多账号:** 支持多微信账号同时运行
# 快速开始

## 准备
### 1.网页版微信

本方案中实现微信消息的收发依赖了网页版微信的登录,可以尝试登录 <https://wx.qq.com/>,如果能够成功登录就可以开始后面的步骤了。

### 2.运行环境

操作系统支持 Linux、MacOS、Windows,并需安装 `Python3.6` 及以上版本。推荐使用Linux服务器,可以托管在后台长期运行。

### 3.项目安装

克隆本项目代码:

```bash
https://github.com/zhayujie/chatgpt-on-wechat
```

安装所需依赖:

```bash
pip3 install revChatGPT
pip3 install itchat
```


## 配置

配置文件在根目录的 `config.json` 中,示例文件及各配置项解析如下:

```json
{
// TODO
}
```

其中 token的设置需要在openAI网页端获取:

- 打开 <https://chat.openai.com/chat> 并登录,可使用测试账号 (lgfo353p@linshiyouxiang.net, 密码yy123123),账号来源为该[文章](https://www.bilibili.com/read/cv20257021)
- F12 进入开发者控制台
- 选择Application -> Cookies,将 session-token 中的值填入配置中

![](https://blog.cos.zhayujie.com/bot/chatgpt-token.png)


## 运行

1.如果是开发机本地调试,直接执行:

```
python3 app.py
```
终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了。


2.如果是服务器部署,则使用nohup在后台运行:

```
nohup python3 app.py &
```

## 使用


+ 1
- 1
bot/chatgpt/chat_gpt_bot.py Ver fichero

@@ -5,7 +5,7 @@ from common.log import logger

config = {
"Authorization": "<Your Bearer Token Here>", # This is optional
"session_token": "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..n8p94letJscz9y64.vgWOg1sSU7Wkoxbs81kTB_9rGgXQVmc6i9LgBHzo-EsUatVV-PsGKiAc9g8gaTaAf1pM_QW53ECH7b2Ge80ie2Q-EAsx-qdiLdwfggwob3dXk3zTQmK5pL8_aVNQ1YoMzQNciBXUbHdZhwzZrXPEsXr5eocjNm2fD5LcTR4cBwH4LRo9Z4AZsFBg9SJ9miQLLBdtkBmjWNQfwM_OHhlAKOYAT_aR1e3E0M6M173xbyvs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rBcl15REEKM9XhZOSGWRRwAmf_4iVsy6ceqXMuYMbEGL7xnw6tmBWzuuN21_1RnxY8JS8CtzjPC4LAIRgN7VE4M6LbEcQJiaw9hVsUzLueoP-CCtjBeqQ1ylsaz6C4rOpDISATG-jAQ66FE9P0YHXQXOAip4Bf7KO-IvSvZF_dKv2_RMdAE53dlpup5oCWqPk8qAVNgZXIT6LN8MiqRDVfObQDa-uElVtX8ll7ItOUXRoXUJfxabE6oW.bDrh_KN_-hbGsWTk_0z35g"
}
chatbot = Chatbot(config)
user_session = dict()


+ 1
- 2
channel/wechat/wechat_channel.py Ver fichero

@@ -21,8 +21,7 @@ def handler_group_msg(msg):
WechatChannel().handle_group(msg)


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


class WechatChannel(Channel):


+ 3
- 0
config.json Ver fichero

@@ -0,0 +1,3 @@
{
"bot_": "123"
}

Cargando…
Cancelar
Guardar