diff options
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/Airforce.py | 2 | ||||
-rw-r--r-- | g4f/Provider/Binjie.py | 65 | ||||
-rw-r--r-- | g4f/Provider/Blackbox.py | 2 | ||||
-rw-r--r-- | g4f/Provider/ChatifyAI.py | 10 | ||||
-rw-r--r-- | g4f/Provider/LiteIcoding.py | 132 | ||||
-rw-r--r-- | g4f/Provider/__init__.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraAnimagineXL.py | 66 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraBing.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraGeminiPro.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraLLaMA31.py | 10 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraMidjourney.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraProdiaAI.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraSD15.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraSD21.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraSDLora.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/NexraSDTurbo.py | 2 | ||||
-rw-r--r-- | g4f/Provider/nexra/__init__.py | 1 |
17 files changed, 27 insertions, 279 deletions
diff --git a/g4f/Provider/Airforce.py b/g4f/Provider/Airforce.py index 3ec08b99..e7907cec 100644 --- a/g4f/Provider/Airforce.py +++ b/g4f/Provider/Airforce.py @@ -37,7 +37,7 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin): 'gpt-3.5-turbo', 'gpt-3.5-turbo-0125', 'gpt-3.5-turbo-1106', - 'llama-3-70b-chat', + default_model, 'llama-3-70b-chat-turbo', 'llama-3-8b-chat', 'llama-3-8b-chat-turbo', diff --git a/g4f/Provider/Binjie.py b/g4f/Provider/Binjie.py deleted file mode 100644 index 90f9ec3c..00000000 --- a/g4f/Provider/Binjie.py +++ /dev/null @@ -1,65 +0,0 @@ -from __future__ import annotations - -import random -from ..requests import StreamSession - -from ..typing import AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider, format_prompt - - -class Binjie(AsyncGeneratorProvider): - url = "https://chat18.aichatos8.com" - working = True - supports_gpt_4 = True - supports_stream = True - supports_system_message = True - supports_message_history = True - - @staticmethod - async def create_async_generator( - model: str, - messages: Messages, - proxy: str = None, - timeout: int = 120, - **kwargs, - ) -> AsyncResult: - async with StreamSession( - headers=_create_header(), proxies={"https": proxy}, timeout=timeout - ) as session: - payload = _create_payload(messages, **kwargs) - async with session.post("https://api.binjie.fun/api/generateStream", json=payload) as response: - response.raise_for_status() - async for chunk in response.iter_content(): - if chunk: - chunk = chunk.decode() - if "sorry, 您的ip已由于触发防滥用检测而被封禁" in chunk: - raise RuntimeError("IP address is blocked by abuse detection.") - yield chunk - - -def _create_header(): - return { - "accept" : "application/json, text/plain, */*", - "content-type" : "application/json", - "origin" : "https://chat18.aichatos8.com", - "referer" : "https://chat18.aichatos8.com/" - } - - -def _create_payload( - messages: Messages, - system_message: str = "", - user_id: int = None, - **kwargs -): - if not user_id: - user_id = random.randint(1690000544336, 2093025544336) - return { - "prompt": format_prompt(messages), - "network": True, - "system": system_message, - "withoutContext": False, - "stream": True, - "userId": f"#/chat/{user_id}" - } - diff --git a/g4f/Provider/Blackbox.py b/g4f/Provider/Blackbox.py index 3bc49dc4..5989145b 100644 --- a/g4f/Provider/Blackbox.py +++ b/g4f/Provider/Blackbox.py @@ -80,7 +80,6 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): "gpt-4o": "gpt-4o", "gemini-pro": "gemini-pro", 'claude-sonnet-3.5': "claude-sonnet-3.5", - 'blackboxai-pro': "blackboxai-pro", } model_prefixes = { @@ -107,7 +106,6 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): model_referers = { "blackboxai": f"{url}/?model=blackboxai", - "blackboxai-pro": f"{url}/?model=blackboxai-pro", "gpt-4o": f"{url}/?model=gpt-4o", "gemini-pro": f"{url}/?model=gemini-pro", "claude-sonnet-3.5": f"{url}/?model=claude-sonnet-3.5" diff --git a/g4f/Provider/ChatifyAI.py b/g4f/Provider/ChatifyAI.py index c5b4a104..a999afac 100644 --- a/g4f/Provider/ChatifyAI.py +++ b/g4f/Provider/ChatifyAI.py @@ -17,10 +17,18 @@ class ChatifyAI(AsyncGeneratorProvider, ProviderModelMixin): default_model = 'llama-3.1' models = [default_model] + model_aliases = { + "llama-3.1-8b": "llama-3.1", + } @classmethod def get_model(cls, model: str) -> str: - return cls.default_model + if model in cls.models: + return model + elif model in cls.model_aliases: + return cls.model_aliases.get(model, cls.default_model) + else: + return cls.default_model @classmethod async def create_async_generator( diff --git a/g4f/Provider/LiteIcoding.py b/g4f/Provider/LiteIcoding.py deleted file mode 100644 index f349c85e..00000000 --- a/g4f/Provider/LiteIcoding.py +++ /dev/null @@ -1,132 +0,0 @@ -from __future__ import annotations -import base64 -import re -from aiohttp import ClientSession, ClientResponseError -from ..typing import AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider, ProviderModelMixin -from .helper import format_prompt - -class LiteIcoding(AsyncGeneratorProvider, ProviderModelMixin): - url = "https://lite.icoding.ink" - api_endpoint = "/api/v1/gpt/message" - working = True - supports_gpt_4 = True - default_model = "gpt-4o" - models = [ - 'gpt-4o', - 'gpt-4-turbo', - 'claude-3', - 'claude-3.5', - 'gemini-1.5', - ] - - model_aliases = { - "gpt-4o-mini": "gpt-4o", - "gemini-pro": "gemini-1.5", - } - - bearer_tokens = [ - "NWQ2OWNkMjcxYjE0NDIyNmFjMTE5OWIzYzg0OWE1NjY=", - ] - current_token_index = 0 - - @classmethod - def decode_token(cls, encoded_token: str) -> str: - return base64.b64decode(encoded_token).decode('utf-8') - - @classmethod - def get_next_bearer_token(cls): - encoded_token = cls.bearer_tokens[cls.current_token_index] - cls.current_token_index = (cls.current_token_index + 1) % len(cls.bearer_tokens) - return cls.decode_token(encoded_token) - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - **kwargs - ) -> AsyncResult: - bearer_token = cls.get_next_bearer_token() - headers = { - "Accept": "*/*", - "Accept-Language": "en-US,en;q=0.9", - "Authorization": f"Bearer {bearer_token}", - "Connection": "keep-alive", - "Content-Type": "application/json;charset=utf-8", - "DNT": "1", - "Origin": cls.url, - "Referer": f"{cls.url}/", - "Sec-Fetch-Dest": "empty", - "Sec-Fetch-Mode": "cors", - "Sec-Fetch-Site": "same-origin", - "User-Agent": ( - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/126.0.0.0 Safari/537.36" - ), - "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"', - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": '"Linux"', - } - - data = { - "model": model, - "chatId": "-1", - "messages": [ - { - "role": msg["role"], - "content": msg["content"], - "time": msg.get("time", ""), - "attachments": msg.get("attachments", []), - } - for msg in messages - ], - "plugins": [], - "systemPrompt": "", - "temperature": 0.5, - } - - async with ClientSession(headers=headers) as session: - try: - async with session.post( - f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy - ) as response: - response.raise_for_status() - buffer = "" - full_response = "" - - def decode_content(data): - bytes_array = bytes([int(b, 16) ^ 255 for b in data.split()]) - return bytes_array.decode('utf-8') - - async for chunk in response.content.iter_any(): - if chunk: - buffer += chunk.decode() - while "\n\n" in buffer: - part, buffer = buffer.split("\n\n", 1) - if part.startswith("data: "): - content = part[6:].strip() - if content and content != "[DONE]": - content = content.strip('"') - decoded_content = decode_content(content) - full_response += decoded_content - full_response = ( - full_response.replace('""', '') - .replace('" "', ' ') - .replace("\\n\\n", "\n\n") - .replace("\\n", "\n") - .replace('\\"', '"') - .strip() - ) - filtered_response = re.sub(r'\n---\n.*', '', full_response, flags=re.DOTALL) - cleaned_response = filtered_response.strip().strip('"') - yield cleaned_response - - except ClientResponseError as e: - raise RuntimeError( - f"ClientResponseError {e.status}: {e.message}, url={e.request_info.url}, data={data}" - ) from e - - except Exception as e: - raise RuntimeError(f"Unexpected error: {str(e)}") from e diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py index 73a17e10..3d6539fc 100644 --- a/g4f/Provider/__init__.py +++ b/g4f/Provider/__init__.py @@ -22,7 +22,6 @@ from .Airforce import Airforce from .Aura import Aura from .Bing import Bing from .BingCreateImages import BingCreateImages -from .Binjie import Binjie from .Blackbox import Blackbox from .ChatGot import ChatGot from .ChatGpt import ChatGpt @@ -50,7 +49,6 @@ from .HuggingChat import HuggingChat from .HuggingFace import HuggingFace from .Koala import Koala from .Liaobots import Liaobots -from .LiteIcoding import LiteIcoding from .Local import Local from .MagickPen import MagickPen from .MetaAI import MetaAI diff --git a/g4f/Provider/nexra/NexraAnimagineXL.py b/g4f/Provider/nexra/NexraAnimagineXL.py deleted file mode 100644 index d6fbc629..00000000 --- a/g4f/Provider/nexra/NexraAnimagineXL.py +++ /dev/null @@ -1,66 +0,0 @@ -from __future__ import annotations - -from aiohttp import ClientSession -import json - -from ...typing import AsyncResult, Messages -from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin -from ...image import ImageResponse - - -class NexraAnimagineXL(AsyncGeneratorProvider, ProviderModelMixin): - label = "Nexra Animagine XL" - url = "https://nexra.aryahcr.cc/documentation/midjourney/en" - api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True - - default_model = 'animagine-xl' - models = [default_model] - - @classmethod - def get_model(cls, model: str) -> str: - return cls.default_model - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - response: str = "url", # base64 or url - **kwargs - ) -> AsyncResult: - # Retrieve the correct model to use - model = cls.get_model(model) - - # Format the prompt from the messages - prompt = messages[0]['content'] - - headers = { - "Content-Type": "application/json" - } - payload = { - "prompt": prompt, - "model": model, - "response": response - } - - async with ClientSession(headers=headers) as session: - async with session.post(cls.api_endpoint, json=payload, proxy=proxy) as response: - response.raise_for_status() - text_data = await response.text() - - try: - # Parse the JSON response - json_start = text_data.find('{') - json_data = text_data[json_start:] - data = json.loads(json_data) - - # Check if the response contains images - if 'images' in data and len(data['images']) > 0: - image_url = data['images'][0] - yield ImageResponse(image_url, prompt) - else: - yield ImageResponse("No images found in the response.", prompt) - except json.JSONDecodeError: - yield ImageResponse("Failed to parse JSON. Response might not be in JSON format.", prompt) diff --git a/g4f/Provider/nexra/NexraBing.py b/g4f/Provider/nexra/NexraBing.py index 02f3724d..716e9254 100644 --- a/g4f/Provider/nexra/NexraBing.py +++ b/g4f/Provider/nexra/NexraBing.py @@ -13,7 +13,7 @@ class NexraBing(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Bing" url = "https://nexra.aryahcr.cc/documentation/bing/en" api_endpoint = "https://nexra.aryahcr.cc/api/chat/complements" - working = True + working = False supports_gpt_4 = False supports_stream = False diff --git a/g4f/Provider/nexra/NexraGeminiPro.py b/g4f/Provider/nexra/NexraGeminiPro.py index 651f7cb4..fb0b096b 100644 --- a/g4f/Provider/nexra/NexraGeminiPro.py +++ b/g4f/Provider/nexra/NexraGeminiPro.py @@ -11,7 +11,7 @@ class NexraGeminiPro(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Gemini PRO" url = "https://nexra.aryahcr.cc/documentation/gemini-pro/en" api_endpoint = "https://nexra.aryahcr.cc/api/chat/complements" - working = True + working = False supports_stream = True default_model = 'gemini-pro' diff --git a/g4f/Provider/nexra/NexraLLaMA31.py b/g4f/Provider/nexra/NexraLLaMA31.py index c67febb3..d461f2b2 100644 --- a/g4f/Provider/nexra/NexraLLaMA31.py +++ b/g4f/Provider/nexra/NexraLLaMA31.py @@ -17,10 +17,18 @@ class NexraLLaMA31(AsyncGeneratorProvider, ProviderModelMixin): default_model = 'llama-3.1' models = [default_model] + model_aliases = { + "llama-3.1-8b": "llama-3.1", + } @classmethod def get_model(cls, model: str) -> str: - return cls.default_model + if model in cls.models: + return model + elif model in cls.model_aliases: + return cls.model_aliases.get(model, cls.default_model) + else: + return cls.default_model @classmethod async def create_async_generator( diff --git a/g4f/Provider/nexra/NexraMidjourney.py b/g4f/Provider/nexra/NexraMidjourney.py index 3d6a4960..e43cb164 100644 --- a/g4f/Provider/nexra/NexraMidjourney.py +++ b/g4f/Provider/nexra/NexraMidjourney.py @@ -12,7 +12,7 @@ class NexraMidjourney(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Midjourney" url = "https://nexra.aryahcr.cc/documentation/midjourney/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'midjourney' models = [default_model] diff --git a/g4f/Provider/nexra/NexraProdiaAI.py b/g4f/Provider/nexra/NexraProdiaAI.py index 262558fd..9d82ab9b 100644 --- a/g4f/Provider/nexra/NexraProdiaAI.py +++ b/g4f/Provider/nexra/NexraProdiaAI.py @@ -12,7 +12,7 @@ class NexraProdiaAI(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Prodia AI" url = "https://nexra.aryahcr.cc/documentation/prodia/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'absolutereality_v181.safetensors [3d9d4d2b]' models = [ diff --git a/g4f/Provider/nexra/NexraSD15.py b/g4f/Provider/nexra/NexraSD15.py index 410947df..03b35013 100644 --- a/g4f/Provider/nexra/NexraSD15.py +++ b/g4f/Provider/nexra/NexraSD15.py @@ -12,7 +12,7 @@ class NexraSD15(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Stable Diffusion 1.5" url = "https://nexra.aryahcr.cc/documentation/stable-diffusion/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'stablediffusion-1.5' models = [default_model] diff --git a/g4f/Provider/nexra/NexraSD21.py b/g4f/Provider/nexra/NexraSD21.py index fc5c90d9..46cd6611 100644 --- a/g4f/Provider/nexra/NexraSD21.py +++ b/g4f/Provider/nexra/NexraSD21.py @@ -12,7 +12,7 @@ class NexraSD21(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Stable Diffusion 2.1" url = "https://nexra.aryahcr.cc/documentation/stable-diffusion/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'stablediffusion-2.1' models = [default_model] diff --git a/g4f/Provider/nexra/NexraSDLora.py b/g4f/Provider/nexra/NexraSDLora.py index ad986507..a33afa04 100644 --- a/g4f/Provider/nexra/NexraSDLora.py +++ b/g4f/Provider/nexra/NexraSDLora.py @@ -12,7 +12,7 @@ class NexraSDLora(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Stable Diffusion Lora" url = "https://nexra.aryahcr.cc/documentation/stable-diffusion/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'sdxl-lora' models = [default_model] diff --git a/g4f/Provider/nexra/NexraSDTurbo.py b/g4f/Provider/nexra/NexraSDTurbo.py index feb59f0b..da1428b8 100644 --- a/g4f/Provider/nexra/NexraSDTurbo.py +++ b/g4f/Provider/nexra/NexraSDTurbo.py @@ -12,7 +12,7 @@ class NexraSDTurbo(AsyncGeneratorProvider, ProviderModelMixin): label = "Nexra Stable Diffusion Turbo" url = "https://nexra.aryahcr.cc/documentation/stable-diffusion/en" api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True + working = False default_model = 'sdxl-turbo' models = [default_model] diff --git a/g4f/Provider/nexra/__init__.py b/g4f/Provider/nexra/__init__.py index d8b9218f..c2e6b2f6 100644 --- a/g4f/Provider/nexra/__init__.py +++ b/g4f/Provider/nexra/__init__.py @@ -1,4 +1,3 @@ -from .NexraAnimagineXL import NexraAnimagineXL from .NexraBing import NexraBing from .NexraBlackbox import NexraBlackbox from .NexraChatGPT import NexraChatGPT |