From ae8dae82cffb07eeeecc5b07ffc9b502e92bfe62 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Sat, 21 Oct 2023 00:52:19 +0100 Subject: ~ | g4f `v-0.1.7.2` patch / unpatch providers --- g4f/Provider/AItianhuSpace.py | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'g4f/Provider/AItianhuSpace.py') diff --git a/g4f/Provider/AItianhuSpace.py b/g4f/Provider/AItianhuSpace.py index 7811c9c8..51297bcd 100644 --- a/g4f/Provider/AItianhuSpace.py +++ b/g4f/Provider/AItianhuSpace.py @@ -1,9 +1,9 @@ from __future__ import annotations import random, json - -from ..typing import AsyncResult, Messages -from ..requests import StreamSession +from ..debug import logging +from ..typing import AsyncResult, Messages +from ..requests import StreamSession from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies domains = { @@ -17,37 +17,37 @@ class AItianhuSpace(AsyncGeneratorProvider): supports_gpt_35_turbo = True @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - domain: str = None, - cookies: dict = None, - timeout: int = 120, - **kwargs - ) -> AsyncResult: + async def create_async_generator(cls, + model: str, + messages: Messages, + proxy: str = None, + domain: str = None, + cookies: dict = None, + timeout: int = 10, **kwargs) -> AsyncResult: + 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 logging: + print(f"AItianhuSpace | using domain: {domain}") + if not cookies: - cookies = get_cookies(domain) + cookies = get_cookies('.aitianhu.space') if not cookies: - raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies") + raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies [refresh https://{domain} on chrome]") url = f'https://{domain}' - async with StreamSession( - proxies={"https": proxy}, - cookies=cookies, - timeout=timeout, - impersonate="chrome110", - verify=False - ) as session: + async with StreamSession(proxies={"https": proxy}, + cookies=cookies, timeout=timeout, impersonate="chrome110", verify=False) as session: + data = { "prompt": format_prompt(messages), "options": {}, -- cgit v1.2.3