返回提交历史
Modified
g4f/Provider/FreeGpt.py
+5
-5
XFEstudio/gpt4free
Update FreeGpt.py
ce92e598
代码差异
1 个文件
+5
-5
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
import time, hashlib, random
4
4
5
5
from ..typing import AsyncResult, Messages
6
from ..requests import StreamSession
6
from ..requests import StreamSession, raise_for_status
7
7
from .base_provider import AsyncGeneratorProvider
8
8
from ..errors import RateLimitError
9
9
@@ -29,9 +29,9 @@ class FreeGpt(AsyncGeneratorProvider):
29
29
**kwargs
30
30
) -> AsyncResult:
31
31
async with StreamSession(
32
impersonate="chrome107",
32
impersonate="chrome",
33
33
timeout=timeout,
34
proxies={"https": proxy}
34
proxies={"all": proxy}
35
35
) as session:
36
36
prompt = messages[-1]["content"]
37
37
timestamp = int(time.time())
@@ -43,9 +43,9 @@ class FreeGpt(AsyncGeneratorProvider):
43
43
}
44
44
domain = random.choice(domains)
45
45
async with session.post(f"{domain}/api/generate", json=data) as response:
46
response.raise_for_status()
46
await raise_for_status(response)
47
47
async for chunk in response.iter_content():
48
chunk = chunk.decode()
48
chunk = chunk.decode(errors="ignore")
49
49
if chunk == "当前地区当日额度已消耗完":
50
50
raise RateLimitError("Rate limit reached")
51
51
yield chunk