summaryrefslogtreecommitdiffstats
path: root/g4f/requests.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-01 20:29:57 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-01 20:29:57 +0200
commit7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a (patch)
treeb6519bff3c7ee7a37189d67a3247d3db7a316c15 /g4f/requests.py
parentDisable Wewordle Provider (diff)
downloadgpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar.gz
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar.bz2
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar.lz
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar.xz
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.tar.zst
gpt4free-7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a.zip
Diffstat (limited to 'g4f/requests.py')
-rw-r--r--g4f/requests.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/g4f/requests.py b/g4f/requests.py
index 6f4b587c..367bafa0 100644
--- a/g4f/requests.py
+++ b/g4f/requests.py
@@ -8,10 +8,12 @@ from aiohttp.base_protocol import BaseProtocol
from curl_cffi.requests import AsyncSession as BaseSession
from curl_cffi.requests import Response
-from curl_cffi import AsyncCurl
-is_newer_0_5_9 = hasattr(AsyncCurl, "remove_handle")
-is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies")
+import curl_cffi
+
+is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl")
+is_newer_0_5_9 = hasattr(curl_cffi.AsyncCurl, "remove_handle")
+is_newer_0_5_10 = hasattr(BaseSession, "release_curl")
class StreamResponse:
def __init__(self, inner: Response, content: StreamReader, request):
@@ -65,13 +67,22 @@ class StreamRequest:
async def __aenter__(self) -> StreamResponse:
self.curl = await self.session.pop_curl()
self.enter = self.loop.create_future()
- request, _, header_buffer = self.session._set_curl_options(
- self.curl,
- self.method,
- self.url,
- content_callback=self.on_content,
- **self.options
- )
+ if is_newer_0_5_10:
+ request, _, header_buffer, _, _ = self.session._set_curl_options(
+ self.curl,
+ self.method,
+ self.url,
+ content_callback=self.on_content,
+ **self.options
+ )
+ else:
+ request, _, header_buffer = self.session._set_curl_options(
+ self.curl,
+ self.method,
+ self.url,
+ content_callback=self.on_content,
+ **self.options
+ )
if is_newer_0_5_9:
self.handle = self.session.acurl.add_handle(self.curl)
else: