与 OpenAI API 通信时出现 RateLimitingError

问题描述 投票:0回答:1

我是 ChatGPT OpenAI API 的新手,并尝试使用这个小 python 脚本启动并运行它:

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
  ]
)

print(completion.choices[0].message)

但是脚本给了我以下错误:

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

我的配额是 5 美元,对于这个简单的提示来说已经足够了。这是代码问题,还是我应该简单地将积分添加到我的 OpenAI 帐户?

python chatgpt-api
1个回答
0
投票

根据速率限制,有5种速率限制:

  • RPM(每分钟请求数)
  • RPD(每日请求数)
  • TPM(每分钟令牌数)
  • TPD(每天代币)
  • IPM(每分钟图像数)

就您而言,您可以点击

RPM
RPD
。您可以检查标题中的速率限制或您的帐户页面来确认这一点。

您可以使用此Python代码(src):

raw_response = client.chat.completions.with_raw_response.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
  ]
)

chat_completion = raw_response.parse()
response_headers = raw_response.headers
print(response_headers)
© www.soinside.com 2019 - 2024. All rights reserved.