From cadc507fad2fee59b23d1d8e73c472c077f468fc Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 18 Nov 2023 04:38:31 +0100 Subject: Add AiChatOnline, ChatgptDemoAi, ChatgptNext Providers Add OnlineGpt and TalkAi Provider Add get_random_string and get_random_hex helper Remove funcaptcha package --- g4f/Provider/helper.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'g4f/Provider/helper.py') diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py index f879816a..c420dee3 100644 --- a/g4f/Provider/helper.py +++ b/g4f/Provider/helper.py @@ -3,6 +3,9 @@ from __future__ import annotations import sys import asyncio import webbrowser +import random +import string +import secrets from os import path from asyncio import AbstractEventLoop from platformdirs import user_config_dir @@ -120,12 +123,10 @@ def get_cookies(domain_name=''): def format_prompt(messages: Messages, add_special_tokens=False) -> str: if not add_special_tokens and len(messages) <= 1: return messages[0]["content"] - formatted = "\n".join( - [ - f'{message["role"].capitalize()}: {message["content"]}' - for message in messages - ] - ) + formatted = "\n".join([ + f'{message["role"].capitalize()}: {message["content"]}' + for message in messages + ]) return f"{formatted}\nAssistant:" @@ -137,10 +138,19 @@ def get_browser( ) -> Chrome: if user_data_dir == None: user_data_dir = user_config_dir("g4f") - if proxy: if not options: options = ChromeOptions() options.add_argument(f'--proxy-server={proxy}') + return Chrome(options=options, user_data_dir=user_data_dir, headless=headless) + + +def get_random_string(length: int = 10) -> str: + return ''.join( + random.choice(string.ascii_lowercase + string.digits) + for _ in range(length) + ) + - return Chrome(user_data_dir=user_data_dir, options=options, headless=headless) \ No newline at end of file +def get_random_hex() -> str: + return secrets.token_hex(16).zfill(32) \ No newline at end of file -- cgit v1.2.3