From 1eb7dc05e59433de149ec16d9b2fe19b3fa4b24b Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 26 Jan 2024 12:49:52 +0100 Subject: Fix: ChromeDriver only supports characters in the BMP Add set_cookies helper, Show last used model --- g4f/Provider/selenium/AItianhuSpace.py | 5 ++--- g4f/Provider/selenium/PerplexityAi.py | 6 ++---- g4f/Provider/selenium/TalkAi.py | 9 ++++----- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'g4f/Provider/selenium') diff --git a/g4f/Provider/selenium/AItianhuSpace.py b/g4f/Provider/selenium/AItianhuSpace.py index 9878bd5a..6af8ceaf 100644 --- a/g4f/Provider/selenium/AItianhuSpace.py +++ b/g4f/Provider/selenium/AItianhuSpace.py @@ -6,7 +6,7 @@ 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 +from ...webdriver import WebDriver, WebDriverSession, element_send_text from ... import debug class AItianhuSpace(AbstractProvider): @@ -91,8 +91,7 @@ XMLHttpRequest.prototype.open = function(method, url) { driver.execute_script(script) # Submit prompt - driver.find_element(By.CSS_SELECTOR, "textarea.n-input__textarea-el").send_keys(prompt) - driver.find_element(By.CSS_SELECTOR, "button.n-button.n-button--primary-type.n-button--medium-type").click() + element_send_text(driver.find_element(By.CSS_SELECTOR, "textarea.n-input__textarea-el"), prompt) # Read response while True: diff --git a/g4f/Provider/selenium/PerplexityAi.py b/g4f/Provider/selenium/PerplexityAi.py index 8ae6ad2b..6b529d5b 100644 --- a/g4f/Provider/selenium/PerplexityAi.py +++ b/g4f/Provider/selenium/PerplexityAi.py @@ -6,14 +6,13 @@ 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 PerplexityAi(AbstractProvider): url = "https://www.perplexity.ai" @@ -83,8 +82,7 @@ WebSocket.prototype.send = function(...args) { raise RuntimeError("You need a account for copilot") # Submit prompt - driver.find_element(By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']").send_keys(prompt) - driver.find_element(By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']").send_keys(Keys.ENTER) + element_send_text(driver.find_element(By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']"), prompt) # Stream response script = """ diff --git a/g4f/Provider/selenium/TalkAi.py b/g4f/Provider/selenium/TalkAi.py index 5aeb48ac..89280598 100644 --- a/g4f/Provider/selenium/TalkAi.py +++ b/g4f/Provider/selenium/TalkAi.py @@ -42,7 +42,7 @@ class TalkAi(AbstractProvider): "content": message["content"] } for message in messages], "model": model if model else "gpt-3.5-turbo", - "max_tokens": 256, + "max_tokens": 2048, "temperature": 1, "top_p": 1, "presence_penalty": 0, @@ -67,16 +67,15 @@ window._reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); while True: chunk = driver.execute_script(""" chunk = await window._reader.read(); -if (chunk["done"]) { +if (chunk.done) { return null; } content = ""; -lines = chunk["value"].split("\\n") -lines.forEach((line, index) => { +for (line of chunk.value.split("\\n")) { if (line.startsWith('data: ')) { content += line.substring('data: '.length); } -}); +} return content; """) if chunk: -- cgit v1.2.3