fix: 整理了代理与反代之间的关系

This commit is contained in:
ikechan8370 2023-03-07 16:27:51 +08:00
parent ad9516d370
commit 3ee5a2f3f6
5 changed files with 49 additions and 12 deletions

View file

@ -1,6 +1,5 @@
import { v4 as uuidv4 } from 'uuid'
import { Config } from '../utils/config.js'
import HttpsProxyAgent from 'https-proxy-agent'
import _ from 'lodash'
import fetch from 'node-fetch'
let proxy
@ -11,7 +10,7 @@ if (Config.proxy) {
console.warn('未安装https-proxy-agent请在插件目录下执行pnpm add https-proxy-agent')
}
}
// API3
export class OfficialChatGPTClient {
constructor (opts = {}) {
const {
@ -28,7 +27,6 @@ export class OfficialChatGPTClient {
agent: proxy(Config.proxy)
}
: {}
const mergedOptions = {
...defaultOptions,
...options
@ -50,7 +48,11 @@ export class OfficialChatGPTClient {
if (timeoutMs) {
abortController = new AbortController()
}
const url = this._apiReverseUrl || 'https://chat.openai.com/backend-api/conversation'
let url = this._apiReverseUrl || 'https://chat.openai.com/backend-api/conversation'
if (this._apiReverseUrl && Config.proxy && !Config.apiForceUseReverse) {
// 如果配了proxy而且有反代但是没开启强制反代
url = 'https://chat.openai.com/backend-api/conversation'
}
const body = {
action,
messages: [