summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/selenium
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/selenium')
-rw-r--r--g4f/Provider/selenium/AItianhuSpace.py116
-rw-r--r--g4f/Provider/selenium/Bard.py80
-rw-r--r--g4f/Provider/selenium/MyShell.py4
-rw-r--r--g4f/Provider/selenium/PerplexityAi.py4
-rw-r--r--g4f/Provider/selenium/TalkAi.py4
-rw-r--r--g4f/Provider/selenium/__init__.py2
6 files changed, 6 insertions, 204 deletions
diff --git a/g4f/Provider/selenium/AItianhuSpace.py b/g4f/Provider/selenium/AItianhuSpace.py
deleted file mode 100644
index 4c438e3b..00000000
--- a/g4f/Provider/selenium/AItianhuSpace.py
+++ /dev/null
@@ -1,116 +0,0 @@
-from __future__ import annotations
-
-import time
-import random
-
-from ...typing import CreateResult, Messages
-from ..base_provider import AbstractProvider
-from ..helper import format_prompt, get_random_string
-from ...webdriver import WebDriver, WebDriverSession, element_send_text
-from ... import debug
-
-class AItianhuSpace(AbstractProvider):
- url = "https://chat3.aiyunos.top/"
- working = True
- supports_stream = True
- supports_gpt_35_turbo = True
- _domains = ["aitianhu.com", "aitianhu1.top"]
-
- @classmethod
- def create_completion(
- cls,
- model: str,
- messages: Messages,
- stream: bool,
- domain: str = None,
- proxy: str = None,
- timeout: int = 120,
- webdriver: WebDriver = None,
- headless: bool = True,
- **kwargs
- ) -> CreateResult:
- if not model:
- model = "gpt-3.5-turbo"
- if not domain:
- rand = get_random_string(6)
- domain = random.choice(cls._domains)
- domain = f"{rand}.{domain}"
- if debug.logging:
- print(f"AItianhuSpace | using domain: {domain}")
- url = f"https://{domain}"
- prompt = format_prompt(messages)
-
- with WebDriverSession(webdriver, "", headless=headless, proxy=proxy) as driver:
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
-
- wait = WebDriverWait(driver, timeout)
-
- # Bypass devtools detection
- driver.get("https://blank.page/")
- wait.until(EC.visibility_of_element_located((By.ID, "sheet")))
- driver.execute_script(f"""
- document.getElementById('sheet').addEventListener('click', () => {{
- window.open(arguments[0]);
- }});
- """, url)
- driver.find_element(By.ID, "sheet").click()
- time.sleep(10)
-
- original_window = driver.current_window_handle
- for window_handle in driver.window_handles:
- if window_handle != original_window:
- driver.close()
- driver.switch_to.window(window_handle)
- break
-
- # Wait for page load
- wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "textarea.n-input__textarea-el")))
-
- # Register hook in XMLHttpRequest
- script = """
-const _http_request_open = XMLHttpRequest.prototype.open;
-window._last_message = window._message = "";
-window._loadend = false;
-XMLHttpRequest.prototype.open = function(method, url) {
- if (url == "/api/chat-process") {
- this.addEventListener("progress", (event) => {
- const lines = this.responseText.split("\\n");
- try {
- window._message = JSON.parse(lines[lines.length-1])["text"];
- } catch(e) { }
- });
- this.addEventListener("loadend", (event) => {
- window._loadend = true;
- });
- }
- return _http_request_open.call(this, method, url);
-}
-"""
- driver.execute_script(script)
-
- # Submit prompt
- element_send_text(driver.find_element(By.CSS_SELECTOR, "textarea.n-input__textarea-el"), prompt)
-
- # Read response
- while True:
- chunk = driver.execute_script("""
-if (window._message && window._message != window._last_message) {
- try {
- return window._message.substring(window._last_message.length);
- } finally {
- window._last_message = window._message;
- }
-}
-if (window._loadend) {
- return null;
-}
-return "";
-""")
- if chunk:
- yield chunk
- elif chunk != "":
- break
- else:
- time.sleep(0.1) \ No newline at end of file
diff --git a/g4f/Provider/selenium/Bard.py b/g4f/Provider/selenium/Bard.py
deleted file mode 100644
index 9c809128..00000000
--- a/g4f/Provider/selenium/Bard.py
+++ /dev/null
@@ -1,80 +0,0 @@
-from __future__ import annotations
-
-import time
-import os
-
-try:
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
-except ImportError:
- pass
-
-from ...typing import CreateResult, Messages
-from ..base_provider import AbstractProvider
-from ..helper import format_prompt
-from ...webdriver import WebDriver, WebDriverSession, element_send_text
-
-
-class Bard(AbstractProvider):
- url = "https://bard.google.com"
- working = False
- needs_auth = True
- webdriver = True
-
- @classmethod
- def create_completion(
- cls,
- model: str,
- messages: Messages,
- stream: bool,
- proxy: str = None,
- webdriver: WebDriver = None,
- user_data_dir: str = None,
- headless: bool = True,
- **kwargs
- ) -> CreateResult:
- prompt = format_prompt(messages)
- session = WebDriverSession(webdriver, user_data_dir, headless, proxy=proxy)
- with session as driver:
- try:
- driver.get(f"{cls.url}/chat")
- wait = WebDriverWait(driver, 10 if headless else 240)
- wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")))
- except:
- # Reopen browser for login
- if not webdriver:
- driver = session.reopen()
- driver.get(f"{cls.url}/chat")
- login_url = os.environ.get("G4F_LOGIN_URL")
- if login_url:
- yield f"Please login: [Google Bard]({login_url})\n\n"
- wait = WebDriverWait(driver, 240)
- wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ql-editor.textarea")))
- else:
- raise RuntimeError("Prompt textarea not found. You may not be logged in.")
-
- # Add hook in XMLHttpRequest
- script = """
-const _http_request_open = XMLHttpRequest.prototype.open;
-window._message = "";
-XMLHttpRequest.prototype.open = function(method, url) {
- if (url.includes("/assistant.lamda.BardFrontendService/StreamGenerate")) {
- this.addEventListener("load", (event) => {
- window._message = JSON.parse(JSON.parse(this.responseText.split("\\n")[3])[0][2])[4][0][1][0];
- });
- }
- return _http_request_open.call(this, method, url);
-}
-"""
- driver.execute_script(script)
-
- element_send_text(driver.find_element(By.CSS_SELECTOR, "div.ql-editor.textarea"), prompt)
-
- while True:
- chunk = driver.execute_script("return window._message;")
- if chunk:
- yield chunk
- return
- else:
- time.sleep(0.1) \ No newline at end of file
diff --git a/g4f/Provider/selenium/MyShell.py b/g4f/Provider/selenium/MyShell.py
index a3f246ff..02e182d4 100644
--- a/g4f/Provider/selenium/MyShell.py
+++ b/g4f/Provider/selenium/MyShell.py
@@ -9,7 +9,7 @@ from ...webdriver import WebDriver, WebDriverSession, bypass_cloudflare
class MyShell(AbstractProvider):
url = "https://app.myshell.ai/chat"
- working = True
+ working = False
supports_gpt_35_turbo = True
supports_stream = True
@@ -73,4 +73,4 @@ return content;
elif chunk != "":
break
else:
- time.sleep(0.1) \ No newline at end of file
+ time.sleep(0.1)
diff --git a/g4f/Provider/selenium/PerplexityAi.py b/g4f/Provider/selenium/PerplexityAi.py
index 6b529d5b..d965dbf7 100644
--- a/g4f/Provider/selenium/PerplexityAi.py
+++ b/g4f/Provider/selenium/PerplexityAi.py
@@ -16,7 +16,7 @@ from ...webdriver import WebDriver, WebDriverSession, element_send_text
class PerplexityAi(AbstractProvider):
url = "https://www.perplexity.ai"
- working = True
+ working = False
supports_gpt_35_turbo = True
supports_stream = True
@@ -105,4 +105,4 @@ if(window._message && window._message != window._last_message) {
elif chunk != "":
break
else:
- time.sleep(0.1) \ No newline at end of file
+ time.sleep(0.1)
diff --git a/g4f/Provider/selenium/TalkAi.py b/g4f/Provider/selenium/TalkAi.py
index 89280598..a7b63375 100644
--- a/g4f/Provider/selenium/TalkAi.py
+++ b/g4f/Provider/selenium/TalkAi.py
@@ -8,7 +8,7 @@ from ...webdriver import WebDriver, WebDriverSession
class TalkAi(AbstractProvider):
url = "https://talkai.info"
- working = True
+ working = False
supports_gpt_35_turbo = True
supports_stream = True
@@ -83,4 +83,4 @@ return content;
elif chunk != "":
break
else:
- time.sleep(0.1) \ No newline at end of file
+ time.sleep(0.1)
diff --git a/g4f/Provider/selenium/__init__.py b/g4f/Provider/selenium/__init__.py
index 9a020460..3a59ea58 100644
--- a/g4f/Provider/selenium/__init__.py
+++ b/g4f/Provider/selenium/__init__.py
@@ -1,6 +1,4 @@
-from .AItianhuSpace import AItianhuSpace
from .MyShell import MyShell
from .PerplexityAi import PerplexityAi
from .Phind import Phind
from .TalkAi import TalkAi
-from .Bard import Bard \ No newline at end of file