Last active
December 30, 2022 18:37
-
-
Save JenniferFuBook/edff440e06a95e0688e02a18239b91fc 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, n, size} = req.body; | |
const result = await openai.createImageVariation( | |
createReadStream(fileName) as unknown as File, | |
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