From 88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Thu, 5 Oct 2023 05:13:37 +0200 Subject: Add AiAsk, Chatgpt4Online, ChatgptDemo and ChatgptX Provider Fix Bing, Liaobots and ChatgptAi Provider Add "gpt_35_long" model and custom timeout --- g4f/Provider/Yqcloud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'g4f/Provider/Yqcloud.py') diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py index ac93315c..1b22de9e 100644 --- a/g4f/Provider/Yqcloud.py +++ b/g4f/Provider/Yqcloud.py @@ -16,10 +16,11 @@ class Yqcloud(AsyncGeneratorProvider): model: str, messages: list[dict[str, str]], proxy: str = None, + timeout: int = 30, **kwargs, ) -> AsyncGenerator: async with ClientSession( - headers=_create_header() + headers=_create_header(), timeout=timeout ) as session: payload = _create_payload(messages) async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response: -- cgit v1.2.3 From 4fa6e9c0f597c07d2acf10732fe2aeda270c6ca6 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 7 Oct 2023 09:02:48 +0200 Subject: Add GptGod Provider Remove timeout from aiohttp providers Disable Opchatgpts and ChatgptLogin provider --- g4f/Provider/Yqcloud.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'g4f/Provider/Yqcloud.py') diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py index 1b22de9e..ac93315c 100644 --- a/g4f/Provider/Yqcloud.py +++ b/g4f/Provider/Yqcloud.py @@ -16,11 +16,10 @@ class Yqcloud(AsyncGeneratorProvider): model: str, messages: list[dict[str, str]], proxy: str = None, - timeout: int = 30, **kwargs, ) -> AsyncGenerator: async with ClientSession( - headers=_create_header(), timeout=timeout + headers=_create_header() ) as session: payload = _create_payload(messages) async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response: -- cgit v1.2.3 From 4a9d7714adab375beda9db2a16bb34d139efef90 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 8 Oct 2023 11:39:19 +0200 Subject: Add Cromicle to provider list --- g4f/Provider/Yqcloud.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'g4f/Provider/Yqcloud.py') diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py index ac93315c..74c998e2 100644 --- a/g4f/Provider/Yqcloud.py +++ b/g4f/Provider/Yqcloud.py @@ -26,6 +26,9 @@ class Yqcloud(AsyncGeneratorProvider): response.raise_for_status() async for stream in response.content.iter_any(): if stream: + stream = stream.decode() + if "sorry, 您的ip已由于触发防滥用检测而被封禁" in stream: + raise RuntimeError("IP address is blocked by abuse detection.") yield stream.decode() -- cgit v1.2.3 From 6401084fd0d23b75a883888f70cd705e4cacd202 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 8 Oct 2023 13:59:56 +0200 Subject: Add Messages and AsyncResult typing Add system_message in Yqcloud --- g4f/Provider/Yqcloud.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'g4f/Provider/Yqcloud.py') diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py index 74c998e2..0e96e20f 100644 --- a/g4f/Provider/Yqcloud.py +++ b/g4f/Provider/Yqcloud.py @@ -1,8 +1,9 @@ from __future__ import annotations +import random from aiohttp import ClientSession -from ..typing import AsyncGenerator +from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider, format_prompt @@ -14,22 +15,22 @@ class Yqcloud(AsyncGeneratorProvider): @staticmethod async def create_async_generator( model: str, - messages: list[dict[str, str]], + messages: Messages, proxy: str = None, **kwargs, - ) -> AsyncGenerator: + ) -> AsyncResult: async with ClientSession( headers=_create_header() ) as session: - payload = _create_payload(messages) + payload = _create_payload(messages, **kwargs) async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response: response.raise_for_status() - async for stream in response.content.iter_any(): - if stream: - stream = stream.decode() - if "sorry, 您的ip已由于触发防滥用检测而被封禁" in stream: + async for chunk in response.content.iter_any(): + if chunk: + chunk = chunk.decode() + if "sorry, 您的ip已由于触发防滥用检测而被封禁" in chunk: raise RuntimeError("IP address is blocked by abuse detection.") - yield stream.decode() + yield chunk def _create_header(): @@ -40,12 +41,19 @@ def _create_header(): } -def _create_payload(messages: list[dict[str, str]]): +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": system_message, "withoutContext": False, "stream": True, - "userId": "#/chat/1693025544336" + "userId": f"#/chat/{user_id}" } -- cgit v1.2.3