mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-25 12:16:17 +03:00
Update FreeGpt.py
This commit is contained in:
parent
8229b62ce3
commit
ce92e598a0
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
import time, hashlib, random
|
import time, hashlib, random
|
||||||
|
|
||||||
from ..typing import AsyncResult, Messages
|
from ..typing import AsyncResult, Messages
|
||||||
from ..requests import StreamSession
|
from ..requests import StreamSession, raise_for_status
|
||||||
from .base_provider import AsyncGeneratorProvider
|
from .base_provider import AsyncGeneratorProvider
|
||||||
from ..errors import RateLimitError
|
from ..errors import RateLimitError
|
||||||
|
|
||||||
@ -29,9 +29,9 @@ class FreeGpt(AsyncGeneratorProvider):
|
|||||||
**kwargs
|
**kwargs
|
||||||
) -> AsyncResult:
|
) -> AsyncResult:
|
||||||
async with StreamSession(
|
async with StreamSession(
|
||||||
impersonate="chrome107",
|
impersonate="chrome",
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
proxies={"https": proxy}
|
proxies={"all": proxy}
|
||||||
) as session:
|
) as session:
|
||||||
prompt = messages[-1]["content"]
|
prompt = messages[-1]["content"]
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
@ -43,9 +43,9 @@ class FreeGpt(AsyncGeneratorProvider):
|
|||||||
}
|
}
|
||||||
domain = random.choice(domains)
|
domain = random.choice(domains)
|
||||||
async with session.post(f"{domain}/api/generate", json=data) as response:
|
async with session.post(f"{domain}/api/generate", json=data) as response:
|
||||||
response.raise_for_status()
|
await raise_for_status(response)
|
||||||
async for chunk in response.iter_content():
|
async for chunk in response.iter_content():
|
||||||
chunk = chunk.decode()
|
chunk = chunk.decode(errors="ignore")
|
||||||
if chunk == "当前地区当日额度已消耗完":
|
if chunk == "当前地区当日额度已消耗完":
|
||||||
raise RateLimitError("Rate limit reached")
|
raise RateLimitError("Rate limit reached")
|
||||||
yield chunk
|
yield chunk
|
||||||
|
Loading…
Reference in New Issue
Block a user