summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-11-16 21:48:26 +0100
committerGitHub <noreply@github.com>2023-11-16 21:48:26 +0100
commit8393b2bd56b601890ffc27a7c0d93ef7c189a325 (patch)
treea0c1ae03c2df4486067ea9268db16ea68c708102 /g4f/Provider/helper.py
parentMerge pull request #1257 from AndPim4912/ignored-tupo (diff)
parentUpdate Liaobots.py (diff)
downloadgpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar.gz
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar.bz2
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar.lz
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar.xz
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.tar.zst
gpt4free-8393b2bd56b601890ffc27a7c0d93ef7c189a325.zip
Diffstat (limited to 'g4f/Provider/helper.py')
-rw-r--r--g4f/Provider/helper.py63
1 files changed, 55 insertions, 8 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py
index 519a024a..cad32f05 100644
--- a/g4f/Provider/helper.py
+++ b/g4f/Provider/helper.py
@@ -3,13 +3,44 @@ from __future__ import annotations
import sys
import asyncio
import webbrowser
-
from os import path
from asyncio import AbstractEventLoop
from platformdirs import user_config_dir
+from browser_cookie3 import (
+ chrome,
+ chromium,
+ opera,
+ opera_gx,
+ brave,
+ edge,
+ vivaldi,
+ firefox,
+ BrowserCookieError
+)
+try:
+ from selenium.webdriver.remote.webdriver import WebDriver
+ except ImportError:
+ class WebDriver():
+ pass
+try:
+ from undetected_chromedriver import Chrome, ChromeOptions
+except ImportError:
+ class Chrome():
+ def __init__():
+ raise RuntimeError('Please install the "undetected_chromedriver" package')
+ class ChromeOptions():
+ def add_argument():
+ pass
+try:
+ from pyvirtualdisplay import Display
+except ImportError:
+ class Display():
+ def start():
+ pass
+ def stop():
+ pass
-from ..typing import Dict, Messages
-from browser_cookie3 import chrome, chromium, opera, opera_gx, brave, edge, vivaldi, firefox, BrowserCookieError
+from ..typing import Dict, Messages, Union, Tuple
from .. import debug
# Change event loop policy on windows
@@ -106,10 +137,26 @@ def format_prompt(messages: Messages, add_special_tokens=False) -> str:
return f"{formatted}\nAssistant:"
-def get_browser(user_data_dir: str = None):
- from undetected_chromedriver import Chrome
-
- if not user_data_dir:
+def get_browser(
+ user_data_dir: str = None,
+ hidden_display: bool = False,
+ proxy: str = None,
+ options: ChromeOptions = None
+) -> Union[Chrome, Tuple[Chrome, Display]] :
+ if user_data_dir == None:
user_data_dir = user_config_dir("g4f")
- return Chrome(user_data_dir=user_data_dir) \ No newline at end of file
+ if hidden_display:
+ display = Display(visible=0, size=(1920, 1080))
+ display.start()
+
+ if proxy:
+ if not options:
+ options = ChromeOptions()
+ options.add_argument(f'--proxy-server={proxy}')
+
+ browser = Chrome(user_data_dir=user_data_dir, options=options)
+ if hidden_display:
+ return browser, display
+
+ return browser \ No newline at end of file