Skip to content

Commit

Permalink
fix: comment code in route for build purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
HoreKk committed May 6, 2024
1 parent 53f58bb commit 541d53e
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions webapp-next/pages/api/chat.ts
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');
// }
// }

0 comments on commit 541d53e

Please sign in to comment.