OpenAI gpt-3.5-turbo:请求失败,状态码为400

huangapple go评论75阅读模式
英文:

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?"
    }
  ]
}

我得到了这种错误:
OpenAI gpt-3.5-turbo:请求失败,状态码为400|
在终端中,消息提示的输出是为了检查我是否发送了正确的消息提示。

我还尝试添加组织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:
OpenAI gpt-3.5-turbo:请求失败,状态码为400|
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种角色:systemuserassistantfunction

英文:

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?"
    }
  ]
}

OpenAI gpt-3.5-turbo:请求失败,状态码为400

Based on https://platform.openai.com/docs/api-reference/chat/create there is only 4 roles: system, user, assistant, or function

OpenAI gpt-3.5-turbo:请求失败,状态码为400

huangapple
  • 本文由 发表于 2023年7月3日 17:30:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定