mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
19 lines
510 B
JavaScript
19 lines
510 B
JavaScript
import { Configuration, OpenAIApi } from 'openai'
|
|
import { Config } from './config.js'
|
|
|
|
export async function createImage (prompt, n = 1, size = '512x512') {
|
|
const configuration = new Configuration({
|
|
apiKey: Config.apiKey
|
|
})
|
|
const openai = new OpenAIApi(configuration)
|
|
if (Config.debug) {
|
|
logger.info({ prompt, n, size })
|
|
}
|
|
const response = await openai.createImage({
|
|
prompt,
|
|
n,
|
|
size,
|
|
response_format: 'b64_json'
|
|
})
|
|
return response.data.data?.map(pic => pic.b64_json)
|
|
}
|