summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-24 01:05:29 +0100
committerGitHub <noreply@github.com>2024-01-24 01:05:29 +0100
commit71d71b6512df12d6295c1f8323eb056edd89c57f (patch)
treedb88f2c8237b51519401e077df059b71f41e6404 /g4f/Provider/helper.py
parentMerge pull request #1509 from hlohaus/sort (diff)
parentAdd get_connector helper (diff)
downloadgpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar.gz
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar.bz2
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar.lz
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar.xz
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.tar.zst
gpt4free-71d71b6512df12d6295c1f8323eb056edd89c57f.zip
Diffstat (limited to '')
-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