02月13, 2023

WeChat接入ChatGPT

最近ChatGPT火爆网络,本文介绍如何将ChatGPT接入WeChat。

准备

  • OpenAi 的 ApiKey.

  • 云服务器.

  • NodeJs18.

注意:如果是Centos发行版,请使用Centos8。官方升级了全套工具链,导致 NodeJs18 不能在 Centos7及以前版本中使用。具体查看issue

步骤

下载

下载wechat-chatgpt源码,并且切换到new-wechatgpt分支。new-wechatgpt分支使用的新版本的chatgpt-api,放弃了ChatGPTAPIBrowser的使用。

git clone https://github.com/fuergaosi233/wechat-chatgpt.git

git checkout -b new-wechatgpt origin/new-wechatgpt

wechat-chatgp 通过 Docker 和 Railway部署目前都有问题,直接运行源码即可。

修改配置文件和chatgpt-api版本

  1. 将 OpenAi 的 ApiKey 添加到配置文件.env

cp .env.example .env

OPENAI_API_KEY=xxxxxxxxx
  1. 将 package.json 的版本修改^4.2.0
"chatgpt": "^4.2.0",

如果不修改chatgpt版本,可能出现未知错误,请看日志 | Error unknown, please see the log

运行

  1. npm install 安装相关依赖。

  2. npm run dev 启动项目。

  3. 用微信小号扫码登录(有封号危险⚠️)!

后台运行

  1. npm install pm2 -g 全局下载pm2。

  2. 编写pm2.json配置文件。

{
  "apps": [
    {
      "name": "wechat-gpt-bot",
      "script": "./dist/main.js",
      "cwd": "/root/wechat-chatgpt",
      "exec_mode": "fork",
      "max_memory_restart": "1G",
      "autorestart": true,
      "node_args": [],
      "args": [],
      "env": {}
    }
  ]
}
  1. pm2 startOrReload pm2.json 启动项目。

  2. pm2 logs 查看日志,日志有微信登录码。

本文链接:https://imyoyo.xyz/post/WeChat-jie-ru-ChatGPT.html

-- EOF --

Comments