feat: update beta

This commit is contained in:
ikechan8370 2023-02-20 13:23:13 +08:00
parent 049e71b7bb
commit 5399d57e38
22 changed files with 147 additions and 13 deletions

View file

@ -1,4 +1,4 @@
## 本页面内容部分过时仅修改node-fetch部分可供参考。
## 本页面已过时
### Node.js >= 14 (并且 <18)时的安装方法

View file

@ -29,14 +29,8 @@ Node.js >= 18 / Node.js >= 14(with node-fetch)
> * 浏览器模式通过在本地启动Chrome等浏览器模拟用户访问ChatGPT网站使得获得和官方以及API2模式一模一样的回复质量同时保证安全性。缺点是本方法对环境要求较高需要提供桌面环境和一个可用的代理能够访问ChatGPT的IP地址且响应速度不如API而且高峰期容易无法使用。一般作为API3的下位替代。
> * 必应Bing将调用微软新必应接口进行对话。需要在必应网页能够正常使用新必应且设置有效的Bing登录Cookie方可使用。
1. 进入 Yunzai根目录
2. 检查 Node.js 版本
```
node -v
```
若 Node.js >= 18根据下方步骤安装即可。否则参考[这里](LowerNode.md)
3. 请将 chatgpt-plugin 放置在 Yunzai-Bot 的 plugins 目录下
2. 请将 chatgpt-plugin 放置在 Yunzai-Bot 的 plugins 目录下
推荐使用 git 进行安装,以方便后续升级。在 Yunzai-Bot 根目录夹打开终端,运行下述指令进行安装
@ -49,7 +43,8 @@ pnpm install -w undici chatgpt showdown mathjax-node delay uuid remark strip-mar
如果您需要使用基于浏览器的访问模式,请运行下述指令
> 浏览器模式仅为备选,如您需要使用浏览器模式,您还需要有**桌面环境**,优先级建议:必应>API>浏览器
> 浏览器模式仅为备选,如您需要使用浏览器模式,您还需要有**桌面环境**,优先级建议:必应>API3>浏览器
> 2.20更新必应被大削变得蠢了建议还是API3优先
请注意:**若使用API模式chatgpt的版本号注意要大于4.4.0**
**若使用Bing模式@waylaidwanderer/chatgpt-api 尽可能保持最新版本**

0
REDIS
View file

View file

