javascript - OpenAI gpt-3.5-turbo : Request failed with status code 400

标签 javascript node.js openai-api chatgpt-api gpt-3

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

我遇到了这种错误: enter image description here | 消息提示的输出位于终端中,以防您想检查我是否发送了正确的消息提示。

我还尝试添加组织 ID,但仍然不起作用,也尝试将其从 v3.2.1 更新到 v3.3.0,但根本不起作用。我的账户里还有余额。

最佳答案

问题已解决,我发送了错误的 Angular 色而不是机器人,它应该是助理。所以这种格式将使一切恢复正常:

{
  "prompt": [
    {
      "role": "assistant",
      "content": "Something went wrong."
    },
    {
      "role": "user",
      "content": "What is wrong?"
    }
  ]
}

enter image description here

基于https://platform.openai.com/docs/api-reference/chat/create只有 4 个 Angular 色:systemuserassistantfunction

enter image description here

关于javascript - OpenAI gpt-3.5-turbo : Request failed with status code 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76603485/

相关文章:

javascript - 简单的html5+javascript游戏闪烁

JavaScript 通过属性删除对象数组中的元素

javascript - 首先显示 Div,然后在表单中第二次单击按钮时提交

javascript - Net.Socket 实例不会在 NodeJS 中消失

node.js - AWS node.js 自动重试失败的 batchWrite()

openai-api - GPT3 插入完成 - 无效参数 :suffix

node.js - 没有得到 openAI model 的任何回应。给出错误 : Request failed with status code 429

Javascript编码打破和组合多字节字符?

javascript - 套接字远程端口代表什么?

node.js - OpenAI 嵌入 API : How to change the embedding output dimension?