Using a function to call get for a relational graph

Hey friends, currently trying to utilize the API for the first time and I keep getting an error with this:

Response content: {‘error’: {‘message’: ‘Unrecognized request argument supplied: prompt’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

I am using python and trying to call gpt in order to get relationships between words from a text file I have. This is the python code I have to call get

def call_gpt_api(api_key, prompt_text):
    global API_ENDPOINT
    try:
        data = {
            "model": "gpt-3.5-turbo",
            "messages": [{"role": "user", "content": "Say this is a test!"}],
            "prompt": prompt_text,
            "max_tokens": 3000,
            "stop": "\n",
            "temperature": 0
        }
        headers = {"Content-Type": "application/json", "Authorization": "Bearer " + api_key}
        r = requests.post(url=API_ENDPOINT, headers=headers, json=data)
        response_data = r.json()  # Parse the response as JSON
        print("Response content:", response_data)
        return response_data
    except Exception as e:
        print("Error:", e)

I am just curious if this is correct for making the api request? Keep getting an error as listed above. Thanks!

Hi!

Nope!

If you go to the playground, top right, you’ll see “show code” - where it will give you a bunch of examples you can select from

since you’re using requests, you can use the curl example as reference:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "hello hello!"
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}'
1 Like

Thank you so much! That was exactly the direction I was looking for. api has been changing a good bit lately

1 Like