mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-23 17:23:57 +03:00
a28bab9387
Fix preview for uploaded and generated images in gui Improve typing, readme
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
from aiohttp import ClientSession, ClientResponse, ClientTimeout
|
|
from typing import AsyncGenerator, Any
|
|
|
|
from .Provider.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
|
|
) |