Skip to content

Commit

Permalink
Merge pull request #434 from fuergaosi233/chore/update
Browse files Browse the repository at this point in the history
Chore/update
  • Loading branch information
fuergaosi233 authored Dec 28, 2022
2 parents 53b7fa0 + 361e1d3 commit 83353b0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 203 deletions.
100 changes: 1 addition & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
> Use ChatGPT On Wechat via wechaty
English | [中文文档](README_ZH.md)

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/BHJD6L?referralCode=FaJtD_)

If you don't have a server or want to experience rapid deployment, you can use Railway to do so, see [Usage with Railway](#usage-with-railway).

### Update Decomber 27, 2022
Using railway & docker deployment, there may be problems that cannot be solved, we are working on it.

Expand All @@ -25,16 +21,6 @@ Thanks @transitive-bullshit, The ChatGPT API automates the work.
You should use password & username to login, and config [CAPTCHAs](#CAPTCHAS).
⚠️ There may be a problem with the Docker image because I don't have an X86 device and Qume doesn't work.

### Update December 13, 2022

~~Yesterday (2022.12.12), OpenAI upgraded the authentication measures.~~

~~It causes `⚠️ No chatgpt item in pool` when you use this project.~~

~~However, please rest assured that we are actively looking for an effective solution,~~

~~If you have a good solution, feel free to contribute!~~

## 🌟 Feature

- [x] Use ChatGPT On Wechat via wechaty
Expand All @@ -45,44 +31,7 @@ You should use password & username to login, and config [CAPTCHAs](#CAPTCHAS).
- [x] Publish to Docker.hub
- [x] Add Railway deploy
- [x] Auto Reload OpenAI Accounts Pool
- [ ] Add sendmessage retry for 429/503

## Use with docker in Linux(recommended)

```sh
cp config.yaml.example config.yaml
# Change Config.yaml
# run docker command in Linux or WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
```

## Use with docker in Windows

```sh
# Create and modify config.yaml in the current directory
# run docker command in WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# In the Windows command line (cmd) environment, you may mount the current directory like this:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
```

## Upgrade docker image version

```sh
docker pull holegots/wechat-chatgpt:latest
docker stop wechat-chatgpt
docker rm wechat-chatgpt
# run docker command in Linux or WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# In the Windows command line (cmd) environment, you may mount the current directory like this:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
```
- [X] Add sendmessage retry for 429/503

## Install

Expand Down Expand Up @@ -152,53 +101,6 @@ npm run dev

If you are logging in for the first time, then you need to scan the qrcode.

## Usage with Railway

[Railway](https://railway.app/) is a deployment platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.This section describes how to quickly deploy a wechat-chatgpt project using Railway.

Firstly, you'll need to sign up for a Railway account and sign in using GitHub verification.

Then click the one-click deployment button below to deploy.

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/BHJD6L?referralCode=FaJtD_)

After some validation is complete, you can begin the deployment.You will see the following interface:

![railway-deployment](docs/images/railway-deployment.png)

Some environment variables need to be configured:

- **CHAT_GPT_EMAIL** : Your OpenAI Account email, if you have session_token, It's optional.

- **CHAT_GPT_PASSWORD** : Your OpenAI Account password, *if you have session_token, It's optional*.

- **CHAT_GPT_RETRY_TIMES** : The number of times to retry when the OpenAI API returns 429 or 503.

- **CHAT_PRIVATE_TRIGGER_KEYWORD** : If you hope only some keywords can trigger chatgpt on private chat, you can set it.

Click the Deploy button and your service will start deploying shortly.The following interface appears to indicate that the deployment has begun:

![railway-deploying](docs/images/railway-deploying.png)

When the deployment is displayed successfully, click to view the logs and find the WeChat login link in Deploy Logs.

![railway-deployed](docs/images/railway-deployed.png)

Click to enter and use your prepared WeChat to scan the code to log in.

Log in successfully and start sending and receiving messages(This process can take several minutes):

![railway-success](docs/images/railway-succeed.png)

Besides, in deployment, you may encounter the following issues:

- **Error: ⚠️ No chatgpt item in pool** : This error means that you have not configured the OpenAI account information correctly. You can solve this problem from the following aspects:1. Check whether the token or openAI account and password are filled in correctly. 2. The token may have expired (experience shows that the expiration time of the token is **24** hours), you can go to the chatGPT official website to re-obtain the token. 3. Redeploy Current Services.Note that the above should be modified on the Variables page in Railway Dashboard.
- **After the deployment is complete, the QR code is not generated**.Try **refreshing** the page to see again if the Deploy Logs panel generated a link and QR code.
- **The generated QR code cannot be scanned**.On the generated QR code, there is a link that can be clicked to scan the QR code.
- **Message feedback is very slow**.Because Railway's servers are deployed overseas, there is an increase in message feedback latency, but it is still within the acceptance range. If you are time sensitive, you can use your own server deployment.

## Author

👤 **holegots**

- Twitter: [@fuergaosi](https://twitter.com/fuergaosi)
Expand Down
97 changes: 2 additions & 95 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@
> 在微信上迅速接入 ChatGPT,让它成为你最好的助手!
> [English](README.md) | 中文文档
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/BHJD6L?referralCode=FaJtD_)

如果你没有自己的服务器或者想体验快速部署,可使用 Railway 进行部署,参见 [Railway 部署](#railway-部署)

### 2022.12.27 更新
目前, 使用 Docker 或 Railway 部署, 会出现意料之外的问题, 我们正在努力解决。

### 2022.12.20 更新

感谢 @transitive-bullshit [的工](), 使得ChatGPT API可以自动完成这项工作。
感谢 @transitive-bullshit 的工作, 使得ChatGPT API可以自动完成这项工作。
现在可以使用密码的用户名来登录, 并配置打码 [CAPTCHAs](#CAPTCHAS) 来使得整个流程全自动化.

### 2022.12.12 更新
~~昨天(2022.12.12),OpenAI 加入了CloudFlare认证措施。~~

~~这使得本项目在运行是会出现 `⚠️ No chatgpt item in pool` 的错误。~~

~~我们正在积极寻找有效的解决方案,如果你有好的解决方案,欢迎贡献!~~

## 🌟 功能点

Expand All @@ -41,44 +31,7 @@
- [x] 发布到 Docker.hub
- [x] 通过 Railway 进行部署
- [x] 实现 OpenAI 账户池的热加载
- [ ] 当 OpenAI 返回码为 429/503 时自动重试

## 在Linux上通过Docker使用(✅ 推荐)

```sh
cp config.yaml.example config.yaml
# 在当前目录创建并修改config.yaml
# 在Linux或WindowsPowerShell上运行如下命令
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# 使用二维码登陆
docker logs -f wechat-chatgpt
```

## 在Windows上通过Docker使用

```sh
# 在当前目录创建并修改config.yaml
# 在WindowsPowerShell中运行如下命令
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# 在Windows command line (cmd)中, 您需要像这样修改上述代码的挂载目录:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# 通过二维码登录
docker logs -f wechat-chatgpt
```

## 更新Docker镜像版本

```sh
docker pull holegots/wechat-chatgpt:latest
docker stop wechat-chatgpt
docker rm wechat-chatgpt
# 在Linux或WindowsPowerShell上运行如下命令
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# 在Windows command line (cmd)中, 您需要像这样修改上述代码的挂载目录:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# 通过二维码登录
docker logs -f wechat-chatgpt
```
- [X] 当 OpenAI 返回码为 429/503 时自动重试

## 安装

Expand Down Expand Up @@ -142,52 +95,6 @@ npm run dev
```

如果您是初次登陆,那么需要扫描二维码

## 使用 Railway 部署

[Railway](https://railway.app/) 是一个部署平台,您可以在其上配置基础架构,在本地使用该基础架构进行开发,然后将其部署到云端。本部分将描述如何快速使用 Railway 部署一个 wechat-chatgpt 项目。

首先,您需要注册一个 Railway 帐户,并使用 GitHub 验证登录。

然后点击下面的一键部署按钮进行部署。

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/BHJD6L?referralCode=FaJtD_)

完成一些验证操作后,就可以开始部署了。您将看到以下界面:

![railway-deployment](docs/images/railway-deployment.png)

您需要配置一些环境变量:

- **CHAT_GPT_EMAIL** :您的 OpenAI 帐户电子邮件,如果您有 session_token,则可不填。

- **CHAT_GPT_PASSWORD** :您的 OpenAI 帐户密码,如果您有 session_token,则可不填。

- **CHAT_GPT_RETRY_TIMES** :当 OpenAI API 返回 429 或 503 时重试的次数。

- **CHAT_PRIVATE_TRIGGER_KEYWORD** :如果您希望只有一些关键字才能在私人聊天中触发 ChatGPT,则可以设置它。

点击“部署”按钮,您的服务将立即开始部署。以下界面出现表示部署已经开始:

![railway-deploying](docs/images/railway-deploying.png)

当部署过程显示为成功后,点击查看日志,在部署日志中找到微信登录链接:

![railway-deployed](docs/images/railway-deployed.png)

点击链接,使用准备好的微信扫码登录。

成功登录并开始发送和接收消息(此过程可能需要几分钟):

![railway-success](docs/images/railway-succeed.png)

此外,在部署中,您可能会遇到以下问题:

- **Error: ⚠️ No chatgpt item in pool**:此错误表示验证信息有问题。您可以从以下几个方面解决此问题:1.检查 token 或 openAI 账号和密码是否正确填写。2. token 可能已经过期(经验表明 token 的过期时间为**24**小时),您可以到 chatGPT 官网重新获取 token。3. 重新部署当前服务。请注意,应在铁路仪表板的 **Variables** 页面上修改上述内容。
- **部署完成后,不会生成二维码**。尝试**刷新**页面,再次查看 Deploy Logs 面板是否生成了链接和二维码。
- **生成的二维码无法扫描**。在生成的二维码上,有一个链接可以点击扫描二维码。
- **消息反馈缓慢**。由于 Railway 的服务器部署在海外,消息反馈延迟会有所增加,但仍在可接受范围内。如果您对时间敏感,则可以使用自己的服务器部署。

## 作者

👤 **holegots**
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"chatgpt": "^3.3.1",
"chatgpt": "^3.3.6",
"dotenv": "^16.0.3",
"execa": "^6.1.0",
"qrcode": "^1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bot = WechatyBuilder.build({
// get a Wechaty instance

async function main() {
await chatGPTBot.startGPTBot();
bot
.on("scan", async (qrcode, status) => {
const url = `https://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`;
Expand All @@ -24,7 +25,6 @@ async function main() {
.on("login", async (user) => {
console.log(`User ${user} logged in`);
chatGPTBot.setBotName(user.name());
await chatGPTBot.startGPTBot();
})
.on("message", async (message) => {
if (!chatGPTBot.ready) {
Expand Down

0 comments on commit 83353b0

Please sign in to comment.