SOLVED! - Formatting problems (Invalid Request Error)

Hello! I’m really new to this, and for the life of me I cannot figure out the proper formatting of the JSON request to send in. I’ve utilized OpenAI Playground to set up exactly what I need, but then it comes back with an error, saying “Unrecognized request argument supplied: messages”

I can’t figure out what I’m supposed to do. The farthest I’ve been able to get is by changing the word “messages” in the code to “prompt”, which gives an error saying “‘$.prompt’ is invalid”

I’ve attached my code at the bottom of the post, is anyone able to help me properly format this JSON file? Neither me, or GPT 3.5 can figure out what the proper formatting is for multiple messages. I just want to be able to send a prompt successfully. Any help is appreciated.

Code:

{
  "messages": [
    {
      "role": "system",
      "content": "You are a chatbot AI named Iris. You were designed to respond with interesting and comedic responses, responding the same way a human would, and insuring the user can chat for as long as possible."
    },
    {
      "role": "user",
      "content": "Hey, how's your day?"
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}

I believe you are calling the wrong endpoint

Update your endpoint to:

https://api.openai.com/v1/chat/completions

If you’re using the Python library:

openai.ChatCompletion.create(

I’m guessing this is what you are using:

openai.Completion.create(

Or… If you are giving GPT the wheel

requests.post("https://api.openai.com/v1/completions"

1 Like

That. Was my problem. Thank you.

I’m using C# and Unity, trying to utilize GPT to mainly take the wheel to set things up. Eventually it stopped improving things and began repeating code that didn’t work, so I tried here. Thank god.

The link it kept giving me as the endpoint was this:
https://api.openai.com/v1/engines/davinci/completions

Thank you so much!! I’m finally past the big roadblock I ran into

1 Like

Sounds like a fun project! No problem. Happy coding

1 Like

The problem is that the JSON doesn’t specify the model. A simple addition:


create = {
  "messages": [
    {
      "role": "system",
      "content": "You are a chatbot AI named Iris. You were designed to respond with interesting and comedic responses, responding the same way a human would, and insuring the user can chat for as long as possible."
    },
    {
      "role": "user",
      "content": "Hey, how's your day?"
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "model": "gpt-3.5-turbo"
}

If you are using that with the python API library, you’ll pass the whole json as a parameter, different than API reference examples:

openai_object = openai.ChatCompletion.create(**create)
openai_data = json.loads(str(openai_object))

The second line gets the response into a native Python data structure instead of an object. (You would use a different method for streaming out of a generator object when stream=True).