英文:
How do I make an API call to GPT-3 correctly?
问题
我正在尝试调用GPT-3的API,但我收到了一个错误(Bad request 400)。以下是我的代码:
url = "https://api.openai.com/v1/engines/gpt-3/jobs"
headers = {
"Content-Type": "application/json",
"Authorization": "sk-apikey"
}
data = {
"model": "text-davinci-002",
"prompt": "Correct this to standard English : Who are you",
"max_tokens": 60
}
response = requests.post(url, headers=headers, data=json.dumps(data))
英文:
I am trying to make an API call to GPT-3 but I am getting an error (Bad request 400). Here is my code:
url = "https://api.openai.com/v1/engines/gpt-3/jobs"
headers = {
"Content-Type": "application/json",
"Authorization": "sk-apikey"
}
data = {
"model": "text-davinci-002",
"prompt": "Correct this to standard English : Who are you",
"max_tokens": 60
}
response = requests.post(url, headers=headers, data=json.dumps(data))
答案1
得分: 1
尝试更改URL并修复授权标头...
url = "https://api.openai.com/v1/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"model": "text-davinci-002",
"prompt": "将其更正为标准英语:你是谁\n",
"max_tokens": 60
}
response = requests.post(url, headers=headers, data=json.dumps(data))
response.json()
英文:
Try changing the url and fixing the Authorization header...
url = "https://api.openai.com/v1/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"model": "text-davinci-002",
"prompt": "Correct this to standard English : Who are you \n",
"max_tokens": 60
}
response = requests.post(url, headers=headers, data=json.dumps(data))
response.json()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论