fix: use openai_compat layer for error handling

The code was directly importing openai.error which fails with openai>=1.0.
The project already has an openai_compat.py compatibility layer that handles
both old (<1.0) and new (>=1.0) OpenAI SDK versions.

This commit updates chat_gpt_bot.py to use the compatibility layer.

Related: #2687
This commit is contained in:
JasonOA888
2026-03-10 00:33:45 +08:00
parent 71c8436e90
commit f1e888f3de
2 changed files with 2 additions and 2 deletions

0
0 Normal file
View File

View File

@@ -4,7 +4,7 @@ import time
import json
import openai
import openai.error
from models.openai.openai_compat import error as openai_error, RateLimitError, Timeout, APIError, APIConnectionError
import requests
from common import const
from models.bot import Bot
@@ -229,7 +229,7 @@ class ChatGPTBot(Bot, OpenAIImage, OpenAICompatibleBot):
"""
try:
if conf().get("rate_limit_chatgpt") and not self.tb4chatgpt.get_token():
raise openai.error.RateLimitError("RateLimitError: rate limit exceeded")
raise RateLimitError("RateLimitError: rate limit exceeded")
# if api_key == None, the default openai.api_key will be used
if args is None:
args = self.args