OpenAI gpt-3.5-turbo: Request failed with status code 400
P粉546138344
P粉546138344 2023-09-01 12:17:58
0
1
566
<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粉546138344
P粉546138344

reply all(1)
P粉267791326

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代码>

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!