So I'm working on some python code that works with chatgpt3. What it does is it sends a request with a prompt and then gets the reply, but I keep getting Errors. The error is
Traceback (most recent call last):
File "main.py", line 16, in <module>
print(response_json['choices'][0]['text'])
KeyError: 'choices'
Here is my code:
import json
import requests
import os
data = {
"prompt": "What is the meaning of life?",
"model": "text-davinci-002"
}
response = requests.post("https://api.openai.com/v1/engines/davinci/completions", json=data, headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {apikey}",
})
response_json = json.loads(response.text)
print(response_json['choices'][0]['text'])
I do have an API key that is valid and the JSON code I don't get the JSON code.
{'error': {'message': 'Cannot specify both model and engine', 'type': 'invalid_request_error', 'param': None, 'code': None}}
I have tried different API keys and that didn't work. i even looked up all the different models for chatgpt and it still doesn't work