-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: comment code in route for build purpose
- Loading branch information
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { Configuration, OpenAIApi } from 'openai'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
// import { Configuration, OpenAIApi } from 'openai'; | ||
// import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const configuration = new Configuration({ | ||
apiKey: process.env.OPENAI_API_KEY | ||
}); | ||
// const configuration = new Configuration({ | ||
// apiKey: process.env.OPENAI_API_KEY | ||
// }); | ||
|
||
const openai = new OpenAIApi(configuration); | ||
// const openai = new OpenAIApi(configuration); | ||
|
||
type DataResponse = { | ||
text: string; | ||
}; | ||
// type DataResponse = { | ||
// text: string; | ||
// }; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<DataResponse> | ||
) { | ||
if (req.method === 'POST') { | ||
const prompt = req.body.text; | ||
const response = await openai.createCompletion({ | ||
model: 'text-davinci-003', | ||
prompt: prompt, | ||
max_tokens: 60 | ||
}); | ||
// export default async function handler( | ||
// req: NextApiRequest, | ||
// res: NextApiResponse<DataResponse> | ||
// ) { | ||
// if (req.method === 'POST') { | ||
// const prompt = req.body.text; | ||
// const response = await openai.createCompletion({ | ||
// model: 'text-davinci-003', | ||
// prompt: prompt, | ||
// max_tokens: 60 | ||
// }); | ||
|
||
res | ||
.status(200) | ||
.json({ text: (response.data.choices[0].text || '').trim() }); | ||
} else { | ||
res.setHeader('Allow', 'POST'); | ||
res.status(405).end('Method Not Allowed'); | ||
} | ||
} | ||
// res | ||
// .status(200) | ||
// .json({ text: (response.data.choices[0].text || '').trim() }); | ||
// } else { | ||
// res.setHeader('Allow', 'POST'); | ||
// res.status(405).end('Method Not Allowed'); | ||
// } | ||
// } |