rchatgpt-on-wecom


Namerchatgpt-on-wecom JSON
Version 1.3.4 PyPI version JSON
download
home_pagehttps://github.com/yanjlee/chatgpt-on-wecom
Summary基于ChatGPT的企业微信聊天应用,通过 [OpenAI](https://github.com/openai/openai-quickstart-python) 接口生成对话内容,使用 [wechatpy](https://github.com/wechatpy/wechatpy) 实现企业微信应用号消息的接收和回复.
upload_time2024-06-01 07:28:18
maintainerNone
docs_urlNone
authoryanjlee
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 简介

基于ChatGPT的企业微信聊天应用,通过 [OpenAI](https://github.com/openai/openai-quickstart-python) 接口生成对话内容,使用 [wechatpy](https://github.com/wechatpy/wechatpy) 实现企业微信应用号消息的接收和回复。已实现的特性如下:

- [x] **文本对话:** 接收发送给应用号的企业微信消息,使用ChatGPT生成回复内容,完成自动回复
- [x] **上下文记忆**:支持多轮对话记忆,且为每个好友维护独立的上下会话


# 更新日志
1、创建:基于 https://github.com/zhayujie/chatgpt-on-wechat 的微信对话项目,稍加改造,增加企业微信应用的功能。
2、更新:改用最新的GPT3.5-Turbo接口

# 快速开始

## 准备

### 1. OpenAI账号注册

前往 [OpenAI注册页面](https://beta.openai.com/signup) 创建账号,参考这篇 [教程](https://www.cnblogs.com/damugua/p/16969508.html) 可以通过虚拟手机号来接收验证码。创建完账号则前往 [API管理页面](https://beta.openai.com/account/api-keys) 创建一个 API Key 并保存下来,后面需要在项目中配置这个key。

> 项目中使用的对话模型是 davinci,计费方式是约每 750 字 (包含请求和回复) 消耗 $0.02,图片生成是每张消耗 $0.016,账号创建有免费的 $18 额度,使用完可以更换邮箱重新注册。


### 2.运行环境

支持 Linux、MacOS、Windows 系统(可在Linux服务器上长期运行),同时需安装 `Python`。 
> 建议Python版本在 3.7.1~3.9.X 之间,3.10及以上版本在 MacOS 可用,其他系统上不确定能否正常运行。


1.克隆项目代码:

```bash
git clone https://github.com/mostlittlebee/chatgpt-on-wecom
cd chatgpt-on-wecom/
```

2.安装所需核心依赖:

```bash
pip3 install flask
pip3 install wechatpy
pycryptodome
pip3 install --upgrade openai
```
注:`openai`使用最新版本,需高于等于0.27.0 ,如果之前安装过请单独更新下pip3 install --upgrade openai

## 配置

配置文件的模板在根目录的`config-template.json`中,需复制该模板创建最终生效的 `config.json` 文件:

```bash
cp config-template.json config.json
```

然后在`config.json`中填入配置,以下是对默认配置的说明,可根据需要进行自定义修改:

```bash
# config.json文件内容示例
{ 
  "open_ai_api_key": "你的OPENAI KEY",
  "conversation_max_tokens": 最大返回字符,
  "WECHAT_TOKEN": "企业微信 回调token",
  "WECHAT_ENCODING_AES_KEY":"企业微信 编码后的AES Key",
  "WECHAT_CORP_ID":"企业微信 企业ID",
  "Secret":"企业微信 应用Secret",
  "AppId":"企业微信 应用ID",
  "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。
}
```



## 运行

### 1.本地运行

如果是开发机 **本地运行**,直接在项目根目录下执行:

```bash
python3 app.py
```


### 2.服务器部署

使用nohup命令在后台运行程序:

```bash
touch nohup.out                                   # 首次运行需要新建日志文件                     
nohup python3 app.py & tail -f nohup.out          # 在后台运行程序并通过日志输出二维码
```

> **特殊指令:** 用户向应用号发送 **#清除记忆** 即可清空该用户的上下文记忆。 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yanjlee/chatgpt-on-wecom",
    "name": "rchatgpt-on-wecom",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "yanjlee",
    "author_email": "yanjlee@163.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/5a/f135b6f95f2db58fd548bd84f7e28f7ed81ed920b962812f38d5ad163d9f/rchatgpt_on_wecom-1.3.4.tar.gz",
    "platform": null,
    "description": "# \u7b80\u4ecb\r\n\r\n\u57fa\u4e8eChatGPT\u7684\u4f01\u4e1a\u5fae\u4fe1\u804a\u5929\u5e94\u7528\uff0c\u901a\u8fc7 [OpenAI](https://github.com/openai/openai-quickstart-python) \u63a5\u53e3\u751f\u6210\u5bf9\u8bdd\u5185\u5bb9\uff0c\u4f7f\u7528 [wechatpy](https://github.com/wechatpy/wechatpy) \u5b9e\u73b0\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u53f7\u6d88\u606f\u7684\u63a5\u6536\u548c\u56de\u590d\u3002\u5df2\u5b9e\u73b0\u7684\u7279\u6027\u5982\u4e0b\uff1a\r\n\r\n- [x] **\u6587\u672c\u5bf9\u8bdd\uff1a** \u63a5\u6536\u53d1\u9001\u7ed9\u5e94\u7528\u53f7\u7684\u4f01\u4e1a\u5fae\u4fe1\u6d88\u606f\uff0c\u4f7f\u7528ChatGPT\u751f\u6210\u56de\u590d\u5185\u5bb9\uff0c\u5b8c\u6210\u81ea\u52a8\u56de\u590d\r\n- [x] **\u4e0a\u4e0b\u6587\u8bb0\u5fc6**\uff1a\u652f\u6301\u591a\u8f6e\u5bf9\u8bdd\u8bb0\u5fc6\uff0c\u4e14\u4e3a\u6bcf\u4e2a\u597d\u53cb\u7ef4\u62a4\u72ec\u7acb\u7684\u4e0a\u4e0b\u4f1a\u8bdd\r\n\r\n\r\n# \u66f4\u65b0\u65e5\u5fd7\r\n1\u3001\u521b\u5efa\uff1a\u57fa\u4e8e https://github.com/zhayujie/chatgpt-on-wechat \u7684\u5fae\u4fe1\u5bf9\u8bdd\u9879\u76ee\uff0c\u7a0d\u52a0\u6539\u9020\uff0c\u589e\u52a0\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u7684\u529f\u80fd\u3002\r\n2\u3001\u66f4\u65b0\uff1a\u6539\u7528\u6700\u65b0\u7684GPT3.5-Turbo\u63a5\u53e3\r\n\r\n# \u5feb\u901f\u5f00\u59cb\r\n\r\n## \u51c6\u5907\r\n\r\n### 1. OpenAI\u8d26\u53f7\u6ce8\u518c\r\n\r\n\u524d\u5f80 [OpenAI\u6ce8\u518c\u9875\u9762](https://beta.openai.com/signup) \u521b\u5efa\u8d26\u53f7\uff0c\u53c2\u8003\u8fd9\u7bc7 [\u6559\u7a0b](https://www.cnblogs.com/damugua/p/16969508.html) \u53ef\u4ee5\u901a\u8fc7\u865a\u62df\u624b\u673a\u53f7\u6765\u63a5\u6536\u9a8c\u8bc1\u7801\u3002\u521b\u5efa\u5b8c\u8d26\u53f7\u5219\u524d\u5f80 [API\u7ba1\u7406\u9875\u9762](https://beta.openai.com/account/api-keys) \u521b\u5efa\u4e00\u4e2a API Key \u5e76\u4fdd\u5b58\u4e0b\u6765\uff0c\u540e\u9762\u9700\u8981\u5728\u9879\u76ee\u4e2d\u914d\u7f6e\u8fd9\u4e2akey\u3002\r\n\r\n> \u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u5bf9\u8bdd\u6a21\u578b\u662f davinci\uff0c\u8ba1\u8d39\u65b9\u5f0f\u662f\u7ea6\u6bcf 750 \u5b57 (\u5305\u542b\u8bf7\u6c42\u548c\u56de\u590d) \u6d88\u8017 $0.02\uff0c\u56fe\u7247\u751f\u6210\u662f\u6bcf\u5f20\u6d88\u8017 $0.016\uff0c\u8d26\u53f7\u521b\u5efa\u6709\u514d\u8d39\u7684 $18 \u989d\u5ea6\uff0c\u4f7f\u7528\u5b8c\u53ef\u4ee5\u66f4\u6362\u90ae\u7bb1\u91cd\u65b0\u6ce8\u518c\u3002\r\n\r\n\r\n### 2.\u8fd0\u884c\u73af\u5883\r\n\r\n\u652f\u6301 Linux\u3001MacOS\u3001Windows \u7cfb\u7edf\uff08\u53ef\u5728Linux\u670d\u52a1\u5668\u4e0a\u957f\u671f\u8fd0\u884c)\uff0c\u540c\u65f6\u9700\u5b89\u88c5 `Python`\u3002 \r\n> \u5efa\u8baePython\u7248\u672c\u5728 3.7.1~3.9.X \u4e4b\u95f4\uff0c3.10\u53ca\u4ee5\u4e0a\u7248\u672c\u5728 MacOS \u53ef\u7528\uff0c\u5176\u4ed6\u7cfb\u7edf\u4e0a\u4e0d\u786e\u5b9a\u80fd\u5426\u6b63\u5e38\u8fd0\u884c\u3002\r\n\r\n\r\n1.\u514b\u9686\u9879\u76ee\u4ee3\u7801\uff1a\r\n\r\n```bash\r\ngit clone https://github.com/mostlittlebee/chatgpt-on-wecom\r\ncd chatgpt-on-wecom/\r\n```\r\n\r\n2.\u5b89\u88c5\u6240\u9700\u6838\u5fc3\u4f9d\u8d56\uff1a\r\n\r\n```bash\r\npip3 install flask\r\npip3 install wechatpy\r\npycryptodome\r\npip3 install --upgrade openai\r\n```\r\n\u6ce8\uff1a`openai`\u4f7f\u7528\u6700\u65b0\u7248\u672c\uff0c\u9700\u9ad8\u4e8e\u7b49\u4e8e0.27.0 \uff0c\u5982\u679c\u4e4b\u524d\u5b89\u88c5\u8fc7\u8bf7\u5355\u72ec\u66f4\u65b0\u4e0bpip3 install --upgrade openai\r\n\r\n## \u914d\u7f6e\r\n\r\n\u914d\u7f6e\u6587\u4ef6\u7684\u6a21\u677f\u5728\u6839\u76ee\u5f55\u7684`config-template.json`\u4e2d\uff0c\u9700\u590d\u5236\u8be5\u6a21\u677f\u521b\u5efa\u6700\u7ec8\u751f\u6548\u7684 `config.json` \u6587\u4ef6\uff1a\r\n\r\n```bash\r\ncp config-template.json config.json\r\n```\r\n\r\n\u7136\u540e\u5728`config.json`\u4e2d\u586b\u5165\u914d\u7f6e\uff0c\u4ee5\u4e0b\u662f\u5bf9\u9ed8\u8ba4\u914d\u7f6e\u7684\u8bf4\u660e\uff0c\u53ef\u6839\u636e\u9700\u8981\u8fdb\u884c\u81ea\u5b9a\u4e49\u4fee\u6539\uff1a\r\n\r\n```bash\r\n# config.json\u6587\u4ef6\u5185\u5bb9\u793a\u4f8b\r\n{ \r\n  \"open_ai_api_key\": \"\u4f60\u7684OPENAI KEY\",\r\n  \"conversation_max_tokens\": \u6700\u5927\u8fd4\u56de\u5b57\u7b26,\r\n  \"WECHAT_TOKEN\": \"\u4f01\u4e1a\u5fae\u4fe1 \u56de\u8c03token\",\r\n  \"WECHAT_ENCODING_AES_KEY\":\"\u4f01\u4e1a\u5fae\u4fe1 \u7f16\u7801\u540e\u7684AES Key\",\r\n  \"WECHAT_CORP_ID\":\"\u4f01\u4e1a\u5fae\u4fe1 \u4f01\u4e1aID\",\r\n  \"Secret\":\"\u4f01\u4e1a\u5fae\u4fe1 \u5e94\u7528Secret\",\r\n  \"AppId\":\"\u4f01\u4e1a\u5fae\u4fe1 \u5e94\u7528ID\",\r\n  \"character_desc\": \"\u4f60\u662fChatGPT, \u4e00\u4e2a\u7531OpenAI\u8bad\u7ec3\u7684\u5927\u578b\u8bed\u8a00\u6a21\u578b, \u4f60\u65e8\u5728\u56de\u7b54\u5e76\u89e3\u51b3\u4eba\u4eec\u7684\u4efb\u4f55\u95ee\u9898\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u8bed\u8a00\u4e0e\u4eba\u4ea4\u6d41\u3002\r\n}\r\n```\r\n\r\n\r\n\r\n## \u8fd0\u884c\r\n\r\n### 1.\u672c\u5730\u8fd0\u884c\r\n\r\n\u5982\u679c\u662f\u5f00\u53d1\u673a **\u672c\u5730\u8fd0\u884c**\uff0c\u76f4\u63a5\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u6267\u884c\uff1a\r\n\r\n```bash\r\npython3 app.py\r\n```\r\n\r\n\r\n### 2.\u670d\u52a1\u5668\u90e8\u7f72\r\n\r\n\u4f7f\u7528nohup\u547d\u4ee4\u5728\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f\uff1a\r\n\r\n```bash\r\ntouch nohup.out                                   # \u9996\u6b21\u8fd0\u884c\u9700\u8981\u65b0\u5efa\u65e5\u5fd7\u6587\u4ef6                     \r\nnohup python3 app.py & tail -f nohup.out          # \u5728\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f\u5e76\u901a\u8fc7\u65e5\u5fd7\u8f93\u51fa\u4e8c\u7ef4\u7801\r\n```\r\n\r\n> **\u7279\u6b8a\u6307\u4ee4\uff1a** \u7528\u6237\u5411\u5e94\u7528\u53f7\u53d1\u9001 **#\u6e05\u9664\u8bb0\u5fc6** \u5373\u53ef\u6e05\u7a7a\u8be5\u7528\u6237\u7684\u4e0a\u4e0b\u6587\u8bb0\u5fc6\u3002 \r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u57fa\u4e8eChatGPT\u7684\u4f01\u4e1a\u5fae\u4fe1\u804a\u5929\u5e94\u7528\uff0c\u901a\u8fc7 [OpenAI](https://github.com/openai/openai-quickstart-python) \u63a5\u53e3\u751f\u6210\u5bf9\u8bdd\u5185\u5bb9\uff0c\u4f7f\u7528 [wechatpy](https://github.com/wechatpy/wechatpy) \u5b9e\u73b0\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u53f7\u6d88\u606f\u7684\u63a5\u6536\u548c\u56de\u590d.",
    "version": "1.3.4",
    "project_urls": {
        "Homepage": "https://github.com/yanjlee/chatgpt-on-wecom"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "138e9c8034b30cafed0a128d303012498b1e7a64db8446f7c1ffe80aa8e7fe53",
                "md5": "bfe4f140c32b85744139777b7fc217ae",
                "sha256": "537d5132e311afb6f126304db31f7c184d934e0ae2dcb2045cc1e34f1df3a9cd"
            },
            "downloads": -1,
            "filename": "rchatgpt_on_wecom-1.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bfe4f140c32b85744139777b7fc217ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15736,
            "upload_time": "2024-06-01T07:28:16",
            "upload_time_iso_8601": "2024-06-01T07:28:16.535033Z",
            "url": "https://files.pythonhosted.org/packages/13/8e/9c8034b30cafed0a128d303012498b1e7a64db8446f7c1ffe80aa8e7fe53/rchatgpt_on_wecom-1.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e95af135b6f95f2db58fd548bd84f7e28f7ed81ed920b962812f38d5ad163d9f",
                "md5": "589d39f75d1c91165ca34cc9469f7bde",
                "sha256": "d6aa492e33c566a3e2ec6aef0675ff3780a53e6a8efebee024161802699a31e9"
            },
            "downloads": -1,
            "filename": "rchatgpt_on_wecom-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "589d39f75d1c91165ca34cc9469f7bde",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16800,
            "upload_time": "2024-06-01T07:28:18",
            "upload_time_iso_8601": "2024-06-01T07:28:18.617614Z",
            "url": "https://files.pythonhosted.org/packages/e9/5a/f135b6f95f2db58fd548bd84f7e28f7ed81ed920b962812f38d5ad163d9f/rchatgpt_on_wecom-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-01 07:28:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yanjlee",
    "github_project": "chatgpt-on-wecom",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rchatgpt-on-wecom"
}
        
Elapsed time: 4.69818s