@ -1,6 +1,8 @@
import plugin from '../../../lib/plugins/plugin.js'
import { Config } from '../utils/config.js'
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
import { exec } from 'child_process'
import {checkPnpm} from "../utils/common.js";
export class ChatgptManagement extends plugin {
constructor (e) {
@ -62,6 +64,10 @@ export class ChatgptManagement extends plugin {
{
reg: '^#chatgpt模式$',
fnc: 'modeHelp'
},
{
reg: '^#chatgpt(强制)更新$',
fnc: 'updateChatGPTPlugin'
}
]
})
@ -185,6 +191,69 @@ export class ChatgptManagement extends plugin {
}
}
async checkAuth (e) {
if (!e.isMaster) {
e.reply(`只有主人才能命令ChatGPT哦~
(*/ω*)`)
return false
}
return true
}
async updateChatGPTPlugin (e) {
let timer
if (!await this.checkAuth(e)) {
return true
}
let isForce = e.msg.includes('强制')
let command = 'git pull'
if (isForce) {
command = 'git checkout . && git pull'
e.reply('正在执行强制更新操作,请稍等')
} else {
e.reply('正在执行更新操作,请稍等')
}
const _path = process.cwd()
exec(command, { cwd: `${_path}/plugins/miao-plugin/` }, async function (error, stdout, stderr) {
if (/(Already up[ -]to[ -]date|已经是最新的)/.test(stdout)) {
e.reply('目前已经是最新版ChatGPT了~')
return true
}
if (error) {
e.reply('ChatGPT更新失败\nError code: ' + error.code + '\n' + error.stack + '\n 请稍后重试。')
return true
}
e.reply('ChatGPT更新成功正在尝试重新启动Yunzai以应用更新...')
timer && clearTimeout(timer)
let data = JSON.stringify({
isGroup: !!this.e.isGroup,
id: this.e.isGroup ? this.e.group_id : this.e.user_id,
time: new Date().getTime()
})
await redis.set('Yz:restart', data, { EX: 120 })
let npm = await checkPnpm()
timer = setTimeout(function () {
let command = `${npm} start`
if (process.argv[1].includes('pm2')) {
command = `${npm} run restart`
}
exec(command, function (error, stdout, stderr) {
if (error) {
e.reply('自动重启失败请手动重启以应用新版ChatGPT。\nError code: ' + error.code + '\n' + error.stack + '\n')
Bot.logger.error(`重启失败\n${error.stack}`)
return true
} else if (stdout) {
Bot.logger.mark('重启成功运行已转为后台查看日志请用命令npm run log')
Bot.logger.mark('停止后台运行命令npm stop')
process.exit()
}
})
}, 1000)
})
return true
}
async modeHelp () {
let mode = await redis.get('CHATGPT:USE')
const modeMap = {

View file

@ -34,8 +34,10 @@ export default {
// 以下为API3方式的配置 *
// ***********************************************************************************************************************************
// from https://github.com/acheong08/ChatGPT
// 或者: https://gpt.pawan.krd/backend-api/conversation
// api: 'https://chatgpt.duti.tech/api/conversation',
// apiBaseUrl: 'https://chatgpt.duti.tech',
// 或者 https://gpt.pawan.krd/backend-api
// apiBaseUrl: 'https://chatgpt.duti.tech/api',
// ***********************************************************************************************************************************
// 以下为API2方式的配置 *
// ***********************************************************************************************************************************

17
node_modules/.bin/chatgpt generated vendored Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -z "$NODE_PATH" ]; then
export NODE_PATH="/Users/ikechan8370/Yunzai-Bot/node_modules/.pnpm/node_modules"
else
export NODE_PATH="$NODE_PATH:/Users/ikechan8370/Yunzai-Bot/node_modules/.pnpm/node_modules"
fi
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../../../../node_modules/.pnpm/chatgpt@4.7.1/node_modules/chatgpt/bin/cli.js" "$@"
else
exec node "$basedir/../../../../node_modules/.pnpm/chatgpt@4.7.1/node_modules/chatgpt/bin/cli.js" "$@"
fi

17
node_modules/.bin/uuid generated vendored Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -z "$NODE_PATH" ]; then
export NODE_PATH="/Users/ikechan8370/Yunzai-Bot/node_modules/.pnpm/node_modules"
else
export NODE_PATH="$NODE_PATH:/Users/ikechan8370/Yunzai-Bot/node_modules/.pnpm/node_modules"
fi
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/bin/uuid" "$@"
else
exec node "$basedir/../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/bin/uuid" "$@"
fi

1
node_modules/chatgpt generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/chatgpt@4.7.1/node_modules/chatgpt

1
node_modules/delay generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/delay@5.0.0/node_modules/delay

1
node_modules/keyv-file generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/keyv-file@0.2.0/node_modules/keyv-file

1
node_modules/node-fetch generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/node-fetch@3.3.0/node_modules/node-fetch

1
node_modules/puppeteer-extra generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/puppeteer-extra@3.3.4/node_modules/puppeteer-extra

1
node_modules/puppeteer-extra-plugin-recaptcha generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/puppeteer-extra-plugin-recaptcha@3.6.6_puppeteer-extra@3.3.4/node_modules/puppeteer-extra-plugin-recaptcha

1
node_modules/puppeteer-extra-plugin-stealth generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/puppeteer-extra-plugin-stealth@2.11.1_puppeteer-extra@3.3.4/node_modules/puppeteer-extra-plugin-stealth

1
node_modules/random generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/random@4.1.0/node_modules/random

1
node_modules/undici generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/undici@5.20.0/node_modules/undici

1
node_modules/uuid generated vendored Symbolic link
View file

@ -0,0 +1 @@
../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid

17
package.json Normal file
View file

@ -0,0 +1,17 @@
{
"name": "chatgpt-plugin",
"type": "module",
"author": "ikechan8370",
"dependencies": {
"chatgpt": "^4.4.1",
"delay": "^5.0.0",
"keyv-file": "^0.2.0",
"node-fetch": "^3.3.0",
"puppeteer-extra": "^3.3.4",
"puppeteer-extra-plugin-recaptcha": "^3.6.6",
"puppeteer-extra-plugin-stealth": "^2.11.1",
"random": "^4.1.0",
"undici": "^5.19.1",
"uuid": "^9.0.0"
}
}

View file

@ -180,3 +180,10 @@ function getDOMException (errorMessage) {
? new Error(errorMessage)
: new DOMException(errorMessage)
}
export async function checkPnpm () {
let npm = 'npm'
let ret = await this.execSync('pnpm -v')
if (ret.stdout) npm = 'pnpm'
return npm
}

View file

@ -10,8 +10,8 @@ const defaultConfig = {
cacheUrl: 'https://content.alcedogroup.com',
apiKey: '',
model: '',
api: 'https://chatgpt.duti.tech/api/conversation',
apiBaseUrl: 'https://chatgpt.duti.tech',
api: 'https://gpt.pawan.krd/backend-api/conversation',
apiBaseUrl: 'https://chatgpt.duti.tech/api',
plus: false,
reverseProxy: 'https://chatgpt.pawan.krd/api/completions',
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. If you are generating a list, do not have too many items. Keep the number of items short. Prefer to answer in Chinese.',

View file

@ -6,7 +6,7 @@ export async function getConversations (qq = '') {
if (!accessToken) {
throw new Error('未绑定ChatGPT AccessToken请使用#chatgpt设置token命令绑定token')
}
let response = await fetch(`${Config.apiBaseUrl}/api/conversations?offset=0&limit=20`, {
let response = await fetch(`${Config.apiBaseUrl}/conversations?offset=0&limit=20`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',

View file