summaryrefslogtreecommitdiffstats
path: root/g4f/requests
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-10 14:23:30 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-10 14:23:30 +0200
commit65bcc8ae8bfc435b302be7cad0f4f87961154646 (patch)
tree0f65dde345aa2b6d0d87b5caf78169b6357761e1 /g4f/requests
parentAdd OpenRouter and DeepInfraImage Provider (#1814) (diff)
downloadgpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar.gz
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar.bz2
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar.lz
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar.xz
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.tar.zst
gpt4free-65bcc8ae8bfc435b302be7cad0f4f87961154646.zip
Diffstat (limited to 'g4f/requests')
-rw-r--r--g4f/requests/aiohttp.py7
-rw-r--r--g4f/requests/curl_cffi.py18
2 files changed, 20 insertions, 5 deletions
diff --git a/g4f/requests/aiohttp.py b/g4f/requests/aiohttp.py
index 71e7bde7..cdbedef3 100644
--- a/g4f/requests/aiohttp.py
+++ b/g4f/requests/aiohttp.py
@@ -33,9 +33,14 @@ class StreamSession(ClientSession):
**DEFAULT_HEADERS,
**headers
}
+ connect = None
+ if isinstance(timeout, tuple):
+ connect, timeout = timeout;
+ if timeout is not None:
+ timeout = ClientTimeout(timeout, connect)
super().__init__(
**kwargs,
- timeout=ClientTimeout(timeout) if timeout else None,
+ timeout=timeout,
response_class=StreamResponse,
connector=get_connector(connector, proxies.get("all", proxies.get("https"))),
headers=headers
diff --git a/g4f/requests/curl_cffi.py b/g4f/requests/curl_cffi.py
index 91142365..000448fe 100644
--- a/g4f/requests/curl_cffi.py
+++ b/g4f/requests/curl_cffi.py
@@ -1,6 +1,11 @@
from __future__ import annotations
-from curl_cffi.requests import AsyncSession, Response, CurlMime
+from curl_cffi.requests import AsyncSession, Response
+try:
+ from curl_cffi.requests import CurlMime
+ has_curl_mime = True
+except ImportError:
+ has_curl_mime = False
from typing import AsyncGenerator, Any
from functools import partialmethod
import json
@@ -78,6 +83,11 @@ class StreamSession(AsyncSession):
patch = partialmethod(request, "PATCH")
delete = partialmethod(request, "DELETE")
-class FormData(CurlMime):
- def add_field(self, name, data=None, content_type: str = None, filename: str = None) -> None:
- self.addpart(name, content_type=content_type, filename=filename, data=data) \ No newline at end of file
+if has_curl_mime:
+ class FormData(CurlMime):
+ def add_field(self, name, data=None, content_type: str = None, filename: str = None) -> None:
+ self.addpart(name, content_type=content_type, filename=filename, data=data)
+else:
+ class FormData():
+ def __init__(self) -> None:
+ raise RuntimeError("CurlMimi in curl_cffi is missing | pip install -U g4f[curl_cffi]") \ No newline at end of file