admin 管理员组文章数量: 887021
【Bugs】openai.error.ServiceUnavailableError: The server is overloaded or not ready yet.
@author: SUFEHeisenberg
@date: 2023/07/21
在调用ChatGPT API时报错:
openai.error.ServiceUnavailableError: The server is overloaded or not ready yet.
Solution
利用指数退避的思想:
import openai
from tenacity import (
retry,
stop_after_attempt,
wait_random_exponential,
retry_if_exception_type
) # for exponential backoff
@retry(
retry=retry_if_exception_type((openai.error.APIError, openai.error.APIConnectionError, openai.error.RateLimitError, openai.error.ServiceUnavailableError, openai.error.Timeout)),
wait=wait_random_exponential(multiplier=1, max=60),
stop=stop_after_attempt(10)
)
def chat_completion_with_backoff(**kwargs):
return openai.ChatCompletion.create(**kwargs)
response = chat_completion_with_backoff(
model=model,
messages=[
{"role": "system", "content": system_msg},
{"role": "user", "content": longtext},
],
max_tokens=max_tokens,
)
Reference
https://community.openai/t/openai-error-serviceunavailableerror-the-server-is-overloaded-or-not-ready-yet/32670/20
本文标签: error OpenAI Bugs ServiceUnavailableError Ready
版权声明:本文标题:【Bugs】openai.error.ServiceUnavailableError The server is overloaded or not ready yet 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1724991327h845930.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论