diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-05 05:13:37 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-05 05:13:37 +0200 |
commit | 88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9 (patch) | |
tree | 7e6e3b6c179cf1a695f9d80026d544a4fd3c5203 /g4f/Provider/AItianhuSpace.py | |
parent | ~ | g4f v-0.1.4.8 - Fixed `g4f.Provider.Bing` (diff) | |
download | gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.gz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.bz2 gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.lz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.xz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.zst gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.zip |
Diffstat (limited to 'g4f/Provider/AItianhuSpace.py')
-rw-r--r-- | g4f/Provider/AItianhuSpace.py | 33 |
1 files changed, 22 insertions, 11 deletions
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"<script>": - raise RuntimeError("Solve Challenge") + raise RuntimeError("Solve challenge and pass cookies and a fixed domain") if b"platform's risk control" in line: raise RuntimeError("Platform's Risk Control") line = json.loads(line) |