From 2f64bc99efed1c7ea44e116ab7db12d5f75412a1 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 13 Nov 2023 18:58:52 +0100 Subject: Fix Chatgpt4Online Provider --- g4f/Provider/Acytoo.py | 51 ----------------- g4f/Provider/AiAsk.py | 2 +- g4f/Provider/Aibn.py | 58 ------------------- g4f/Provider/Aichat.py | 4 +- g4f/Provider/Ails.py | 101 ---------------------------------- g4f/Provider/Chatgpt4Online.py | 48 ++++++++-------- g4f/Provider/ChatgptDuo.py | 58 ------------------- g4f/Provider/Cromicle.py | 50 ----------------- g4f/Provider/FreeGpt.py | 2 +- g4f/Provider/__init__.py | 5 -- g4f/Provider/deprecated/Acytoo.py | 51 +++++++++++++++++ g4f/Provider/deprecated/Aibn.py | 58 +++++++++++++++++++ g4f/Provider/deprecated/Ails.py | 101 ++++++++++++++++++++++++++++++++++ g4f/Provider/deprecated/ChatgptDuo.py | 58 +++++++++++++++++++ g4f/Provider/deprecated/Cromicle.py | 50 +++++++++++++++++ g4f/Provider/deprecated/__init__.py | 7 ++- 16 files changed, 353 insertions(+), 351 deletions(-) delete mode 100644 g4f/Provider/Acytoo.py delete mode 100644 g4f/Provider/Aibn.py delete mode 100644 g4f/Provider/Ails.py delete mode 100644 g4f/Provider/ChatgptDuo.py delete mode 100644 g4f/Provider/Cromicle.py create mode 100644 g4f/Provider/deprecated/Acytoo.py create mode 100644 g4f/Provider/deprecated/Aibn.py create mode 100644 g4f/Provider/deprecated/Ails.py create mode 100644 g4f/Provider/deprecated/ChatgptDuo.py create mode 100644 g4f/Provider/deprecated/Cromicle.py (limited to 'g4f/Provider') diff --git a/g4f/Provider/Acytoo.py b/g4f/Provider/Acytoo.py deleted file mode 100644 index 4dee176a..00000000 --- a/g4f/Provider/Acytoo.py +++ /dev/null @@ -1,51 +0,0 @@ -from __future__ import annotations - -from aiohttp import ClientSession - -from ..typing import AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider - - -class Acytoo(AsyncGeneratorProvider): - url = 'https://chat.acytoo.com' - working = False - supports_message_history = True - supports_gpt_35_turbo = True - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - **kwargs - ) -> AsyncResult: - async with ClientSession( - headers=_create_header() - ) as session: - async with session.post( - f'{cls.url}/api/completions', - proxy=proxy, - json=_create_payload(messages, **kwargs) - ) as response: - response.raise_for_status() - async for stream in response.content.iter_any(): - if stream: - yield stream.decode() - - -def _create_header(): - return { - 'accept': '*/*', - 'content-type': 'application/json', - } - - -def _create_payload(messages: Messages, temperature: float = 0.5, **kwargs): - return { - 'key' : '', - 'model' : 'gpt-3.5-turbo', - 'messages' : messages, - 'temperature' : temperature, - 'password' : '' - } \ No newline at end of file diff --git a/g4f/Provider/AiAsk.py b/g4f/Provider/AiAsk.py index ac123fc9..094ef076 100644 --- a/g4f/Provider/AiAsk.py +++ b/g4f/Provider/AiAsk.py @@ -8,7 +8,7 @@ class AiAsk(AsyncGeneratorProvider): url = "https://e.aiask.me" supports_message_history = True supports_gpt_35_turbo = True - working = True + working = False @classmethod async def create_async_generator( diff --git a/g4f/Provider/Aibn.py b/g4f/Provider/Aibn.py deleted file mode 100644 index 1f81a61e..00000000 --- a/g4f/Provider/Aibn.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -import time -import hashlib - -from ..typing import AsyncResult, Messages -from ..requests import StreamSession -from .base_provider import AsyncGeneratorProvider - - -class Aibn(AsyncGeneratorProvider): - url = "https://aibn.cc" - working = False - supports_message_history = True - supports_gpt_35_turbo = True - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - timeout: int = 120, - **kwargs - ) -> AsyncResult: - async with StreamSession( - impersonate="chrome107", - proxies={"https": proxy}, - timeout=timeout - ) as session: - timestamp = int(time.time()) - data = { - "messages": messages, - "pass": None, - "sign": generate_signature(timestamp, messages[-1]["content"]), - "time": timestamp - } - async with session.post(f"{cls.url}/api/generate", json=data) as response: - response.raise_for_status() - async for chunk in response.iter_content(): - yield chunk.decode() - - @classmethod - @property - def params(cls): - params = [ - ("model", "str"), - ("messages", "list[dict[str, str]]"), - ("stream", "bool"), - ("temperature", "float"), - ] - param = ", ".join([": ".join(p) for p in params]) - return f"g4f.provider.{cls.__name__} supports: ({param})" - - -def generate_signature(timestamp: int, message: str, secret: str = "undefined"): - data = f"{timestamp}:{message}:{secret}" - return hashlib.sha256(data.encode()).hexdigest() \ No newline at end of file diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py index 77ae4429..41ea9a96 100644 --- a/g4f/Provider/Aichat.py +++ b/g4f/Provider/Aichat.py @@ -8,8 +8,8 @@ from .helper import get_cookies from ..requests import StreamSession class Aichat(AsyncProvider): - url = "https://chat-gpt.org/chat" - working = True + url = "https://chat-gpt.org/chat" + working = False supports_gpt_35_turbo = True @staticmethod diff --git a/g4f/Provider/Ails.py b/g4f/Provider/Ails.py deleted file mode 100644 index 58010756..00000000 --- a/g4f/Provider/Ails.py +++ /dev/null @@ -1,101 +0,0 @@ -from __future__ import annotations - -import hashlib -import time -import uuid -import json -from datetime import datetime -from aiohttp import ClientSession - -from ..typing import SHA256, AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider - - -class Ails(AsyncGeneratorProvider): - url = "https://ai.ls" - working = False - supports_message_history = True - supports_gpt_35_turbo = True - - @staticmethod - async def create_async_generator( - model: str, - messages: Messages, - stream: bool, - proxy: str = None, - **kwargs - ) -> AsyncResult: - headers = { - "authority": "api.caipacity.com", - "accept": "*/*", - "accept-language": "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3", - "authorization": "Bearer free", - "client-id": str(uuid.uuid4()), - "client-v": "0.1.278", - "content-type": "application/json", - "origin": "https://ai.ls", - "referer": "https://ai.ls/", - "sec-ch-ua": '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"', - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": '"Windows"', - "sec-fetch-dest": "empty", - "sec-fetch-mode": "cors", - "sec-fetch-site": "cross-site", - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", - "from-url": "https://ai.ls/?chat=1" - } - async with ClientSession( - headers=headers - ) as session: - timestamp = _format_timestamp(int(time.time() * 1000)) - json_data = { - "model": "gpt-3.5-turbo", - "temperature": kwargs.get("temperature", 0.6), - "stream": True, - "messages": messages, - "d": datetime.now().strftime("%Y-%m-%d"), - "t": timestamp, - "s": _hash({"t": timestamp, "m": messages[-1]["content"]}), - } - async with session.post( - "https://api.caipacity.com/v1/chat/completions", - proxy=proxy, - json=json_data - ) as response: - response.raise_for_status() - start = "data: " - async for line in response.content: - line = line.decode('utf-8') - if line.startswith(start) and line != "data: [DONE]": - line = line[len(start):-1] - line = json.loads(line) - if token := line["choices"][0]["delta"].get("content"): - if "ai.ls" in token or "ai.ci" in token: - raise Exception(f"Response Error: {token}") - yield token - - - @classmethod - @property - def params(cls): - params = [ - ("model", "str"), - ("messages", "list[dict[str, str]]"), - ("stream", "bool"), - ("temperature", "float"), - ] - param = ", ".join([": ".join(p) for p in params]) - return f"g4f.provider.{cls.__name__} supports: ({param})" - - -def _hash(json_data: dict[str, str]) -> SHA256: - base_string: str = f'{json_data["t"]}:{json_data["m"]}:WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf:{len(json_data["m"])}' - - return SHA256(hashlib.sha256(base_string.encode()).hexdigest()) - - -def _format_timestamp(timestamp: int) -> str: - e = timestamp - n = e % 10 - r = n + 1 if n % 2 == 0 else n - return str(e - n + r) \ No newline at end of file diff --git a/g4f/Provider/Chatgpt4Online.py b/g4f/Provider/Chatgpt4Online.py index d7509639..57ab9482 100644 --- a/g4f/Provider/Chatgpt4Online.py +++ b/g4f/Provider/Chatgpt4Online.py @@ -1,42 +1,44 @@ from __future__ import annotations -import json +import re from aiohttp import ClientSession -from ..typing import AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider +from ..typing import Messages +from .base_provider import AsyncProvider +from .helper import format_prompt - -class Chatgpt4Online(AsyncGeneratorProvider): +class Chatgpt4Online(AsyncProvider): url = "https://chatgpt4online.org" supports_message_history = True supports_gpt_35_turbo = True - working = False + working = True + _wpnonce = None @classmethod - async def create_async_generator( + async def create_async( cls, model: str, messages: Messages, proxy: str = None, **kwargs - ) -> AsyncResult: + ) -> str: async with ClientSession() as session: + if not cls._wpnonce: + async with session.get(f"{cls.url}/", proxy=proxy) as response: + response.raise_for_status() + response = await response.text() + if result := re.search(r'data-nonce="(.*?)"', response): + cls._wpnonce = result.group(1) + else: + raise RuntimeError("No nonce found") data = { - "botId": "default", - "customId": None, - "session": "N/A", - "chatId": "", - "contextId": 58, - "messages": messages, - "newMessage": messages[-1]["content"], - "stream": True + "_wpnonce": cls._wpnonce, + "post_id": 58, + "url": "https://chatgpt4online.org", + "action": "wpaicg_chat_shortcode_message", + "message": format_prompt(messages), + "bot_id": 3405 } - - async with session.post(f"{cls.url}/wp-json/mwai-ui/v1/chats/submit", json=data, proxy=proxy) as response: + async with session.post(f"{cls.url}/rizq", data=data, proxy=proxy) as response: response.raise_for_status() - async for line in response.content: - if line.startswith(b"data: "): - line = json.loads(line[6:]) - if line["type"] == "live": - yield line["data"] \ No newline at end of file + return (await response.json())["data"] \ No newline at end of file diff --git a/g4f/Provider/ChatgptDuo.py b/g4f/Provider/ChatgptDuo.py deleted file mode 100644 index fef3f856..00000000 --- a/g4f/Provider/ChatgptDuo.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -from ..typing import Messages -from curl_cffi.requests import AsyncSession -from .base_provider import AsyncProvider, format_prompt - - -class ChatgptDuo(AsyncProvider): - url = "https://chatgptduo.com" - supports_gpt_35_turbo = True - working = False - - @classmethod - async def create_async( - cls, - model: str, - messages: Messages, - proxy: str = None, - timeout: int = 120, - **kwargs - ) -> str: - async with AsyncSession( - impersonate="chrome107", - proxies={"https": proxy}, - timeout=timeout - ) as session: - prompt = format_prompt(messages), - data = { - "prompt": prompt, - "search": prompt, - "purpose": "ask", - } - response = await session.post(f"{cls.url}/", data=data) - response.raise_for_status() - data = response.json() - - cls._sources = [{ - "title": source["title"], - "url": source["link"], - "snippet": source["snippet"] - } for source in data["results"]] - - return data["answer"] - - @classmethod - def get_sources(cls): - return cls._sources - - @classmethod - @property - def params(cls): - params = [ - ("model", "str"), - ("messages", "list[dict[str, str]]"), - ("stream", "bool"), - ] - param = ", ".join([": ".join(p) for p in params]) - return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file diff --git a/g4f/Provider/Cromicle.py b/g4f/Provider/Cromicle.py deleted file mode 100644 index 8deb79c1..00000000 --- a/g4f/Provider/Cromicle.py +++ /dev/null @@ -1,50 +0,0 @@ -from __future__ import annotations - -from aiohttp import ClientSession -from hashlib import sha256 -from ..typing import AsyncResult, Messages, Dict - -from .base_provider import AsyncGeneratorProvider -from .helper import format_prompt - - -class Cromicle(AsyncGeneratorProvider): - url: str = 'https://cromicle.top' - working: bool = False - supports_gpt_35_turbo: bool = True - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - **kwargs - ) -> AsyncResult: - async with ClientSession( - headers=_create_header() - ) as session: - async with session.post( - f'{cls.url}/chat', - proxy=proxy, - json=_create_payload(format_prompt(messages)) - ) as response: - response.raise_for_status() - async for stream in response.content.iter_any(): - if stream: - yield stream.decode() - - -def _create_header() -> Dict[str, str]: - return { - 'accept': '*/*', - 'content-type': 'application/json', - } - - -def _create_payload(message: str) -> Dict[str, str]: - return { - 'message': message, - 'token': 'abc', - 'hash': sha256('abc'.encode() + message.encode()).hexdigest() - } \ No newline at end of file diff --git a/g4f/Provider/FreeGpt.py b/g4f/Provider/FreeGpt.py index a3a26fe6..22c6c9aa 100644 --- a/g4f/Provider/FreeGpt.py +++ b/g4f/Provider/FreeGpt.py @@ -12,7 +12,7 @@ domains = [ class FreeGpt(AsyncGeneratorProvider): url = "https://freegpts1.aifree.site/" - working = True + working = False supports_message_history = True supports_gpt_35_turbo = True diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py index a72db45c..70ad9de7 100644 --- a/g4f/Provider/__init__.py +++ b/g4f/Provider/__init__.py @@ -1,9 +1,6 @@ from __future__ import annotations -from .Acytoo import Acytoo from .AiAsk import AiAsk -from .Aibn import Aibn from .Aichat import Aichat -from .Ails import Ails from .AItianhu import AItianhu from .AItianhuSpace import AItianhuSpace from .Berlin import Berlin @@ -13,11 +10,9 @@ from .ChatForAi import ChatForAi from .Chatgpt4Online import Chatgpt4Online from .ChatgptAi import ChatgptAi from .ChatgptDemo import ChatgptDemo -from .ChatgptDuo import ChatgptDuo from .ChatgptFree import ChatgptFree from .ChatgptLogin import ChatgptLogin from .ChatgptX import ChatgptX -from .Cromicle import Cromicle from .DeepInfra import DeepInfra from .FakeGpt import FakeGpt from .FreeGpt import FreeGpt diff --git a/g4f/Provider/deprecated/Acytoo.py b/g4f/Provider/deprecated/Acytoo.py new file mode 100644 index 00000000..0379fdd6 --- /dev/null +++ b/g4f/Provider/deprecated/Acytoo.py @@ -0,0 +1,51 @@ +from __future__ import annotations + +from aiohttp import ClientSession + +from ...typing import AsyncResult, Messages +from ..base_provider import AsyncGeneratorProvider + + +class Acytoo(AsyncGeneratorProvider): + url = 'https://chat.acytoo.com' + working = False + supports_message_history = True + supports_gpt_35_turbo = True + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: Messages, + proxy: str = None, + **kwargs + ) -> AsyncResult: + async with ClientSession( + headers=_create_header() + ) as session: + async with session.post( + f'{cls.url}/api/completions', + proxy=proxy, + json=_create_payload(messages, **kwargs) + ) as response: + response.raise_for_status() + async for stream in response.content.iter_any(): + if stream: + yield stream.decode() + + +def _create_header(): + return { + 'accept': '*/*', + 'content-type': 'application/json', + } + + +def _create_payload(messages: Messages, temperature: float = 0.5, **kwargs): + return { + 'key' : '', + 'model' : 'gpt-3.5-turbo', + 'messages' : messages, + 'temperature' : temperature, + 'password' : '' + } \ No newline at end of file diff --git a/g4f/Provider/deprecated/Aibn.py b/g4f/Provider/deprecated/Aibn.py new file mode 100644 index 00000000..60cef1e4 --- /dev/null +++ b/g4f/Provider/deprecated/Aibn.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +import time +import hashlib + +from ...typing import AsyncResult, Messages +from ...requests import StreamSession +from ..base_provider import AsyncGeneratorProvider + + +class Aibn(AsyncGeneratorProvider): + url = "https://aibn.cc" + working = False + supports_message_history = True + supports_gpt_35_turbo = True + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: Messages, + proxy: str = None, + timeout: int = 120, + **kwargs + ) -> AsyncResult: + async with StreamSession( + impersonate="chrome107", + proxies={"https": proxy}, + timeout=timeout + ) as session: + timestamp = int(time.time()) + data = { + "messages": messages, + "pass": None, + "sign": generate_signature(timestamp, messages[-1]["content"]), + "time": timestamp + } + async with session.post(f"{cls.url}/api/generate", json=data) as response: + response.raise_for_status() + async for chunk in response.iter_content(): + yield chunk.decode() + + @classmethod + @property + def params(cls): + params = [ + ("model", "str"), + ("messages", "list[dict[str, str]]"), + ("stream", "bool"), + ("temperature", "float"), + ] + param = ", ".join([": ".join(p) for p in params]) + return f"g4f.provider.{cls.__name__} supports: ({param})" + + +def generate_signature(timestamp: int, message: str, secret: str = "undefined"): + data = f"{timestamp}:{message}:{secret}" + return hashlib.sha256(data.encode()).hexdigest() \ No newline at end of file diff --git a/g4f/Provider/deprecated/Ails.py b/g4f/Provider/deprecated/Ails.py new file mode 100644 index 00000000..93c63a69 --- /dev/null +++ b/g4f/Provider/deprecated/Ails.py @@ -0,0 +1,101 @@ +from __future__ import annotations + +import hashlib +import time +import uuid +import json +from datetime import datetime +from aiohttp import ClientSession + +from ...typing import SHA256, AsyncResult, Messages +from ..base_provider import AsyncGeneratorProvider + + +class Ails(AsyncGeneratorProvider): + url = "https://ai.ls" + working = False + supports_message_history = True + supports_gpt_35_turbo = True + + @staticmethod + async def create_async_generator( + model: str, + messages: Messages, + stream: bool, + proxy: str = None, + **kwargs + ) -> AsyncResult: + headers = { + "authority": "api.caipacity.com", + "accept": "*/*", + "accept-language": "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3", + "authorization": "Bearer free", + "client-id": str(uuid.uuid4()), + "client-v": "0.1.278", + "content-type": "application/json", + "origin": "https://ai.ls", + "referer": "https://ai.ls/", + "sec-ch-ua": '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Windows"', + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "cross-site", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", + "from-url": "https://ai.ls/?chat=1" + } + async with ClientSession( + headers=headers + ) as session: + timestamp = _format_timestamp(int(time.time() * 1000)) + json_data = { + "model": "gpt-3.5-turbo", + "temperature": kwargs.get("temperature", 0.6), + "stream": True, + "messages": messages, + "d": datetime.now().strftime("%Y-%m-%d"), + "t": timestamp, + "s": _hash({"t": timestamp, "m": messages[-1]["content"]}), + } + async with session.post( + "https://api.caipacity.com/v1/chat/completions", + proxy=proxy, + json=json_data + ) as response: + response.raise_for_status() + start = "data: " + async for line in response.content: + line = line.decode('utf-8') + if line.startswith(start) and line != "data: [DONE]": + line = line[len(start):-1] + line = json.loads(line) + if token := line["choices"][0]["delta"].get("content"): + if "ai.ls" in token or "ai.ci" in token: + raise Exception(f"Response Error: {token}") + yield token + + + @classmethod + @property + def params(cls): + params = [ + ("model", "str"), + ("messages", "list[dict[str, str]]"), + ("stream", "bool"), + ("temperature", "float"), + ] + param = ", ".join([": ".join(p) for p in params]) + return f"g4f.provider.{cls.__name__} supports: ({param})" + + +def _hash(json_data: dict[str, str]) -> SHA256: + base_string: str = f'{json_data["t"]}:{json_data["m"]}:WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf:{len(json_data["m"])}' + + return SHA256(hashlib.sha256(base_string.encode()).hexdigest()) + + +def _format_timestamp(timestamp: int) -> str: + e = timestamp + n = e % 10 + r = n + 1 if n % 2 == 0 else n + return str(e - n + r) \ No newline at end of file diff --git a/g4f/Provider/deprecated/ChatgptDuo.py b/g4f/Provider/deprecated/ChatgptDuo.py new file mode 100644 index 00000000..c77c6a1c --- /dev/null +++ b/g4f/Provider/deprecated/ChatgptDuo.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +from ...typing import Messages +from curl_cffi.requests import AsyncSession +from ..base_provider import AsyncProvider, format_prompt + + +class ChatgptDuo(AsyncProvider): + url = "https://chatgptduo.com" + supports_gpt_35_turbo = True + working = False + + @classmethod + async def create_async( + cls, + model: str, + messages: Messages, + proxy: str = None, + timeout: int = 120, + **kwargs + ) -> str: + async with AsyncSession( + impersonate="chrome107", + proxies={"https": proxy}, + timeout=timeout + ) as session: + prompt = format_prompt(messages), + data = { + "prompt": prompt, + "search": prompt, + "purpose": "ask", + } + response = await session.post(f"{cls.url}/", data=data) + response.raise_for_status() + data = response.json() + + cls._sources = [{ + "title": source["title"], + "url": source["link"], + "snippet": source["snippet"] + } for source in data["results"]] + + return data["answer"] + + @classmethod + def get_sources(cls): + return cls._sources + + @classmethod + @property + def params(cls): + params = [ + ("model", "str"), + ("messages", "list[dict[str, str]]"), + ("stream", "bool"), + ] + param = ", ".join([": ".join(p) for p in params]) + return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file diff --git a/g4f/Provider/deprecated/Cromicle.py b/g4f/Provider/deprecated/Cromicle.py new file mode 100644 index 00000000..9f986cb5 --- /dev/null +++ b/g4f/Provider/deprecated/Cromicle.py @@ -0,0 +1,50 @@ +from __future__ import annotations + +from aiohttp import ClientSession +from hashlib import sha256 +from ...typing import AsyncResult, Messages, Dict + +from ..base_provider import AsyncGeneratorProvider +from ..helper import format_prompt + + +class Cromicle(AsyncGeneratorProvider): + url: str = 'https://cromicle.top' + working: bool = False + supports_gpt_35_turbo: bool = True + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: Messages, + proxy: str = None, + **kwargs + ) -> AsyncResult: + async with ClientSession( + headers=_create_header() + ) as session: + async with session.post( + f'{cls.url}/chat', + proxy=proxy, + json=_create_payload(format_prompt(messages)) + ) as response: + response.raise_for_status() + async for stream in response.content.iter_any(): + if stream: + yield stream.decode() + + +def _create_header() -> Dict[str, str]: + return { + 'accept': '*/*', + 'content-type': 'application/json', + } + + +def _create_payload(message: str) -> Dict[str, str]: + return { + 'message': message, + 'token': 'abc', + 'hash': sha256('abc'.encode() + message.encode()).hexdigest() + } \ No newline at end of file diff --git a/g4f/Provider/deprecated/__init__.py b/g4f/Provider/deprecated/__init__.py index f8e35b37..ca5ac83e 100644 --- a/g4f/Provider/deprecated/__init__.py +++ b/g4f/Provider/deprecated/__init__.py @@ -13,4 +13,9 @@ from .FastGpt import FastGpt from .Aivvm import Aivvm from .Vitalentum import Vitalentum from .H2o import H2o -from .Myshell import Myshell \ No newline at end of file +from .Myshell import Myshell +from .Acytoo import Acytoo +from .Aibn import Aibn +from .Ails import Ails +from .ChatgptDuo import ChatgptDuo +from .Cromicle import Cromicle \ No newline at end of file -- cgit v1.2.3