From 3982f39424ea037aca1086d45c6f657b4bfc457c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=B2=98r=E1=B9=A8h=E0=B8=AA=E2=88=82ow?= <71973368+MrShadowDev@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:46:25 +0200 Subject: 'Refactored by Sourcery' (#1125) Co-authored-by: Sourcery AI <> --- etc/testing/log_time.py | 8 +-- etc/testing/test_providers.py | 12 ++--- etc/tool/create_provider.py | 8 ++- etc/tool/improve_code.py | 6 +-- etc/tool/readme_table.py | 2 +- etc/tool/vercel.py | 6 +-- g4f/Provider/AItianhu.py | 36 ++++++------- g4f/Provider/AItianhuSpace.py | 23 +++++---- g4f/Provider/Aichat.py | 18 ++++--- g4f/Provider/Ails.py | 24 ++++----- g4f/Provider/Bing.py | 90 ++++++++++++++++++--------------- g4f/Provider/ChatBase.py | 20 ++++---- g4f/Provider/Chatgpt4Online.py | 4 +- g4f/Provider/ChatgptAi.py | 13 +++-- g4f/Provider/ChatgptDemo.py | 12 +++-- g4f/Provider/ChatgptFree.py | 35 +++++++------ g4f/Provider/ChatgptLogin.py | 14 +++-- g4f/Provider/ChatgptX.py | 15 +++--- g4f/Provider/GPTalk.py | 6 +-- g4f/Provider/GptChatly.py | 10 ++-- g4f/Provider/GptForLove.py | 7 +-- g4f/Provider/GptGo.py | 35 +++++++------ g4f/Provider/GptGod.py | 7 ++- g4f/Provider/Liaobots.py | 2 +- g4f/Provider/Vercel.py | 66 +++++++++++------------- g4f/Provider/Ylokh.py | 18 +++---- g4f/Provider/deprecated/AiService.py | 9 ++-- g4f/Provider/deprecated/CodeLinkAva.py | 23 ++++----- g4f/Provider/deprecated/EasyChat.py | 40 +++++++-------- g4f/Provider/deprecated/Equing.py | 11 ++-- g4f/Provider/deprecated/FastGpt.py | 13 ++--- g4f/Provider/deprecated/H2o.py | 2 +- g4f/Provider/deprecated/Lockchat.py | 7 ++- g4f/Provider/deprecated/V50.py | 21 +++++--- g4f/Provider/deprecated/Vitalentum.py | 23 ++++----- g4f/Provider/deprecated/Wuguokai.py | 19 ++++--- g4f/Provider/helper.py | 22 ++++---- g4f/Provider/needs_auth/Bard.py | 14 ++--- g4f/Provider/needs_auth/Raycast.py | 10 ++-- g4f/Provider/needs_auth/Theb.py | 40 +++++++-------- g4f/Provider/unfinished/ChatAiGpt.py | 8 +-- g4f/Provider/unfinished/MikuChat.py | 3 +- g4f/Provider/unfinished/PerplexityAi.py | 2 +- g4f/__init__.py | 2 +- g4f/api/__init__.py | 12 ++--- g4f/gui/server/backend.py | 25 ++++----- g4f/gui/server/internet.py | 13 +++-- g4f/gui/server/provider.py | 14 +++-- g4f/gui/server/website.py | 6 +-- g4f/requests.py | 5 +- 50 files changed, 414 insertions(+), 427 deletions(-) diff --git a/etc/testing/log_time.py b/etc/testing/log_time.py index 376ab86d..79997a61 100644 --- a/etc/testing/log_time.py +++ b/etc/testing/log_time.py @@ -5,9 +5,7 @@ async def log_time_async(method: callable, **kwargs): start = time() result = await method(**kwargs) secs = f"{round(time() - start, 2)} secs" - if result: - return " ".join([result, secs]) - return secs + return " ".join([result, secs]) if result else secs def log_time_yield(method: callable, **kwargs): @@ -20,6 +18,4 @@ def log_time(method: callable, **kwargs): start = time() result = method(**kwargs) secs = f"{round(time() - start, 2)} secs" - if result: - return " ".join([result, secs]) - return secs \ No newline at end of file + return " ".join([result, secs]) if result else secs \ No newline at end of file diff --git a/etc/testing/test_providers.py b/etc/testing/test_providers.py index 0eaad3e8..8c444d34 100644 --- a/etc/testing/test_providers.py +++ b/etc/testing/test_providers.py @@ -22,11 +22,11 @@ def test_provider(provider): return None with concurrent.futures.ThreadPoolExecutor() as executor: - futures = [] - for provider in __all__: - if provider not in _: - futures.append(executor.submit(test_provider, provider)) + futures = [ + executor.submit(test_provider, provider) + for provider in __all__ + if provider not in _ + ] for future in concurrent.futures.as_completed(futures): - result = future.result() - if result: + if result := future.result(): print(f'{result[1]} | {result[0]}') \ No newline at end of file diff --git a/etc/tool/create_provider.py b/etc/tool/create_provider.py index abae8f96..361448e4 100644 --- a/etc/tool/create_provider.py +++ b/etc/tool/create_provider.py @@ -8,8 +8,7 @@ sys.path.append(str(Path(__file__).parent.parent.parent)) import g4f def read_code(text): - match = re.search(r"```(python|py|)\n(?P[\S\s]+?)\n```", text) - if match: + if match := re.search(r"```(python|py|)\n(?P[\S\s]+?)\n```", text): return match.group("code") def input_command(): @@ -99,12 +98,11 @@ And replace "gpt-3.5-turbo" with `model`. print() response = "".join(response) - code = read_code(response) - if code: + if code := read_code(response): with open(provider_path, "w") as file: file.write(code) print("Saved at:", provider_path) - with open(f"g4f/Provider/__init__.py", "a") as file: + with open("g4f/Provider/__init__.py", "a") as file: file.write(f"\nfrom .{name} import {name}") else: with open(provider_path, "r") as file: diff --git a/etc/tool/improve_code.py b/etc/tool/improve_code.py index 9a940b51..b2e36f86 100644 --- a/etc/tool/improve_code.py +++ b/etc/tool/improve_code.py @@ -8,8 +8,7 @@ sys.path.append(str(Path(__file__).parent.parent.parent)) import g4f def read_code(text): - match = re.search(r"```(python|py|)\n(?P[\S\s]+?)\n```", text) - if match: + if match := re.search(r"```(python|py|)\n(?P[\S\s]+?)\n```", text): return match.group("code") path = input("Path: ") @@ -41,7 +40,6 @@ for chunk in g4f.ChatCompletion.create( print() response = "".join(response) -code = read_code(response) -if code: +if code := read_code(response): with open(path, "w") as file: file.write(code) \ No newline at end of file diff --git a/etc/tool/readme_table.py b/etc/tool/readme_table.py index db02f6ec..c7eb3caf 100644 --- a/etc/tool/readme_table.py +++ b/etc/tool/readme_table.py @@ -52,7 +52,7 @@ async def test_async(provider: type[BaseProvider]): response = await provider.create_async(model=model, messages=messages) else: response = provider.create_completion(model=model, messages=messages, stream=False) - return True if response else False + return bool(response) except Exception as e: if logging: print(f"{provider.__name__}: {e.__class__.__name__}: {e}") diff --git a/etc/tool/vercel.py b/etc/tool/vercel.py index 7b87e298..29856bb3 100644 --- a/etc/tool/vercel.py +++ b/etc/tool/vercel.py @@ -22,11 +22,9 @@ def get_model_info() -> dict[str, Any]: urls = [f"{url}/_next/{path}" for path in paths] scripts = [session.get(url).text for url in urls] + models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.=' for script in scripts: - models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.=' - matches = re.findall(models_regex, script) - - if matches: + if matches := re.findall(models_regex, script): models_str = matches[0] stop_sequences_regex = r"(?<=stopSequences:{value:\[)\D(?": raise RuntimeError("Solve challenge and pass cookies") - + if b"platform's risk control" in line: raise RuntimeError("Platform's Risk Control") - + line = json.loads(line) - - if "detail" in line: - content = line["detail"]["choices"][0]["delta"].get("content") - if content: - yield content - else: + + if "detail" not in line: raise RuntimeError(f"Response: {line}") + if content := line["detail"]["choices"][0]["delta"].get( + "content" + ): + yield content @classmethod diff --git a/g4f/Provider/AItianhuSpace.py b/g4f/Provider/AItianhuSpace.py index 46856060..d316fc6f 100644 --- a/g4f/Provider/AItianhuSpace.py +++ b/g4f/Provider/AItianhuSpace.py @@ -27,26 +27,26 @@ class AItianhuSpace(AsyncGeneratorProvider): if not model: model = "gpt-3.5-turbo" - - elif not model in domains: + + elif model not 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 debug.logging: print(f"AItianhuSpace | using domain: {domain}") - + if not cookies: cookies = get_cookies('.aitianhu.space') - if not cookies: - raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies [refresh https://{domain} on chrome]") - + if not 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: + cookies=cookies, timeout=timeout, impersonate="chrome110", verify=False) as session: data = { "prompt": format_prompt(messages), @@ -71,8 +71,9 @@ class AItianhuSpace(AsyncGeneratorProvider): raise RuntimeError("Platform's Risk Control") line = json.loads(line) if "detail" in line: - content = line["detail"]["choices"][0]["delta"].get("content") - if content: + if content := line["detail"]["choices"][0]["delta"].get( + "content" + ): yield content elif "message" in line and "AI-4接口非常昂贵" in line["message"]: raise RuntimeError("Rate limit for GPT 4 reached") diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py index d32c99e1..77ae4429 100644 --- a/g4f/Provider/Aichat.py +++ b/g4f/Provider/Aichat.py @@ -20,8 +20,10 @@ class Aichat(AsyncProvider): cookies = get_cookies('chat-gpt.org') if not kwargs.get('cookies') else kwargs.get('cookies') if not cookies: - raise RuntimeError(f"g4f.provider.Aichat requires cookies, [refresh https://chat-gpt.org on chrome]") - + raise RuntimeError( + "g4f.provider.Aichat requires cookies, [refresh https://chat-gpt.org on chrome]" + ) + headers = { 'authority': 'chat-gpt.org', 'accept': '*/*', @@ -37,13 +39,13 @@ class Aichat(AsyncProvider): 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', } - + async with StreamSession(headers=headers, cookies=cookies, timeout=6, proxies={"https": proxy} if proxy else None, impersonate="chrome110", verify=False) as session: - + json_data = { "message": format_prompt(messages), "temperature": kwargs.get('temperature', 0.5), @@ -51,14 +53,14 @@ class Aichat(AsyncProvider): "top_p": kwargs.get('top_p', 1), "frequency_penalty": 0, } - + async with session.post("https://chat-gpt.org/api/text", json=json_data) as response: - + response.raise_for_status() result = await response.json() - + if not result['response']: raise Exception(f"Error Response: {result}") - + return result["message"] diff --git a/g4f/Provider/Ails.py b/g4f/Provider/Ails.py index 4d072646..fae3e62a 100644 --- a/g4f/Provider/Ails.py +++ b/g4f/Provider/Ails.py @@ -44,8 +44,8 @@ class Ails(AsyncGeneratorProvider): "from-url": "https://ai.ls/?chat=1" } async with ClientSession( - headers=headers - ) as session: + headers=headers + ) as session: timestamp = _format_timestamp(int(time.time() * 1000)) json_data = { "model": "gpt-3.5-turbo", @@ -57,10 +57,10 @@ class Ails(AsyncGeneratorProvider): "s": _hash({"t": timestamp, "m": messages[-1]["content"]}), } async with session.post( - "https://api.caipacity.com/v1/chat/completions", - proxy=proxy, - json=json_data - ) as response: + "https://api.caipacity.com/v1/chat/completions", + proxy=proxy, + json=json_data + ) as response: response.raise_for_status() start = "data: " async for line in response.content: @@ -68,10 +68,9 @@ class Ails(AsyncGeneratorProvider): if line.startswith(start) and line != "data: [DONE]": line = line[len(start):-1] line = json.loads(line) - token = line["choices"][0]["delta"].get("content") - if token: + if token := line["choices"][0]["delta"].get("content"): if "ai.ls" in token or "ai.ci" in token: - raise Exception("Response Error: " + token) + raise Exception(f"Response Error: {token}") yield token @@ -89,12 +88,7 @@ class Ails(AsyncGeneratorProvider): def _hash(json_data: dict[str, str]) -> SHA256: - base_string: str = "%s:%s:%s:%s" % ( - json_data["t"], - json_data["m"], - "WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf", - len(json_data["m"]), - ) + base_string: str = f'{json_data["t"]}:{json_data["m"]}:WI,2rU#_r:r~aF4aJ36[.Z(/8Rv93Rf:{len(json_data["m"])}' return SHA256(hashlib.sha256(base_string.encode()).hexdigest()) diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index 91e9dc2c..ae7f106b 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -56,9 +56,10 @@ class Bing(AsyncGeneratorProvider): return stream_generate(prompt, tone, image, context, proxy, cookies) def create_context(messages: Messages): - context = "".join(f"[{message['role']}](#message)\n{message['content']}\n\n" for message in messages) - - return context + return "".join( + f"[{message['role']}](#message)\n{message['content']}\n\n" + for message in messages + ) class Conversation(): def __init__(self, conversationId: str, clientId: str, conversationSignature: str, imageInfo: dict=None) -> None: @@ -71,7 +72,7 @@ async def create_conversation(session: ClientSession, tone: str, image: str = No url = 'https://www.bing.com/turing/conversation/create?bundleVersion=1.1199.4' async with await session.get(url, proxy=proxy) as response: data = await response.json() - + conversationId = data.get('conversationId') clientId = data.get('clientId') conversationSignature = response.headers.get('X-Sydney-Encryptedconversationsignature') @@ -110,30 +111,30 @@ async def create_conversation(session: ClientSession, tone: str, image: str = No new_img_binary_data = compress_image_to_base64(new_img, compression_rate) data, boundary = build_image_upload_api_payload(new_img_binary_data, conversation, tone) headers = session.headers.copy() - headers["content-type"] = 'multipart/form-data; boundary=' + boundary + headers["content-type"] = f'multipart/form-data; boundary={boundary}' headers["referer"] = 'https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx' headers["origin"] = 'https://www.bing.com' async with await session.post("https://www.bing.com/images/kblob", data=data, headers=headers, proxy=proxy) as image_upload_response: - if image_upload_response.status == 200: - image_info = await image_upload_response.json() - result = {} - if image_info.get('blobId'): - result['bcid'] = image_info.get('blobId', "") - result['blurredBcid'] = image_info.get('processedBlobId', "") - if result['blurredBcid'] != "": - result["imageUrl"] = "https://www.bing.com/images/blob?bcid=" + result['blurredBcid'] - elif result['bcid'] != "": - result["imageUrl"] = "https://www.bing.com/images/blob?bcid=" + result['bcid'] - if config['visualSearch']["enableFaceBlurDebug"]: - result['originalImageUrl'] = "https://www.bing.com/images/blob?bcid=" + result['blurredBcid'] - else: - result['originalImageUrl'] = "https://www.bing.com/images/blob?bcid=" + result['bcid'] - conversation.imageInfo = result - else: - raise Exception("Failed to parse image info.") - else: + if image_upload_response.status != 200: raise Exception("Failed to upload image.") + image_info = await image_upload_response.json() + if not image_info.get('blobId'): + raise Exception("Failed to parse image info.") + result = {'bcid': image_info.get('blobId', "")} + result['blurredBcid'] = image_info.get('processedBlobId', "") + if result['blurredBcid'] != "": + result["imageUrl"] = "https://www.bing.com/images/blob?bcid=" + result['blurredBcid'] + elif result['bcid'] != "": + result["imageUrl"] = "https://www.bing.com/images/blob?bcid=" + result['bcid'] + result['originalImageUrl'] = ( + "https://www.bing.com/images/blob?bcid=" + + result['blurredBcid'] + if config['visualSearch']["enableFaceBlurDebug"] + else "https://www.bing.com/images/blob?bcid=" + + result['bcid'] + ) + conversation.imageInfo = result except Exception as e: print(f"An error happened while trying to send image: {str(e)}") return conversation @@ -282,7 +283,18 @@ def build_image_upload_api_payload(image_bin: str, conversation: Conversation, t 'knowledgeRequest': payload } boundary="----WebKitFormBoundary" + ''.join(random.choices(string.ascii_letters + string.digits, k=16)) - data = '--' + boundary + '\r\nContent-Disposition: form-data; name="knowledgeRequest"\r\n\r\n' + json.dumps(knowledge_request,ensure_ascii=False) + "\r\n--" + boundary + '\r\nContent-Disposition: form-data; name="imageBase64"\r\n\r\n' + image_bin + "\r\n--" + boundary + "--\r\n" + data = ( + f'--{boundary}' + + '\r\nContent-Disposition: form-data; name="knowledgeRequest"\r\n\r\n' + + json.dumps(knowledge_request, ensure_ascii=False) + + "\r\n--" + + boundary + + '\r\nContent-Disposition: form-data; name="imageBase64"\r\n\r\n' + + image_bin + + "\r\n--" + + boundary + + "--\r\n" + ) return data, boundary def is_data_uri_an_image(data_uri): @@ -329,7 +341,7 @@ def extract_data_uri(data_uri): def get_orientation(data: bytes): try: - if data[0:2] != b'\xFF\xD8': + if data[:2] != b'\xFF\xD8': raise Exception('NotJpeg') with Image.open(data) as img: exif_data = img._getexif() @@ -347,11 +359,11 @@ def process_image(orientation, img, new_width, new_height): if orientation: if orientation > 4: img = img.transpose(Image.FLIP_LEFT_RIGHT) - if orientation == 3 or orientation == 4: + if orientation in [3, 4]: img = img.transpose(Image.ROTATE_180) - if orientation == 5 or orientation == 6: + if orientation in [5, 6]: img = img.transpose(Image.ROTATE_270) - if orientation == 7 or orientation == 8: + if orientation in [7, 8]: img = img.transpose(Image.ROTATE_90) new_img.paste(img, (0, 0)) return new_img @@ -362,8 +374,7 @@ def compress_image_to_base64(img, compression_rate): try: output_buffer = io.BytesIO() img.save(output_buffer, format="JPEG", quality=int(compression_rate * 100)) - base64_image = base64.b64encode(output_buffer.getvalue()).decode('utf-8') - return base64_image + return base64.b64encode(output_buffer.getvalue()).decode('utf-8') except Exception as e: raise e @@ -425,19 +436,14 @@ async def stream_generate( cookies: dict = None ): async with ClientSession( - timeout=ClientTimeout(total=900), - cookies=cookies, - headers=Defaults.headers, - ) as session: + timeout=ClientTimeout(total=900), + cookies=cookies, + headers=Defaults.headers, + ) as session: conversation = await create_conversation(session, tone, image, proxy) try: - async with session.ws_connect( - f'wss://sydney.bing.com/sydney/ChatHub', - autoping=False, - params={'sec_access_token': conversation.conversationSignature}, - proxy=proxy - ) as wss: - + async with session.ws_connect('wss://sydney.bing.com/sydney/ChatHub', autoping=False, params={'sec_access_token': conversation.conversationSignature}, proxy=proxy) as wss: + await wss.send_str(format_message({'protocol': 'json', 'version': 1})) await wss.receive(timeout=900) await wss.send_str(create_message(conversation, prompt, tone, context)) @@ -451,7 +457,7 @@ async def stream_generate( for obj in objects: if obj is None or not obj: continue - + response = json.loads(obj) if response.get('type') == 1 and response['arguments'][0].get('messages'): message = response['arguments'][0]['messages'][0] diff --git a/g4f/Provider/ChatBase.py b/g4f/Provider/ChatBase.py index 3d45b40b..8f9e2aad 100644 --- a/g4f/Provider/ChatBase.py +++ b/g4f/Provider/ChatBase.py @@ -20,16 +20,16 @@ class ChatBase(AsyncGeneratorProvider): **kwargs ) -> AsyncResult: chat_id = 'z2c2HSfKnCTh5J4650V0I' - + headers = { - "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", - "Accept" : "*/*", - "Accept-language" : "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3", - "Origin" : cls.url, - "Referer" : cls.url + "/", - "Sec-Fetch-Dest" : "empty", - "Sec-Fetch-Mode" : "cors", - "Sec-Fetch-Site" : "same-origin", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", + "Accept": "*/*", + "Accept-language": "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3", + "Origin": cls.url, + "Referer": f"{cls.url}/", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", } async with ClientSession(headers=headers) as session: data = { @@ -38,7 +38,7 @@ class ChatBase(AsyncGeneratorProvider): "chatId": chat_id, "conversationId": f"kcXpqEnqUie3dnJlsRi_O-{chat_id}" } - + async with session.post("https://www.chatbase.co/api/fe/chat", json=data, proxy=proxy) as response: response.raise_for_status() async for stream in response.content.iter_any(): diff --git a/g4f/Provider/Chatgpt4Online.py b/g4f/Provider/Chatgpt4Online.py index 25208067..e81c8d4c 100644 --- a/g4f/Provider/Chatgpt4Online.py +++ b/g4f/Provider/Chatgpt4Online.py @@ -31,8 +31,8 @@ class Chatgpt4Online(AsyncGeneratorProvider): "newMessage": messages[-1]["content"], "stream": True } - - async with session.post(cls.url + "/wp-json/mwai-ui/v1/chats/submit", json=data, proxy=proxy) as response: + + async with session.post(f"{cls.url}/wp-json/mwai-ui/v1/chats/submit", json=data, proxy=proxy) as response: response.raise_for_status() async for line in response.content: if line.startswith(b"data: "): diff --git a/g4f/Provider/ChatgptAi.py b/g4f/Provider/ChatgptAi.py index d5fd5bff..9783d868 100644 --- a/g4f/Provider/ChatgptAi.py +++ b/g4f/Provider/ChatgptAi.py @@ -38,18 +38,17 @@ class ChatgptAi(AsyncGeneratorProvider): "user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", } async with ClientSession( - headers=headers - ) as session: + headers=headers + ) as session: if not cls._system: async with session.get(cls.url, proxy=proxy) as response: response.raise_for_status() text = await response.text() - result = re.search(r"data-system='(.*?)'", text) - if result: + if result := re.search(r"data-system='(.*?)'", text): cls._system = json.loads(html.unescape(result.group(1))) - if not cls._system: - raise RuntimeError("System args not found") - + if not cls._system: + raise RuntimeError("System args not found") + data = { "botId": cls._system["botId"], "customId": cls._system["customId"], diff --git a/g4f/Provider/ChatgptDemo.py b/g4f/Provider/ChatgptDemo.py index 9efa89ba..bc592ca6 100644 --- a/g4f/Provider/ChatgptDemo.py +++ b/g4f/Provider/ChatgptDemo.py @@ -37,10 +37,13 @@ class ChatgptDemo(AsyncGeneratorProvider): async with session.get(f"{cls.url}/", proxy=proxy) as response: response.raise_for_status() response = await response.text() - result = re.search(r'