Code Monkey home page Code Monkey logo

chatgpt-on-wecom's Introduction

简介

基于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          # 在后台运行程序并通过日志输出二维码

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

chatgpt-on-wecom's People

Contributors

mostlittlebee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chatgpt-on-wecom's Issues

企业微信消息重复请求

因为企业微信5秒内没有收到服务端的响应,会进行断连重试,导致有时候同一个问题被连续问了好几次。这个问题能否帮忙处理一下呢,做下请求缓存啥的。我也不清楚为啥明明异步了,给微信服务端的响应还是会超过5秒,当然很可能是因为我的VPS在国外的原因,网络不稳定导致的。不过最好还是能修复一下哈,谢谢了

openapi回调地址请求不通过

我在本地clone项目并运行,在访问地址http://10.10.10.8:8888/wechat时出现报错提示如下:
Forbidden
You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.
终端显示:” "GET /wechat HTTP/1.1" 403 -“

在访问地址http://10.10.10.8:8888/wechat/时出现报错提示如下:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
终端显示:"GET /wechat/ HTTP/1.1" 404 -

另外,我的问题其实是在保存“微信企业号的接收消息服务器配置” 时提示 “openapi回调地址请求不通过”。看到lssues中有相关讨论作者表示需要在域名加上/wechat或/wechat/,这两个路径测试下来依旧提示“openapi回调地址请求不通过”。所以在本地进行测试出现上述问题。

请问:
1、微信企业号在添加应用后除了配置”接收消息“还有无其它配置(如网页授权及JS-SDK,企业可信IP等)

我已做过的测试:
1、为chatgpt-on-wecom整个目录添加777权限

我的环境:
ubuntu 20.04
python 3.8

我的配置:
微信图片编辑_20230303222616

微信图片_20230303222905

怎么得到chatgpt的回复

我已经自建好企业微信应用,并且已经启用了API接收(看到服务器端显示200)。我用个人微信扫那个企业微信,成功入群,发送消息别人也能看见(但得不到chatgpt的任何回复)。我现在的问题是,如何让chatgpt参与讨论(回复问题)?是需要特别的指令或at谁一下吗?

企业微信自建应用的配置

请问企业微信后台自建应用中接收消息服务器配置段的url应该怎么配置?在保存时一直提示openapi回调地址请求不通过

gpt地址问题

因无法直接访问chatgpt的api,我配置了一个api的代理地址,我应该修改哪个文件,来使用自定义的api地址

企业微信配置该如何获取

  "WECHAT_TOKEN": "企业微信 回调token",
  "WECHAT_ENCODING_AES_KEY":"企业微信 编码后的AES Key",
  "WECHAT_CORP_ID":"企业微信 企业ID",
  "Secret":"企业微信 应用Secret",
  "AppId":"企业微信 应用ID",

我创建了个企业微信,以前没有配置过,不太清楚,请教一下,谢谢。
看了开发者中心创建的,比较像,https://developer.work.weixin.qq.com/tool#/tab/apps/list
但是搜教程又是在应用管理里配置,搞不清楚。。
应用管理里配置的只看到 AppId,Secret
WECHAT_TOKEN、WECHAT_ENCODING_AES_KEY 只在开发者中心文档里看到

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.