如何正确地发起对GPT-3的API调用?

huangapple go评论57阅读模式
英文:

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()

huangapple
  • 本文由 发表于 2023年2月6日 21:09:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定