* feat: api3 WIP

* feat: add support for proxy of openai

* fix: if no proxy
This commit is contained in:
ikechan8370 2023-02-14 22:54:47 +08:00 committed by GitHub
parent ab021d0caa
commit 62c8d56e76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 115 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import { ChatGPTClient, BingAIClient } from '@waylaidwanderer/chatgpt-api'
import { getMessageById, tryTimes, upsertMessage } from '../utils/common.js'
import { ChatGPTPuppeteer } from '../utils/browser.js'
import { KeyvFile } from 'keyv-file'
import {OfficialChatGPTClient} from "../utils/message.js";
// import puppeteer from '../utils/browser.js'
// import showdownKatex from 'showdown-katex'
const blockWords = Config.blockWords
@ -402,6 +403,18 @@ export class chatgpt extends plugin {
invocationId: response.invocationId,
conversationSignature: response.conversationSignature
}
} else if (use === 'api3') {
// official without cloudflare
let accessToken = await redis.get('CHATGPT:TOKEN')
if (!accessToken) {
throw new Error('未绑定ChatGPT AccessToken请使用#chatgpt设置token命令绑定token')
}
this.chatGPTApi = new OfficialChatGPTClient({
accessToken,
apiReverseUrl: Config.api,
timeoutMs: 120000
})
return await this.chatGPTApi.sendMessage(prompt, conversation)
} else {
let completionParams = {}
if (Config.model) {

View file

@ -43,6 +43,11 @@ export class ChatgptManagement extends plugin {
fnc: 'useReversedAPIBasedSolution',
permission: 'master'
},
{
reg: '^#chatgpt切换API3$',
fnc: 'useReversedAPIBasedSolution2',
permission: 'master'
},
{
reg: '^#chatgpt切换(必应|Bing)$',
fnc: 'useReversedBingSolution',
@ -118,7 +123,12 @@ export class ChatgptManagement extends plugin {
async useReversedAPIBasedSolution (e) {
await redis.set('CHATGPT:USE', 'apiReverse')
await this.reply('已切换到基于第三方Reversed API的解决方案如果已经对话过建议执行`#结束对话`避免引起404错误')
await this.reply('已切换到基于第三方Reversed CompletionAPI的解决方案如果已经对话过建议执行`#结束对话`避免引起404错误')
}
async useReversedAPIBasedSolution2 (e) {
await redis.set('CHATGPT:USE', 'api3')
await this.reply('已切换到基于第三方Reversed ConversastionAPI的解决方案如果已经对话过建议执行`#结束对话`避免引起404错误')
}
async useReversedBingSolution (e) {