I am creating a chat with AI GPT, but I'm getting an error 505 (HTTP Version Not Supported) when trying to use the following code:
router.post("/text", async (req, res) => {
try {
const { text, activeChatId } = req.body;
console.log("req.body", req.body);
const response = await openai.createCompletion({ // this line seems to be the cause of the problem
model: "text-davinci-003",
prompt: text,
temperature: 0.5,
max_tokens: 2048,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});
await axios.post(
`https://api.chatengine.io/chats/${activeChatId}/messages/`,
{ text: response.data.choices[0].text },
{
headers: {
"Project-ID": process.env.PROJECT_ID,
"User-Name": process.env.BOT_USER_NAME,
"User-Secret": process.env.BOT_USER_SECRET,
},
}
);
res.status(200).json({ text: response.data.choices[0].text });
} catch (error) {
res.status(505).json({ error: error.message });
}
});
Upon checking, req.body
seems to be receiving data, but response.data
is not. In the console, the headers show "505 HTTP Version Not Supported," while the response shows {"error":"Request failed with status code 429"}
. I am inexperienced in programming and would appreciate help solving this issue.
Here is a screenshot of the error message: https://i.stack.imgur.com/qlMJB.png