mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-24 03:23:49 +03:00
Add rate limit error messages
This commit is contained in:
parent
13b496afd5
commit
78f93bb737
@ -41,7 +41,10 @@ class FreeGpt(AsyncGeneratorProvider):
|
||||
async with session.post(f"{url}/api/generate", json=data) as response:
|
||||
response.raise_for_status()
|
||||
async for chunk in response.iter_content():
|
||||
yield chunk.decode()
|
||||
chunk = chunk.decode()
|
||||
if chunk == "当前地区当日额度已消耗完":
|
||||
raise RuntimeError("Rate limit reached")
|
||||
yield chunk
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
|
@ -61,6 +61,8 @@ class NoowAi(AsyncGeneratorProvider):
|
||||
yield line["data"]
|
||||
elif line["type"] == "end":
|
||||
break
|
||||
elif line["type"] == "error":
|
||||
raise RuntimeError(line["data"])
|
||||
|
||||
def random_string(length: int = 10):
|
||||
return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length))
|
Loading…
Reference in New Issue
Block a user