mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
5797d4e90f
15 changed files with 95625 additions and 60868 deletions
|
|
@ -1,17 +1,11 @@
|
|||
import fetch, { FormData } from 'node-fetch'
|
||||
import { makeForwardMsg } from './common.js'
|
||||
import { Config } from './config.js'
|
||||
import { getProxy } from './proxy.js'
|
||||
|
||||
let proxy
|
||||
if (Config.proxy) {
|
||||
try {
|
||||
proxy = (await import('https-proxy-agent')).default
|
||||
} catch (e) {
|
||||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
let proxy = getProxy()
|
||||
export default class BingDrawClient {
|
||||
constructor(opts) {
|
||||
constructor (opts) {
|
||||
this.opts = opts
|
||||
if (Config.proxy && !Config.sydneyForceUseReverse) {
|
||||
// 如果设置代理,走代理
|
||||
|
|
@ -19,7 +13,7 @@ export default class BingDrawClient {
|
|||
}
|
||||
}
|
||||
|
||||
async getImages(prompt, e) {
|
||||
async getImages (prompt, e) {
|
||||
let urlEncodedPrompt = encodeURIComponent(prompt)
|
||||
let url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=4&FORM=GENCRE`
|
||||
// let d = Math.ceil(Math.random() * 255)
|
||||
|
|
@ -82,7 +76,7 @@ export default class BingDrawClient {
|
|||
}
|
||||
}
|
||||
if (!success) {
|
||||
//最后尝试使用https://cn.bing.com进行一次绘图
|
||||
// 最后尝试使用https://cn.bing.com进行一次绘图
|
||||
logger.info('尝试使用https://cn.bing.com进行绘图')
|
||||
url = `https://cn.bing.com/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||
fetchOptions.referrer = 'https://cn.bing.com/images/create/'
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import fetch, {
|
|||
} from 'node-fetch'
|
||||
import crypto from 'crypto'
|
||||
import WebSocket from 'ws'
|
||||
import HttpsProxyAgent from 'https-proxy-agent'
|
||||
import { Config, pureSydneyInstruction } from './config.js'
|
||||
import { formatDate, getMasterQQ, isCN, getUserData } from './common.js'
|
||||
import delay from 'delay'
|
||||
import moment from 'moment'
|
||||
import { getProxy } from './proxy.js'
|
||||
|
||||
if (!globalThis.fetch) {
|
||||
globalThis.fetch = fetch
|
||||
|
|
@ -19,12 +19,7 @@ if (!globalThis.fetch) {
|
|||
globalThis.Response = Response
|
||||
}
|
||||
// workaround for ver 7.x and ver 5.x
|
||||
let proxy = HttpsProxyAgent
|
||||
if (typeof proxy !== 'function') {
|
||||
proxy = (p) => {
|
||||
return new HttpsProxyAgent.HttpsProxyAgent(p)
|
||||
}
|
||||
}
|
||||
let proxy = getProxy()
|
||||
|
||||
async function getKeyv () {
|
||||
let Keyv
|
||||
|
|
|
|||
|
|
@ -103,8 +103,9 @@ export class ClaudeAIClient {
|
|||
// redirect: 'manual'
|
||||
// // referrer: 'https://claude.ai/chat/bba5a67d-ee59-4196-a371-ece8a35db1f2'
|
||||
// })
|
||||
let host = Config.claudeAIReverseProxy || 'https://claude.ai'
|
||||
const cycleTLS = await initCycleTLS()
|
||||
let result = await cycleTLS(`https://claude.ai/api/organizations/${this.organizationId}/chat_conversations`, {
|
||||
let result = await cycleTLS(`${host}/api/organizations/${this.organizationId}/chat_conversations`, {
|
||||
ja3: this.JA3,
|
||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
|
||||
proxy: this.proxy,
|
||||
|
|
@ -140,7 +141,8 @@ export class ClaudeAIClient {
|
|||
timezone: 'Asia/Hong_Kong'
|
||||
}
|
||||
}
|
||||
let url = 'https://claude.ai/api/append_message'
|
||||
let host = Config.claudeAIReverseProxy || 'https://claude.ai'
|
||||
let url = host + '/api/append_message'
|
||||
const cycleTLS = await initCycleTLS()
|
||||
let streamDataRes = await cycleTLS(url, {
|
||||
ja3: this.JA3,
|
||||
|
|
@ -148,36 +150,43 @@ export class ClaudeAIClient {
|
|||
proxy: this.proxy,
|
||||
body: JSON.stringify(body),
|
||||
headers: this.rawHeaders,
|
||||
disableRedirect: true
|
||||
disableRedirect: true,
|
||||
timeout: Config.claudeAITimeout || 120
|
||||
}, 'post')
|
||||
if (streamDataRes.status === 307) {
|
||||
throw new Error('claude.ai目前不支持你所在的地区')
|
||||
}
|
||||
let streamData = streamDataRes.body
|
||||
// console.log(streamData)
|
||||
let responseText = ''
|
||||
let streams = streamData.split('\n\n')
|
||||
for (let s of streams) {
|
||||
let jsonStr = s.replace('data: ', '').trim()
|
||||
try {
|
||||
let jsonObj = JSON.parse(jsonStr)
|
||||
if (jsonObj && jsonObj.completion) {
|
||||
responseText += jsonObj.completion
|
||||
}
|
||||
if (this.debug) {
|
||||
console.log(jsonObj)
|
||||
}
|
||||
// console.log(responseText)
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
if (this.debug) {
|
||||
console.log(jsonStr)
|
||||
if (streamDataRes.status === 200) {
|
||||
let streamData = streamDataRes.body
|
||||
// console.log(streamData)
|
||||
let responseText = ''
|
||||
let streams = streamData.split('\n\n')
|
||||
for (let s of streams) {
|
||||
let jsonStr = s.replace('data: ', '').trim()
|
||||
try {
|
||||
let jsonObj = JSON.parse(jsonStr)
|
||||
if (jsonObj && jsonObj.completion) {
|
||||
responseText += jsonObj.completion
|
||||
}
|
||||
if (this.debug) {
|
||||
console.log(jsonObj)
|
||||
}
|
||||
// console.log(responseText)
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
if (this.debug) {
|
||||
console.log(jsonStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
text: responseText.trim(),
|
||||
conversationId
|
||||
return {
|
||||
text: responseText.trim(),
|
||||
conversationId
|
||||
}
|
||||
} else if (streamDataRes.status === 408) {
|
||||
throw new Error('claude.ai响应超时,可能是回复文本太多,请调高超时时间重试')
|
||||
} else {
|
||||
throw new Error('unknown error')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,9 +148,11 @@ const defaultConfig = {
|
|||
// claude2
|
||||
claudeAIOrganizationId: '',
|
||||
claudeAISessionKey: '',
|
||||
claudeAIReverseProxy: '',
|
||||
claudeAITimeout: 120,
|
||||
claudeAIJA3: '772,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,27-5-65281-13-35-0-51-18-16-43-10-45-11-17513-23,29-23-24,0',
|
||||
claudeAIUA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
|
||||
version: 'v2.7.4'
|
||||
version: 'v2.7.5'
|
||||
}
|
||||
const _path = process.cwd()
|
||||
let config = {}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,8 @@ import { Configuration, OpenAIApi } from 'openai'
|
|||
import { Config, defaultOpenAIAPI, defaultOpenAIReverseProxy } from './config.js'
|
||||
import fs from 'fs'
|
||||
import { isCN, mkdirs } from './common.js'
|
||||
let proxy
|
||||
if (Config.proxy) {
|
||||
try {
|
||||
proxy = (await import('https-proxy-agent')).default
|
||||
} catch (e) {
|
||||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
function getProxy () {
|
||||
if (!Config.proxy || proxy) {
|
||||
return proxy
|
||||
} else {
|
||||
throw new Error('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
import { getProxy } from './proxy.js'
|
||||
let proxy = getProxy()
|
||||
export async function createImage (prompt, n = 1, size = '512x512') {
|
||||
let basePath = Config.openAiBaseUrl
|
||||
if (Config.openAiBaseUrl && Config.proxy && !Config.openAiForceUseReverse) {
|
||||
|
|
@ -34,7 +21,7 @@ export async function createImage (prompt, n = 1, size = '512x512') {
|
|||
if (Config.debug) {
|
||||
logger.info({ prompt, n, size })
|
||||
}
|
||||
let proxyFn = getProxy()
|
||||
let proxyFn = proxy
|
||||
const response = await openai.createImage({
|
||||
prompt,
|
||||
n,
|
||||
|
|
|
|||
17
utils/proxy.js
Normal file
17
utils/proxy.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// workaround for ver 7.x and ver 5.x
|
||||
import HttpsProxyAgent from 'https-proxy-agent'
|
||||
|
||||
let proxy = HttpsProxyAgent
|
||||
if (typeof proxy !== 'function') {
|
||||
proxy = (p) => {
|
||||
return new HttpsProxyAgent.HttpsProxyAgent(p)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return a proxy function
|
||||
* @returns {*|createHttpsProxyAgent|((opts: (string | createHttpsProxyAgent.HttpsProxyAgentOptions)) => HttpsProxyAgent)}
|
||||
*/
|
||||
export function getProxy () {
|
||||
return proxy
|
||||
}
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
import { Config } from './config.js'
|
||||
import { ChatGPTAPI } from 'chatgpt'
|
||||
import fetch from 'node-fetch'
|
||||
let proxy
|
||||
if (Config.proxy) {
|
||||
try {
|
||||
proxy = (await import('https-proxy-agent')).default
|
||||
} catch (e) {
|
||||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
import { getProxy } from './proxy.js'
|
||||
let proxy = getProxy()
|
||||
const newFetch = (url, options = {}) => {
|
||||
const defaultOptions = Config.proxy
|
||||
? {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue