import requests
api_key = "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"
prompt = 'User message goes here'
response = requests.post(
'https://api.openai.com/v1/engines/davinci-codex/completions',
headers={'Authorization': f'Bearer {api_key}'},
json={'prompt': prompt, 'max_tokens': 50} # Adjust max_tokens as needed
)
data = response.json()
chatgpt_response = data['choices'][0]['text']
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[1], line 13
6 response = requests.post(
7 'https://api.openai.com/v1/engines/davinci-codex/completions',
8 headers={'Authorization': f'Bearer {api_key}'},
9 json={'prompt': prompt, 'max_tokens': 50} # Adjust max_tokens as needed
10 )
12 data = response.json()
---> 13 chatgpt_response = data['choices'][0]['text']
KeyError: 'choices'