mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-09-12 08:29:30 -04: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:
|
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
|
||||||
|
@ -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))
|
Loading…
Reference in New Issue
Block a user