{ console.log("OpenAI Chatbot Post-6ren">
gpt4 book ai didi

axios - OpenAI ChatGPT (GPT-3.5) API 错误 : "openai.createChatCompletion is not a function"

转载 作者:行者123 更新时间:2023-12-02 05:46:45 29 4
gpt4 key购买 nike

我的 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 });
}
};

当我更改API请求时,使用新的API来完成聊天,这个不起作用(API代码来自openAI网站,并且适用于postman)


exports.chatbot = async (req, res) => {
console.log("OpenAI Chatbot Post");

const { textInput } = req.body;

try {
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: textInput }],
});
console.log(completion.data.choices[0].message);

if (completion.data) {
if (completion.data.choices[0].message) {
return res.status(200).json(completion.data.choices[0].message);
}
}

} catch (err) {
return res.status(404).json({ message: err.message });
}
};

错误信息:

POST http://localhost:3000/api/openai/chatbot 404(未找到)

最佳答案

您需要升级OpenAI软件包。

Python:

pip install --upgrade openai

NodeJS:

npm 更新 openai

关闭终端并再次打开。运行代码。错误应该消失。

关于axios - OpenAI ChatGPT (GPT-3.5) API 错误 : "openai.createChatCompletion is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75622285/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com