fix: 优化新引入的依赖安装提示;dalle支持proxy

This commit is contained in:
ikechan8370 2023-03-04 01:10:29 +08:00
parent 49bbb5ceb8
commit a5c0db099d
3 changed files with 468 additions and 404 deletions

View file

@ -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)