diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-10-05 20:06:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 20:06:21 +0200 |
commit | a59dc2fb36b42be735d52db24016f29f09cefff6 (patch) | |
tree | 76240685a9dcc320535cf0ffb3a5b931b2a14b72 /g4f/Provider/AItianhuSpace.py | |
parent | ~ | Merge pull request #984 from HexyeDEV/patch-2 (diff) | |
parent | Merge branch 'main' into bom (diff) | |
download | gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar.gz gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar.bz2 gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar.lz gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar.xz gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.tar.zst gpt4free-a59dc2fb36b42be735d52db24016f29f09cefff6.zip |
Diffstat (limited to '')
-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) |