summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/AItianhuSpace.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-11-18 12:24:39 +0100
committerGitHub <noreply@github.com>2023-11-18 12:24:39 +0100
commit2fcb3f949bbde7f5380acc68dc6b1f938dec12bc (patch)
tree035bd400b4057a744b29a0ebee96579bfbf429f6 /g4f/Provider/AItianhuSpace.py
parent~ | g4f `v-0.1.8.5` (diff)
parentAdd AiChatOnline, ChatgptDemoAi, ChatgptNext Providers (diff)
downloadgpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.gz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.bz2
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.lz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.xz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.zst
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/AItianhuSpace.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/g4f/Provider/AItianhuSpace.py b/g4f/Provider/AItianhuSpace.py
index 0a2f6fe0..312cb3b3 100644
--- a/g4f/Provider/AItianhuSpace.py
+++ b/g4f/Provider/AItianhuSpace.py
@@ -5,7 +5,7 @@ import random
from ..typing import CreateResult, Messages
from .base_provider import BaseProvider
-from .helper import WebDriver, format_prompt, get_browser
+from .helper import WebDriver, format_prompt, get_browser, get_random_string
from .. import debug
class AItianhuSpace(BaseProvider):
@@ -31,8 +31,7 @@ class AItianhuSpace(BaseProvider):
if not model:
model = "gpt-3.5-turbo"
if not domain:
- chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
- rand = ''.join(random.choice(chars) for _ in range(6))
+ rand = get_random_string(6)
domain = random.choice(cls._domains)
domain = f"{rand}.{domain}"
if debug.logging:
@@ -65,10 +64,11 @@ document.getElementById('sheet').addEventListener('click', () => {{
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")))
try:
- # Add hook in XMLHttpRequest
+ # Register hook in XMLHttpRequest
script = """
const _http_request_open = XMLHttpRequest.prototype.open;
window._last_message = window._message = "";
@@ -90,11 +90,11 @@ XMLHttpRequest.prototype.open = function(method, url) {
"""
driver.execute_script(script)
- # Input and submit prompt
+ # 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()
- # Yield response
+ # Read response
while True:
chunk = driver.execute_script("""
if (window._message && window._message != window._last_message) {