summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-24 00:46:35 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-24 00:46:35 +0100
commit69ef224f92fcec3335a857305191678b886651e1 (patch)
treee2eb38fc678c68fa75b06631880172d164a9c7e7 /g4f/Provider/helper.py
parentAdd aiohttp_socks support (diff)
downloadgpt4free-69ef224f92fcec3335a857305191678b886651e1.tar
gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.gz
gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.bz2
gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.lz
gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.xz
gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.zst
gpt4free-69ef224f92fcec3335a857305191678b886651e1.zip
Diffstat (limited to 'g4f/Provider/helper.py')
-rw-r--r--g4f/Provider/helper.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py
index fce1ee6f..cf204e39 100644
--- a/g4f/Provider/helper.py
+++ b/g4f/Provider/helper.py
@@ -6,13 +6,15 @@ import random
import secrets
import string
from asyncio import AbstractEventLoop, BaseEventLoop
+from aiohttp import BaseConnector
from platformdirs import user_config_dir
from browser_cookie3 import (
chrome, chromium, opera, opera_gx,
brave, edge, vivaldi, firefox,
_LinuxPasswordManager, BrowserCookieError
)
-from ..typing import Dict, Messages
+from ..typing import Dict, Messages, Optional
+from ..errors import AiohttpSocksError
from .. import debug
# Global variable to store cookies
@@ -147,4 +149,13 @@ def get_random_hex() -> str:
Returns:
str: A random hexadecimal string of 32 characters (16 bytes).
"""
- return secrets.token_hex(16).zfill(32) \ No newline at end of file
+ return secrets.token_hex(16).zfill(32)
+
+def get_connector(connector: BaseConnector = None, proxy: str = None) -> Optional[BaseConnector]:
+ if proxy and not connector:
+ try:
+ from aiohttp_socks import ProxyConnector
+ connector = ProxyConnector.from_url(proxy)
+ except ImportError:
+ raise AiohttpSocksError('Install "aiohttp_socks" package for proxy support')
+ return connector \ No newline at end of file