summaryrefslogtreecommitdiffstats
path: root/g4f/Provider
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider')
-rw-r--r--g4f/Provider/Llama.py91
-rw-r--r--g4f/Provider/__init__.py1
-rw-r--r--g4f/Provider/selenium/AItianhuSpace.py116
3 files changed, 0 insertions, 208 deletions
diff --git a/g4f/Provider/Llama.py b/g4f/Provider/Llama.py
deleted file mode 100644
index 235c0994..00000000
--- a/g4f/Provider/Llama.py
+++ /dev/null
@@ -1,91 +0,0 @@
-from __future__ import annotations
-
-from aiohttp import ClientSession
-
-from ..typing import AsyncResult, Messages
-from ..requests.raise_for_status import raise_for_status
-from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
-
-
-class Llama(AsyncGeneratorProvider, ProviderModelMixin):
- url = "https://www.llama2.ai"
- working = False
- supports_message_history = True
- default_model = "meta/meta-llama-3-70b-instruct"
- models = [
- "meta/llama-2-7b-chat",
- "meta/llama-2-13b-chat",
- "meta/llama-2-70b-chat",
- "meta/meta-llama-3-8b-instruct",
- "meta/meta-llama-3-70b-instruct",
- ]
- model_aliases = {
- "meta-llama/Meta-Llama-3-8B-Instruct": "meta/meta-llama-3-8b-instruct",
- "meta-llama/Meta-Llama-3-70B-Instruct": "meta/meta-llama-3-70b-instruct",
- "meta-llama/Llama-2-7b-chat-hf": "meta/llama-2-7b-chat",
- "meta-llama/Llama-2-13b-chat-hf": "meta/llama-2-13b-chat",
- "meta-llama/Llama-2-70b-chat-hf": "meta/llama-2-70b-chat",
- }
-
- @classmethod
- async def create_async_generator(
- cls,
- model: str,
- messages: Messages,
- proxy: str = None,
- system_message: str = "You are a helpful assistant.",
- temperature: float = 0.75,
- top_p: float = 0.9,
- max_tokens: int = 8000,
- **kwargs
- ) -> AsyncResult:
- headers = {
- "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0",
- "Accept": "*/*",
- "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
- "Accept-Encoding": "gzip, deflate, br",
- "Referer": f"{cls.url}/",
- "Content-Type": "text/plain;charset=UTF-8",
- "Origin": cls.url,
- "Connection": "keep-alive",
- "Sec-Fetch-Dest": "empty",
- "Sec-Fetch-Mode": "cors",
- "Sec-Fetch-Site": "same-origin",
- "Pragma": "no-cache",
- "Cache-Control": "no-cache",
- "TE": "trailers"
- }
- async with ClientSession(headers=headers) as session:
- system_messages = [message["content"] for message in messages if message["role"] == "system"]
- if system_messages:
- system_message = "\n".join(system_messages)
- messages = [message for message in messages if message["role"] != "system"]
- prompt = format_prompt(messages)
- data = {
- "prompt": prompt,
- "model": cls.get_model(model),
- "systemPrompt": system_message,
- "temperature": temperature,
- "topP": top_p,
- "maxTokens": max_tokens,
- "image": None
- }
- started = False
- async with session.post(f"{cls.url}/api", json=data, proxy=proxy) as response:
- await raise_for_status(response)
- async for chunk in response.content.iter_any():
- if not chunk:
- continue
- if not started:
- chunk = chunk.lstrip()
- started = True
- yield chunk.decode(errors="ignore")
-
-def format_prompt(messages: Messages):
- messages = [
- f"[INST] {message['content']} [/INST]"
- if message["role"] == "user"
- else message["content"]
- for message in messages
- ]
- return "\n".join(messages) + "\n"
diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py
index a9a815ea..10459684 100644
--- a/g4f/Provider/__init__.py
+++ b/g4f/Provider/__init__.py
@@ -41,7 +41,6 @@ from .HuggingFace import HuggingFace
from .Koala import Koala
from .Liaobots import Liaobots
from .LiteIcoding import LiteIcoding
-from .Llama import Llama
from .Local import Local
from .MagickPen import MagickPen
from .MetaAI import MetaAI
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