diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-09-06 22:19:18 +0200 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-09-06 22:19:18 +0200 |
commit | b3950ae6638ce483e985a02afbd7e442136e2baa (patch) | |
tree | 9a226fa2f0f841beac4b26481b6af8d150955537 /g4f | |
parent | Adding a new provider Binjie (diff) | |
download | gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar.gz gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar.bz2 gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar.lz gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar.xz gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.tar.zst gpt4free-b3950ae6638ce483e985a02afbd7e442136e2baa.zip |
Diffstat (limited to 'g4f')
-rw-r--r-- | g4f/Provider/Free2GPT.py | 77 | ||||
-rw-r--r-- | g4f/Provider/__init__.py | 3 | ||||
-rw-r--r-- | g4f/models.py | 4 |
3 files changed, 82 insertions, 2 deletions
diff --git a/g4f/Provider/Free2GPT.py b/g4f/Provider/Free2GPT.py new file mode 100644 index 00000000..a79bd1da --- /dev/null +++ b/g4f/Provider/Free2GPT.py @@ -0,0 +1,77 @@ +from __future__ import annotations + +import time +from hashlib import sha256 + +from aiohttp import BaseConnector, ClientSession + +from ..errors import RateLimitError +from ..requests import raise_for_status +from ..requests.aiohttp import get_connector +from ..typing import AsyncResult, Messages +from .base_provider import AsyncGeneratorProvider, ProviderModelMixin + + +class Free2GPT(AsyncGeneratorProvider, ProviderModelMixin): + url = "https://chat10.free2gpt.xyz" + working = True + supports_message_history = True + default_model = 'llama-3.1-70b' + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: Messages, + proxy: str = None, + connector: BaseConnector = None, + **kwargs, + ) -> AsyncResult: + headers = { + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", + "Accept": "*/*", + "Accept-Language": "en-US,en;q=0.9", + "Accept-Encoding": "gzip, deflate, br", + "Content-Type": "text/plain;charset=UTF-8", + "Referer": f"{cls.url}/", + "Origin": cls.url, + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "Sec-Ch-Ua": '"Chromium";v="127", "Not)A;Brand";v="99"', + "Sec-Ch-Ua-Mobile": "?0", + "Sec-Ch-Ua-Platform": '"Linux"', + "Cache-Control": "no-cache", + "Pragma": "no-cache", + "Priority": "u=1, i", + } + async with ClientSession( + connector=get_connector(connector, proxy), headers=headers + ) as session: + timestamp = int(time.time() * 1e3) + system_message = { + "role": "system", + "content": "" + } + data = { + "messages": [system_message] + messages, + "time": timestamp, + "pass": None, + "sign": generate_signature(timestamp, messages[-1]["content"]), + } + async with session.post( + f"{cls.url}/api/generate", json=data, proxy=proxy + ) as response: + if response.status == 500: + if "Quota exceeded" in await response.text(): + raise RateLimitError( + f"Response {response.status}: Rate limit reached" + ) + await raise_for_status(response) + async for chunk in response.content.iter_any(): + yield chunk.decode(errors="ignore") + + +def generate_signature(time: int, text: str, secret: str = ""): + message = f"{time}:{text}:{secret}" + return sha256(message.encode()).hexdigest() diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py index 8fe8cfad..a3126ddb 100644 --- a/g4f/Provider/__init__.py +++ b/g4f/Provider/__init__.py @@ -16,7 +16,7 @@ from .AiChats import AiChats from .Aura import Aura from .Bing import Bing from .BingCreateImages import BingCreateImages -from .Binjie import Binjie +from .Binjie import Binjie from .Bixin123 import Bixin123 from .Blackbox import Blackbox from .ChatGot import ChatGot @@ -29,6 +29,7 @@ from .DeepInfra import DeepInfra from .DeepInfraImage import DeepInfraImage from .FlowGpt import FlowGpt from .FluxAirforce import FluxAirforce +from .Free2GPT import Free2GPT from .FreeChatgpt import FreeChatgpt from .FreeGpt import FreeGpt from .FreeNetfly import FreeNetfly diff --git a/g4f/models.py b/g4f/models.py index 61350d91..7b42165b 100644 --- a/g4f/models.py +++ b/g4f/models.py @@ -19,6 +19,7 @@ from .Provider import ( DeepInfra, DeepInfraImage, FluxAirforce, + Free2GPT, FreeChatgpt, FreeGpt, FreeNetfly, @@ -86,6 +87,7 @@ default = Model( Blackbox, Bixin123, Binjie, + Free2GPT, ]) ) @@ -182,7 +184,7 @@ llama_3_1_8b = Model( llama_3_1_70b = Model( name = "llama-3.1-70b", base_provider = "Meta", - best_provider = IterListProvider([DDG, HuggingChat, FreeGpt, Blackbox, TeachAnything, HuggingFace]) + best_provider = IterListProvider([DDG, HuggingChat, FreeGpt, Blackbox, TeachAnything, Free2GPT, HuggingFace]) ) llama_3_1_405b = Model( |