summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/needs_auth
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-27 16:09:21 +0100
committerGitHub <noreply@github.com>2024-01-27 16:09:21 +0100
commit0d83bdeef91001c7c00d69f79fccad5a78b4b94b (patch)
tree362ebeb245cc4e123914635b03f890a314a7a40d /g4f/Provider/needs_auth
parentMerge pull request #1512 from KennyPhan123/patch-1 (diff)
parentFix PerplexityLabs Provider, Improve bypass_cloudflare helper (diff)
downloadgpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar.gz
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar.bz2
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar.lz
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar.xz
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.tar.zst
gpt4free-0d83bdeef91001c7c00d69f79fccad5a78b4b94b.zip
Diffstat (limited to 'g4f/Provider/needs_auth')
-rw-r--r--g4f/Provider/needs_auth/Bard.py12
-rw-r--r--g4f/Provider/needs_auth/OpenaiChat.py10
-rw-r--r--g4f/Provider/needs_auth/Poe.py4
-rw-r--r--g4f/Provider/needs_auth/Theb.py5
4 files changed, 12 insertions, 19 deletions
diff --git a/g4f/Provider/needs_auth/Bard.py b/g4f/Provider/needs_auth/Bard.py
index 09ed1c3c..73c62edc 100644
--- a/g4f/Provider/needs_auth/Bard.py
+++ b/g4f/Provider/needs_auth/Bard.py
@@ -7,14 +7,14 @@ try:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.keys import Keys
except ImportError:
pass
from ...typing import CreateResult, Messages
from ..base_provider import AbstractProvider
from ..helper import format_prompt
-from ...webdriver import WebDriver, WebDriverSession
+from ...webdriver import WebDriver, WebDriverSession, element_send_text
+
class Bard(AbstractProvider):
url = "https://bard.google.com"
@@ -68,13 +68,7 @@ XMLHttpRequest.prototype.open = function(method, url) {
"""
driver.execute_script(script)
- textarea = driver.find_element(By.CSS_SELECTOR, "div.ql-editor.textarea")
- lines = prompt.splitlines()
- for idx, line in enumerate(lines):
- textarea.send_keys(line)
- if (len(lines) - 1 != idx):
- textarea.send_keys(Keys.SHIFT + "\n")
- textarea.send_keys(Keys.ENTER)
+ element_send_text(driver.find_element(By.CSS_SELECTOR, "div.ql-editor.textarea"), prompt)
while True:
chunk = driver.execute_script("return window._message;")
diff --git a/g4f/Provider/needs_auth/OpenaiChat.py b/g4f/Provider/needs_auth/OpenaiChat.py
index b07bd49b..60a101d7 100644
--- a/g4f/Provider/needs_auth/OpenaiChat.py
+++ b/g4f/Provider/needs_auth/OpenaiChat.py
@@ -16,9 +16,8 @@ try:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
- has_webdriver = True
except ImportError:
- has_webdriver = False
+ pass
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
from ..helper import format_prompt, get_cookies
@@ -332,13 +331,14 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
cookies = cls._cookies or get_cookies("chat.openai.com", False)
if not access_token and "access_token" in cookies:
access_token = cookies["access_token"]
- if not access_token and not has_webdriver:
- raise MissingAccessToken(f'Missing "access_token"')
if not access_token:
login_url = os.environ.get("G4F_LOGIN_URL")
if login_url:
yield f"Please login: [ChatGPT]({login_url})\n\n"
- access_token, cookies = cls.browse_access_token(proxy)
+ try:
+ access_token, cookies = cls.browse_access_token(proxy)
+ except MissingRequirementsError:
+ raise MissingAccessToken(f'Missing "access_token"')
cls._cookies = cookies
headers = {"Authorization": f"Bearer {access_token}"}
diff --git a/g4f/Provider/needs_auth/Poe.py b/g4f/Provider/needs_auth/Poe.py
index 41c5315a..0c969d27 100644
--- a/g4f/Provider/needs_auth/Poe.py
+++ b/g4f/Provider/needs_auth/Poe.py
@@ -5,7 +5,7 @@ import time
from ...typing import CreateResult, Messages
from ..base_provider import AbstractProvider
from ..helper import format_prompt
-from ...webdriver import WebDriver, WebDriverSession
+from ...webdriver import WebDriver, WebDriverSession, element_send_text
models = {
"meta-llama/Llama-2-7b-chat-hf": {"name": "Llama-2-7b"},
@@ -89,7 +89,7 @@ class Poe(AbstractProvider):
else:
raise RuntimeError("Prompt textarea not found. You may not be logged in.")
- driver.find_element(By.CSS_SELECTOR, "footer textarea[class^='GrowingTextArea']").send_keys(prompt)
+ element_send_text(driver.find_element(By.CSS_SELECTOR, "footer textarea[class^='GrowingTextArea']"), prompt)
driver.find_element(By.CSS_SELECTOR, "footer button[class*='ChatMessageSendButton']").click()
script = """
diff --git a/g4f/Provider/needs_auth/Theb.py b/g4f/Provider/needs_auth/Theb.py
index efb38a40..2930e35d 100644
--- a/g4f/Provider/needs_auth/Theb.py
+++ b/g4f/Provider/needs_auth/Theb.py
@@ -5,7 +5,7 @@ import time
from ...typing import CreateResult, Messages
from ..base_provider import AbstractProvider
from ..helper import format_prompt
-from ...webdriver import WebDriver, WebDriverSession
+from ...webdriver import WebDriver, WebDriverSession, element_send_text
models = {
"theb-ai": "TheB.AI",
@@ -118,8 +118,7 @@ window._last_message = "";
# Submit prompt
wait.until(EC.visibility_of_element_located((By.ID, "textareaAutosize")))
- driver.find_element(By.ID, "textareaAutosize").send_keys(prompt)
- driver.find_element(By.ID, "textareaAutosize").send_keys(Keys.ENTER)
+ element_send_text(driver.find_element(By.ID, "textareaAutosize"), prompt)
# Read response with reader
script = """