mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 调整对高版本HttpsProxyAgent支持的一个错误
This commit is contained in:
parent
9c172e9e4b
commit
4ffc6c1a32
1 changed files with 18 additions and 15 deletions
|
|
@ -21,7 +21,9 @@ if (!globalThis.fetch) {
|
||||||
// workaround for ver 7.x and ver 5.x
|
// workaround for ver 7.x and ver 5.x
|
||||||
let proxy = HttpsProxyAgent
|
let proxy = HttpsProxyAgent
|
||||||
if (typeof proxy !== 'function') {
|
if (typeof proxy !== 'function') {
|
||||||
proxy = HttpsProxyAgent.HttpsProxyAgent
|
proxy = (p) => {
|
||||||
|
return new HttpsProxyAgent.HttpsProxyAgent(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getKeyv () {
|
async function getKeyv () {
|
||||||
|
|
@ -41,7 +43,7 @@ async function getKeyv () {
|
||||||
const genRanHex = (size) => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
|
const genRanHex = (size) => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
|
||||||
|
|
||||||
export default class SydneyAIClient {
|
export default class SydneyAIClient {
|
||||||
constructor(opts) {
|
constructor (opts) {
|
||||||
this.opts = {
|
this.opts = {
|
||||||
...opts,
|
...opts,
|
||||||
host: opts.host || Config.sydneyReverseProxy || 'https://edgeservices.bing.com/edgesvc'
|
host: opts.host || Config.sydneyReverseProxy || 'https://edgeservices.bing.com/edgesvc'
|
||||||
|
|
@ -52,7 +54,7 @@ export default class SydneyAIClient {
|
||||||
this.debug = opts.debug
|
this.debug = opts.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
async initCache() {
|
async initCache () {
|
||||||
if (!this.conversationsCache) {
|
if (!this.conversationsCache) {
|
||||||
const cacheOptions = this.opts.cache || {}
|
const cacheOptions = this.opts.cache || {}
|
||||||
cacheOptions.namespace = cacheOptions.namespace || 'bing'
|
cacheOptions.namespace = cacheOptions.namespace || 'bing'
|
||||||
|
|
@ -61,7 +63,7 @@ export default class SydneyAIClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createNewConversation() {
|
async createNewConversation () {
|
||||||
await this.initCache()
|
await this.initCache()
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -126,7 +128,7 @@ export default class SydneyAIClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createWebSocketConnection() {
|
async createWebSocketConnection () {
|
||||||
await this.initCache()
|
await this.initCache()
|
||||||
// let WebSocket = await getWebSocket()
|
// let WebSocket = await getWebSocket()
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
@ -190,13 +192,13 @@ export default class SydneyAIClient {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanupWebSocketConnection(ws) {
|
async cleanupWebSocketConnection (ws) {
|
||||||
clearInterval(ws.bingPingInterval)
|
clearInterval(ws.bingPingInterval)
|
||||||
ws.close()
|
ws.close()
|
||||||
ws.removeAllListeners()
|
ws.removeAllListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMessage(
|
async sendMessage (
|
||||||
message,
|
message,
|
||||||
opts = {}
|
opts = {}
|
||||||
) {
|
) {
|
||||||
|
|
@ -572,9 +574,9 @@ export default class SydneyAIClient {
|
||||||
const message = messages.length
|
const message = messages.length
|
||||||
? messages[messages.length - 1]
|
? messages[messages.length - 1]
|
||||||
: {
|
: {
|
||||||
adaptiveCards: adaptiveCardsSoFar,
|
adaptiveCards: adaptiveCardsSoFar,
|
||||||
text: replySoFar.join('')
|
text: replySoFar.join('')
|
||||||
}
|
}
|
||||||
if (messages[0].contentOrigin === 'Apology') {
|
if (messages[0].contentOrigin === 'Apology') {
|
||||||
console.log('Apology found')
|
console.log('Apology found')
|
||||||
if (!replySoFar[0]) {
|
if (!replySoFar[0]) {
|
||||||
|
|
@ -639,9 +641,9 @@ export default class SydneyAIClient {
|
||||||
const message = messages.length
|
const message = messages.length
|
||||||
? messages[messages.length - 1]
|
? messages[messages.length - 1]
|
||||||
: {
|
: {
|
||||||
adaptiveCards: adaptiveCardsSoFar,
|
adaptiveCards: adaptiveCardsSoFar,
|
||||||
text: replySoFar.join('')
|
text: replySoFar.join('')
|
||||||
}
|
}
|
||||||
// 获取到图片内容
|
// 获取到图片内容
|
||||||
if (message.contentType === 'IMAGE') {
|
if (message.contentType === 'IMAGE') {
|
||||||
message.imageTag = messages.filter(m => m.contentType === 'IMAGE').map(m => m.text).join('')
|
message.imageTag = messages.filter(m => m.contentType === 'IMAGE').map(m => m.text).join('')
|
||||||
|
|
@ -807,6 +809,7 @@ export default class SydneyAIClient {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate through messages, building an array based on the parentMessageId.
|
* Iterate through messages, building an array based on the parentMessageId.
|
||||||
* Each message has an id and a parentMessageId. The parentMessageId is the id of the message that this message is a reply to.
|
* Each message has an id and a parentMessageId. The parentMessageId is the id of the message that this message is a reply to.
|
||||||
|
|
@ -814,7 +817,7 @@ export default class SydneyAIClient {
|
||||||
* @param parentMessageId
|
* @param parentMessageId
|
||||||
* @returns {*[]} An array containing the messages in the order they should be displayed, starting with the root message.
|
* @returns {*[]} An array containing the messages in the order they should be displayed, starting with the root message.
|
||||||
*/
|
*/
|
||||||
static getMessagesForConversation(messages, parentMessageId) {
|
static getMessagesForConversation (messages, parentMessageId) {
|
||||||
const orderedMessages = []
|
const orderedMessages = []
|
||||||
let currentMessageId = parentMessageId
|
let currentMessageId = parentMessageId
|
||||||
while (currentMessageId) {
|
while (currentMessageId) {
|
||||||
|
|
@ -830,7 +833,7 @@ export default class SydneyAIClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateRandomIP() {
|
async function generateRandomIP () {
|
||||||
let ip = await redis.get('CHATGPT:BING_IP')
|
let ip = await redis.get('CHATGPT:BING_IP')
|
||||||
if (ip) {
|
if (ip) {
|
||||||
return ip
|
return ip
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue