Skip to main content

简介

基于ChatGPT的企业微信聊天应用,通过 OpenAI 接口生成对话内容,使用 wechatpy 实现企业微信应用号消息的接收和回复。已实现的特性如下:

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

更新日志

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

快速开始

准备

1. OpenAI账号注册

前往 OpenAI注册页面 创建账号,参考这篇 教程 可以通过虚拟手机号来接收验证码。创建完账号则前往 API管理页面 创建一个 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.克隆项目代码:

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

2.安装所需核心依赖:

pip3 install flask
pip3 install wechatpy
pycryptodome
pip3 install --upgrade openai

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

配置

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

cp config-template.json config.json

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

# 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.本地运行

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

python3 app.py

2.服务器部署

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

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

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

Metadata

Release files for rchatgpt-on-wecom 1.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rchatgpt-on-wecom 1.3.4
File Size Uploaded Provenance Actions
rchatgpt_on_wecom-1.3.4.tar.gz 16.8 kB Without provenance Details for rchatgpt_on_wecom-1.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rchatgpt-on-wecom 1.3.4
File Interpreter ABI Platform Actions
rchatgpt_on_wecom-1.3.4-py3-none-any.whl Python 3 none any Details for rchatgpt_on_wecom-1.3.4-py3-none-any.whl

Total release size: 32.5 kB

Release files / rchatgpt_on_wecom-1.3.4.tar.gz

Download URL rchatgpt_on_wecom-1.3.4.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d6aa492e33c566a3e2ec6aef0675ff3780a53e6a8efebee024161802699a31e9
BLAKE2b-256 checksum
How to use checksums
e95af135b6f95f2db58fd548bd84f7e28f7ed81ed920b962812f38d5ad163d9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Release files / rchatgpt_on_wecom-1.3.4-py3-none-any.whl

Download URL rchatgpt_on_wecom-1.3.4-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
537d5132e311afb6f126304db31f7c184d934e0ae2dcb2045cc1e34f1df3a9cd
BLAKE2b-256 checksum
How to use checksums
138e9c8034b30cafed0a128d303012498b1e7a64db8446f7c1ffe80aa8e7fe53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.2

Security for rchatgpt-on-wecom 1.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page