diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-11-17 11:16:49 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2023-11-17 11:16:49 +0100 |
commit | e4caf1d0ca06b83bc0e272eca0e5330feb417f60 (patch) | |
tree | a745c83959f02cb903f3a559473e37b379f6af24 /g4f/Provider/PerplexityAi.py | |
parent | Update Readme (diff) | |
download | gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar.gz gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar.bz2 gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar.lz gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar.xz gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.tar.zst gpt4free-e4caf1d0ca06b83bc0e272eca0e5330feb417f60.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/PerplexityAi.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/g4f/Provider/PerplexityAi.py b/g4f/Provider/PerplexityAi.py index 1159840a..bce77715 100644 --- a/g4f/Provider/PerplexityAi.py +++ b/g4f/Provider/PerplexityAi.py @@ -22,24 +22,24 @@ class PerplexityAi(BaseProvider): timeout: int = 120, browser: WebDriver = None, copilot: bool = False, - headless: bool = True, **kwargs ) -> CreateResult: - driver = browser if browser else get_browser("", headless, proxy) + driver = browser if browser else get_browser("", False, proxy) 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 prompt = format_prompt(messages) driver.get(f"{cls.url}/") wait = WebDriverWait(driver, timeout) - # Page loaded? + # Is page loaded? wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']"))) - # Add WebSocket hook + # Register WebSocket hook script = """ window._message = window._last_message = ""; window._message_finished = false; @@ -57,8 +57,9 @@ WebSocket.prototype.send = function(...args) { content = JSON.parse(content); } window._message = content["answer"]; - window._message_finished = data[0] == "query_answered"; - window._web_results = content["web_results"]; + if (!window._message_finished) { + window._message_finished = data[0] == "query_answered"; + } } } }); @@ -70,20 +71,19 @@ WebSocket.prototype.send = function(...args) { if copilot: try: - # Check account + # Check for account driver.find_element(By.CSS_SELECTOR, "img[alt='User avatar']") # Enable copilot driver.find_element(By.CSS_SELECTOR, "button[data-testid='copilot-toggle']").click() except: - raise RuntimeError("For copilot you needs a account") + raise RuntimeError("You need a account for copilot") - # Enter question + # Submit prompt driver.find_element(By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']").send_keys(prompt) - # Submit question - driver.find_element(By.CSS_SELECTOR, "button.bg-super svg[data-icon='arrow-right']").click() + driver.find_element(By.CSS_SELECTOR, "textarea[placeholder='Ask anything...']").send_keys(Keys.ENTER) try: - # Yield response + # Stream response script = """ if(window._message && window._message != window._last_message) { try { |