我尝试使用 openAI api 构建 chatgpt 克隆,但我在 api 的响应 paylaod 中收到 404 错误代码。我尝试了多种选择,但没有找到任何解决方案。
这是我的后端代码:
app.get('/', async (req, res) => {
res.status(200).send({
message: ' Hello'
})
})
app.post('/chat', async (req, res) => {
try {
const prompt = req.body.prompt;
console.log('prompt', prompt);
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `${prompt}`,
temperature: 0.9,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0
});
console.log('Request to OpenAI:', {
model: "text-davinci-003",
prompt: `${prompt}`,
temperature: 0.9,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0
});
console.log('Response from OpenAI:', response);
res.status(200).send({
bot: response.data.choices[0].text
});
} catch (error) {
console.log('hello', error);
res.status(500).send(error || "Something Went Wrong");
}
});
app.listen(5000, () => {
console.log("Server is running")
}) ```
The code is running till console.log('propmt' , prompt) but throws error at the response. I have checked documentation and didn't found any solutions.I guess there might be issue with the way i have declared response.
Note: Im using "openai": "^3.3.0".
首先,上面关于 Completions API 已弃用的评论是错误。 Completions API 仍在工作,但它的某些模型已被弃用。
text-davinci-003
已于 2024 年 1 月 4 日弃用。将 text-davinci-003
替换为 gpt-3.5-turbo-instruct
。