mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
Api3 (#149)
* feat: api3 WIP * feat: add support for proxy of openai * fix: if no proxy
This commit is contained in:
parent
ab021d0caa
commit
62c8d56e76
4 changed files with 115 additions and 4 deletions
13
apps/chat.js
13
apps/chat.js
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue