summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/AItianhuSpace.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/AItianhuSpace.py')
-rw-r--r--g4f/Provider/AItianhuSpace.py33
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)