我的 MERN 堆栈代码文件中有这个,并且运行良好。
exports.chatbot = async (req, res) => {
console.log("OpenAI Chatbot Post");
const { textInput } = req.body;
try {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `
What is your name?
My name is Chatbot.
How old are you?
I am 900 years old.
${textInput}`,
max_tokens: 100,
temperature: 0,
});
if (response.data) {
if (response.data.choices[0].text) {
return res.status(200).json(response.data.choices[0].text);
}
}
} catch (err) {
return res.status(404).json({ message: err.message });
}
};
Run Code Online (Sandbox Code Playgroud)
当我更改API请求时,使用新的API来完成聊天,这个不起作用(API代码来自openAI网站,并且适用于postman)
exports.chatbot = async (req, res) …Run Code Online (Sandbox Code Playgroud)