summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-19 20:45:25 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-19 20:45:25 +0100
commit275404373f73cbae7835590c66dbe230155d77f9 (patch)
tree7dd083571e2396a627dfd468f21af8402cc39f2d
parentAdd image upload to Copilot provider (diff)
downloadgpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar.gz
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar.bz2
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar.lz
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar.xz
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.tar.zst
gpt4free-275404373f73cbae7835590c66dbe230155d77f9.zip
-rw-r--r--g4f/cookies.py1
-rw-r--r--g4f/requests/__init__.py19
2 files changed, 19 insertions, 1 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py
index a43ccc86..0c62d697 100644
--- a/g4f/cookies.py
+++ b/g4f/cookies.py
@@ -40,6 +40,7 @@ try:
has_browser_cookie3 = True
except ImportError:
has_browser_cookie3 = False
+ browsers = []
from .typing import Dict, Cookies
from .errors import MissingRequirementsError
diff --git a/g4f/requests/__init__.py b/g4f/requests/__init__.py
index 89e0b4ea..2e576d19 100644
--- a/g4f/requests/__init__.py
+++ b/g4f/requests/__init__.py
@@ -20,9 +20,15 @@ except ImportError:
try:
import nodriver
from nodriver.cdp.network import CookieParam
+ from nodriver import Browser
has_nodriver = True
except ImportError:
has_nodriver = False
+try:
+ from platformdirs import user_config_dir
+ has_platformdirs = True
+except ImportError:
+ has_platformdirs = False
from .. import debug
from .raise_for_status import raise_for_status
@@ -165,4 +171,15 @@ def merge_cookies(cookies: Iterator[Morsel], response: Response) -> Cookies:
if cookies is None:
cookies = {}
for cookie in response.cookies.jar:
- cookies[cookie.name] = cookie.value \ No newline at end of file
+ cookies[cookie.name] = cookie.value
+
+async def get_nodriver(proxy: str = None, **kwargs)-> Browser:
+ if not has_nodriver:
+ raise MissingRequirementsError('Install "nodriver" package | pip install -U nodriver')
+ user_data_dir = user_config_dir("g4f-nodriver") if has_platformdirs else None
+ debug.log(f"Copilot: Open nodriver with user_dir: {user_data_dir}")
+ return await nodriver.start(
+ user_data_dir=user_data_dir,
+ browser_args=None if proxy is None else [f"--proxy-server={proxy}"],
+ **kwargs
+ ) \ No newline at end of file