mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 优化新引入的依赖安装提示;dalle支持proxy
This commit is contained in:
parent
49bbb5ceb8
commit
a5c0db099d
3 changed files with 468 additions and 404 deletions
|
|
@ -2,6 +2,14 @@ import { Configuration, OpenAIApi } from 'openai'
|
|||
import { Config } from './config.js'
|
||||
import fs from 'fs'
|
||||
import { 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')
|
||||
}
|
||||
}
|
||||
|
||||
export async function createImage (prompt, n = 1, size = '512x512') {
|
||||
const configuration = new Configuration({
|
||||
|
|
@ -16,6 +24,8 @@ export async function createImage (prompt, n = 1, size = '512x512') {
|
|||
n,
|
||||
size,
|
||||
response_format: 'b64_json'
|
||||
}, {
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
})
|
||||
return response.data.data?.map(pic => pic.b64_json)
|
||||
}
|
||||
|
|
@ -44,7 +54,11 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') {
|
|||
fs.createReadStream(croppedFileLoc),
|
||||
n,
|
||||
size,
|
||||
'b64_json'
|
||||
'b64_json',
|
||||
'',
|
||||
{
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
}
|
||||
)
|
||||
if (response.status !== 200) {
|
||||
console.log(response.data.error)
|
||||
|
|
@ -110,7 +124,11 @@ export async function editImage (originalImage, mask = [], prompt, num = 1, size
|
|||
prompt,
|
||||
num,
|
||||
size,
|
||||
'b64_json'
|
||||
'b64_json',
|
||||
'',
|
||||
{
|
||||
httpsAgent: Config.proxy ? proxy(Config.proxy) : null
|
||||
}
|
||||
)
|
||||
if (response.status !== 200) {
|
||||
console.log(response.data.error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue