Home  >  Q&A  >  body text

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

<p>Does this method in node.js no longer work? Because then it worked fine but now it doesn't work anymore and also this code is based on their official documentation which is https://platform.openai.com/docs/api-reference/completions/create</ p> <p><strong>My server-side code: </strong></p> <pre class="brush:js;toolbar:false;"> 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 }); //.... </pre> <p><strong>Data I am trying to send: </strong></p> <pre class="brush:json;toolbar:false;">{ "prompt": [ { "role": "bot", "content": "Something went wrong." }, { "role": "user", "content": "What is wrong?" } ] } </pre> <p><strong>I encountered this error: </strong> | The output of the message prompt is in the terminal, in case you want to check if I'm sending the correct message prompt. </p> <p>I also tried adding the organization ID but still didn't work, also tried updating it from v3.2.1 to v3.3.0 but it didn't work at all. I still have a balance in my account. </p>
P粉546138344P粉546138344384 days ago490

reply all(1)I'll reply

  • P粉267791326

    P粉2677913262023-09-02 00:12:30

    Problem solved, I sent the wrong character instead of the bot, it was supposed to be the assistant. So this format will get everything back to normal:

    {
      "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 are only 4 roles: system, user, assistant or function

    reply
    0
  • Cancelreply