mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 优化https-proxy-agent依赖缺失的提示
This commit is contained in:
parent
a5c0db099d
commit
55910dda96
1 changed files with 13 additions and 6 deletions
|
|
@ -10,7 +10,13 @@ if (Config.proxy) {
|
|||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
|
||||
function getProxy() {
|
||||
if (proxy) {
|
||||
return proxy
|
||||
} else {
|
||||
throw new Error('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
export async function createImage (prompt, n = 1, size = '512x512') {
|
||||
const configuration = new Configuration({
|
||||
apiKey: Config.apiKey
|
||||
|
|
@ -19,13 +25,14 @@ export async function createImage (prompt, n = 1, size = '512x512') {
|
|||
if (Config.debug) {
|
||||
logger.info({ prompt, n, size })
|
||||
}
|
||||
let proxyFn = getProxy()
|
||||
const response = await openai.createImage({
|
||||
prompt,
|
||||
n,
|
||||
size,
|
||||
response_format: 'b64_json'
|
||||
}, {
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
httpsAgent: Config.proxy ? proxyFn(Config.proxy) : null
|
||||
})
|
||||
return response.data.data?.map(pic => pic.b64_json)
|
||||
}
|
||||
|
|
@ -49,7 +56,7 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') {
|
|||
|
||||
let croppedFileLoc = `data/chatgpt/imagesAccept/${Date.now()}_cropped.png`
|
||||
await resizeAndCropImage(fileLoc, croppedFileLoc, 512)
|
||||
|
||||
let proxyFn = getProxy()
|
||||
const response = await openai.createImageVariation(
|
||||
fs.createReadStream(croppedFileLoc),
|
||||
n,
|
||||
|
|
@ -57,7 +64,7 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') {
|
|||
'b64_json',
|
||||
'',
|
||||
{
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
httpsAgent: Config.proxy ? proxyFn(Config.proxy) : null
|
||||
}
|
||||
)
|
||||
if (response.status !== 200) {
|
||||
|
|
@ -114,7 +121,7 @@ export async function editImage (originalImage, mask = [], prompt, num = 1, size
|
|||
const arrayBuffer = await blob.arrayBuffer()
|
||||
const buffer = Buffer.from(arrayBuffer)
|
||||
await fs.writeFileSync(fileLoc, buffer)
|
||||
|
||||
let proxyFn = getProxy()
|
||||
let croppedFileLoc = `data/chatgpt/imagesAccept/${Date.now()}_cropped.png`
|
||||
await resizeAndCropImage(fileLoc, croppedFileLoc, 512)
|
||||
let maskFileLoc = await createMask(croppedFileLoc, mask)
|
||||
|
|
@ -127,7 +134,7 @@ export async function editImage (originalImage, mask = [], prompt, num = 1, size
|
|||
'b64_json',
|
||||
'',
|
||||
{
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
httpsAgent: Config.proxy ? proxyFn(Config.proxy) : null
|
||||
}
|
||||
)
|
||||
if (response.status !== 200) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue