summaryrefslogtreecommitdiffstats
path: root/g4f/requests/curl_cffi.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-15 14:55:53 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-15 14:55:53 +0100
commitb7eee50930dbd782d7c068d1d29cd270b97bc741 (patch)
treebdaa4377a62352cf2641c67a6bc21f903b5c0ea1 /g4f/requests/curl_cffi.py
parentAdd Pyinstaller support, Use curl_cffi in You provider (diff)
downloadgpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar.gz
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar.bz2
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar.lz
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar.xz
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.tar.zst
gpt4free-b7eee50930dbd782d7c068d1d29cd270b97bc741.zip
Diffstat (limited to 'g4f/requests/curl_cffi.py')
-rw-r--r--g4f/requests/curl_cffi.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/g4f/requests/curl_cffi.py b/g4f/requests/curl_cffi.py
index cfcdd63b..91142365 100644
--- a/g4f/requests/curl_cffi.py
+++ b/g4f/requests/curl_cffi.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from curl_cffi.requests import AsyncSession, Response
+from curl_cffi.requests import AsyncSession, Response, CurlMime
from typing import AsyncGenerator, Any
from functools import partialmethod
import json
@@ -65,6 +65,8 @@ class StreamSession(AsyncSession):
def request(
self, method: str, url: str, **kwargs
) -> StreamResponse:
+ if isinstance(kwargs.get("data"), CurlMime):
+ kwargs["multipart"] = kwargs.pop("data")
"""Create and return a StreamResponse object for the given HTTP request."""
return StreamResponse(super().request(method, url, stream=True, **kwargs))
@@ -75,3 +77,7 @@ class StreamSession(AsyncSession):
put = partialmethod(request, "PUT")
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