summaryrefslogtreecommitdiffstats
path: root/g4f/requests/aiohttp.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
commite5b7f72b719814ffa2748e8e8ed1c6713a24e1a6 (patch)
tree70e9f87cb18f165428492d53a1c6e28c0828490a /g4f/requests/aiohttp.py
parentUpdate docs / readme, Improve Gemini auth (diff)
downloadgpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.gz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.bz2
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.lz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.xz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.zst
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.zip
Diffstat (limited to 'g4f/requests/aiohttp.py')
-rw-r--r--g4f/requests/aiohttp.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/g4f/requests/aiohttp.py b/g4f/requests/aiohttp.py
new file mode 100644
index 00000000..d9bd6541
--- /dev/null
+++ b/g4f/requests/aiohttp.py
@@ -0,0 +1,30 @@
+from __future__ import annotations
+
+from aiohttp import ClientSession, ClientResponse, ClientTimeout
+from typing import AsyncGenerator, Any
+
+from ..providers.helper import get_connector
+from .defaults import DEFAULT_HEADERS
+
+class StreamResponse(ClientResponse):
+ async def iter_lines(self) -> AsyncGenerator[bytes, None]:
+ async for line in self.content:
+ yield line.rstrip(b"\r\n")
+
+ async def json(self) -> Any:
+ return await super().json(content_type=None)
+
+class StreamSession(ClientSession):
+ def __init__(self, headers: dict = {}, timeout: int = None, proxies: dict = {}, impersonate = None, **kwargs):
+ if impersonate:
+ headers = {
+ **DEFAULT_HEADERS,
+ **headers
+ }
+ super().__init__(
+ **kwargs,
+ timeout=ClientTimeout(timeout) if timeout else None,
+ response_class=StreamResponse,
+ connector=get_connector(kwargs.get("connector"), proxies.get("https")),
+ headers=headers
+ ) \ No newline at end of file