英文:
OpenAI gpt-3.5-turbo: Request failed with status code 400
问题
这个Node.js方法不再起作用吗?因为以前它运行正常,但现在不再起作用,而且这段代码也是基于他们的官方文档的,文档链接在这里:https://platform.openai.com/docs/api-reference/completions/create
我的服务器端代码:
import { Configuration, OpenAIApi } from 'openai';
//....
const configuration = new Configuration({
apiKey: API_KEY,
});
//....
const openai = new OpenAIApi(configuration);
//....
const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: `You are a helpful assistant.`
},
...prompt
],
temperature: 0.2,
max_tokens: 1500,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
//....
res.status(200).send({
bot: response.data.choices[0].message.content
});
//....
我要发送的数据:
{
"prompt": [
{
"role": "bot",
"content": "Something went wrong."
},
{
"role": "user",
"content": "What is wrong?"
}
]
}
我得到了这种错误:
|
在终端中,消息提示的输出是为了检查我是否发送了正确的消息提示。
我还尝试添加组织ID,但仍然不起作用,还尝试从v3.2.1更新到v3.3.0,什么都不起作用。我的账户中仍然有余额。
英文:
does this method in node.js doesn't work anymore? Because back then it was working fine but now it doesn't work anymore and also this code is also based on their official docs which is this https://platform.openai.com/docs/api-reference/completions/create
My server end code:
import { Configuration, OpenAIApi } from 'openai';
//....
const configuration = new Configuration({
apiKey: API_KEY,
});
//....
const openai = new OpenAIApi(configuration);
//....
const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: `You are a helpful assistant.` },
...prompt
],
temperature: 0.2,
max_tokens: 1500,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
//....
res.status(200).send({
bot: response.data.choices[0].message.content
});
//....
The data I am trying to send:
{
"prompt": [
{
"role": "bot",
"content": "Something went wrong."
},
{
"role": "user",
"content": "What is wrong?"
}
]
}
i am getting this kind of error:
|
The output of the message prompt is in the terminal just incase you want to check if i am sending correct message prompt.
I also tried adding the org id and still didn't work and also tried updating it from v3.2.1 to v3.3.0 nothing works at all. I still have balance in the account.
答案1
得分: 1
问题已解决,我发送了一个错误的角色,而不是机器人,它应该是助手。所以这个格式将使一切恢复正常:
{
"prompt": [
{
"role": "assistant",
"content": "Something went wrong."
},
{
"role": "user",
"content": "What is wrong?"
}
]
}
根据https://platform.openai.com/docs/api-reference/chat/create,只有4种角色:system
、user
、assistant
或function
。
英文:
The issue solved, I was sending a wrong role instead of bot it should be assistant. So this format will make everything work again:
{
"prompt": [
{
"role": "assistant",
"content": "Something went wrong."
},
{
"role": "user",
"content": "What is wrong?"
}
]
}
Based on https://platform.openai.com/docs/api-reference/chat/create there is only 4 roles: system
, user
, assistant
, or function
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论