mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
feat: support dalle api
This commit is contained in:
parent
47976f2325
commit
8c9c098e25
5 changed files with 81 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ export function escapeHtml (str) {
|
|||
return str.replace(/[&<>"'/]/g, (match) => htmlEntities[match])
|
||||
}
|
||||
|
||||
export function randomString(length = 5) {
|
||||
export function randomString (length = 5) {
|
||||
let str = ''
|
||||
for (let i = 0; i < length; i++) {
|
||||
str += lodash.random(36).toString(36)
|
||||
|
|
|
|||
19
utils/dalle.js
Normal file
19
utils/dalle.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue