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/AItianhuSpace.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'g4f/Provider/AItianhuSpace.py') diff --git a/g4f/Provider/AItianhuSpace.py b/g4f/Provider/AItianhuSpace.py index 27f2b1fa..78cdf657 100644 --- a/g4f/Provider/AItianhuSpace.py +++ b/g4f/Provider/AItianhuSpace.py @@ -4,11 +4,11 @@ import random, json from ..typing import AsyncGenerator from ..requests import StreamSession -from .base_provider import AsyncGeneratorProvider, format_prompt +from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies domains = { - "gpt-3.5-turbo": ".aitianhu.space", - "gpt-4": ".aitianhu.website", + "gpt-3.5-turbo": "aitianhu.space", + "gpt-4": "aitianhu.website", } class AItianhuSpace(AsyncGeneratorProvider): @@ -21,20 +21,31 @@ class AItianhuSpace(AsyncGeneratorProvider): cls, model: str, messages: list[dict[str, str]], - stream: bool = True, + proxy: str = None, + domain: str = None, + cookies: dict = None, + timeout: int = 30, **kwargs ) -> AsyncGenerator: if not model: model = "gpt-3.5-turbo" elif not model in domains: raise ValueError(f"Model are not supported: {model}") + if not domain: + chars = 'abcdefghijklmnopqrstuvwxyz0123456789' + rand = ''.join(random.choice(chars) for _ in range(6)) + domain = f"{rand}.{domains[model]}" + if not cookies: + cookies = get_cookies(domain) - chars = 'abcdefghijklmnopqrstuvwxyz0123456789' - rand = ''.join(random.choice(chars) for _ in range(6)) - domain = domains[model] - url = f'https://{rand}{domain}' - - async with StreamSession(impersonate="chrome110", verify=False) as session: + url = f'https://{domain}' + async with StreamSession( + proxies={"https": proxy}, + cookies=cookies, + timeout=timeout, + impersonate="chrome110", + verify=False + ) as session: data = { "prompt": format_prompt(messages), "options": {}, @@ -53,7 +64,7 @@ class AItianhuSpace(AsyncGeneratorProvider): response.raise_for_status() async for line in response.iter_lines(): if line == b"