Add rate limit error messages

This commit is contained in:
Heiner Lohaus 2023-10-22 15:15:43 +02:00
parent 13b496afd5
commit 78f93bb737
2 changed files with 6 additions and 1 deletions

View File

@ -41,7 +41,10 @@ class FreeGpt(AsyncGeneratorProvider):
async with session.post(f"{url}/api/generate", json=data) as response: async with session.post(f"{url}/api/generate", json=data) as response:
response.raise_for_status() response.raise_for_status()
async for chunk in response.iter_content(): async for chunk in response.iter_content():
yield chunk.decode() chunk = chunk.decode()
if chunk == "当前地区当日额度已消耗完":
raise RuntimeError("Rate limit reached")
yield chunk
@classmethod @classmethod
@property @property

View File

@ -61,6 +61,8 @@ class NoowAi(AsyncGeneratorProvider):
yield line["data"] yield line["data"]
elif line["type"] == "end": elif line["type"] == "end":
break break
elif line["type"] == "error":
raise RuntimeError(line["data"])
def random_string(length: int = 10): def random_string(length: int = 10):
return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length)) return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length))