所以我正在编写一些与 chatgpt3 一起使用的 python 代码。它的作用是发送带有提示的请求,然后获取回复,但我不断收到错误。错误是
Traceback (most recent call last):
File "main.py", line 16, in <module>
print(response_json['choices'][0]['text'])
KeyError: 'choices'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
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'])
Run Code Online (Sandbox Code Playgroud)
我确实有一个有效的 API 密钥和 JSON 代码,但我没有得到 JSON 代码。
{'error': {'message': 'Cannot specify both model and engine', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Run Code Online (Sandbox Code Playgroud)
我尝试过不同的 API 密钥,但没有成功。我什至查找了 chatgpt 的所有不同型号,但它仍然不起作用