Created
December 31, 2022 00:56
-
-
Save JenniferFuBook/2759c3c6aca7a12bde03f7a05147cc7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from 'next' | |
import { Configuration, OpenAIApi, ImagesResponseDataInner } from 'openai'; | |
import { createReadStream } from 'fs'; | |
const configuration = new Configuration({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); | |
const openai = new OpenAIApi(configuration); | |
type Data = { | |
result: ImagesResponseDataInner[], | |
} | |
export default async function handler( | |
req: NextApiRequest, | |
res: NextApiResponse<Data> | |
) { | |
const {fileName, maskFileName, prompt, n, size} = req.body; | |
const result = await openai.createImageEdit( | |
createReadStream(fileName) as unknown as File, | |
createReadStream(maskFileName) as unknown as File, | |
prompt, | |
n, | |
size, | |
); | |
res.status(200).json({ result: result.data.data }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment