ChatGPT-3 OpenAI API错误:"Unknown endpoint for this model."

qxsslcnc  于 2023-03-03  发布在  其他
关注(0)|答案(2)|浏览(5770)

我刚开始使用API。我发现自己对新的OpenAI产品GPT-3很感兴趣(我知道,它并不是那么新。但我刚刚才发现它)。我试图在Python中使用API密钥,但似乎密钥无效。
这是我的代码(我不能把我的API密钥放在这里,原因很明显):

import requests 
prompt = 'Tell me the history of Europe in summary'
model = 'davinci'
url = 'https://api.openai.com/v1/engines/davinci/jobs'

headers = {
    'content-type': 'application/json',
    'Authorization': 'Bearer MY_API_KEY',
}

data = {
    'prompt': prompt,
    'max-tokens': 100,
    'temperature': 0.5,
}

response = requests.post(url,headers=headers, json=data)
response_json = response.json()
print(response_json)

我不断收到此错误:{'error': {'message': 'Unknown endpoint for this model.', 'type': 'invalid_request_error', 'param': None, 'code': None}}
我已尝试使用新的API金钥数次,但仍然无效。我怎样才能找出金钥无效的原因?

46scxncf

46scxncf1#

所有Engines endpoints都已弃用。

这是正确的Completions endpoint

https://api.openai.com/v1/completions

工作示例

如果您运行test.py,OpenAI API将返回以下完成:
这的确是一个考验

    • 测试. py**
import json
import requests

data = {
    'prompt': 'Say this is a test',
    'model': 'text-davinci-003',
    'max_tokens': 7,
    'temperature': 0
}

response = requests.post('https://api.openai.com/v1/completions', json=data, headers={
    'Content-Type': 'application/json',
    'Authorization': f'Bearer <OPENAI_API_KEY>'
})

response_json = json.loads(response.text)

print(response_json['choices'][0]['text'])
    • 编辑**

如果出现以下错误:

{'error': {'message': 'You exceeded your current quota, please check your plan and billing details.', 'type': 'insufficient_quota', 'param': None, 'code': None}

您可能已经花光了所有的免费点数。正如官方OpenAI article所述:

    • 为了探索和试验API,所有新用户都可以免费获得价值18美元的免费令牌。这些令牌将在3个月后过期。**

超过配额后,您可以选择输入billing information以升级到付费计划,并继续以现收现付方式使用API。如果未输入帐单信息,您仍将具有登录访问权限,但将无法进行任何进一步的API请求。
请参阅pricing页面,了解现收现付定价的最新信息。

5vf7fwbs

5vf7fwbs2#

OpenAI有一个python实现,我建议你去看看。

import os
import openai

openai.api_key = "MY_API_KEY"

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Tell me the history of Europe in summary",
  temperature=0,
  max_tokens=100,
  top_p=1,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\n"]
)

你会更好地使用他们的python包。

相关问题