summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-11-18 12:24:39 +0100
committerGitHub <noreply@github.com>2023-11-18 12:24:39 +0100
commit2fcb3f949bbde7f5380acc68dc6b1f938dec12bc (patch)
tree035bd400b4057a744b29a0ebee96579bfbf429f6 /g4f/Provider/helper.py
parent~ | g4f `v-0.1.8.5` (diff)
parentAdd AiChatOnline, ChatgptDemoAi, ChatgptNext Providers (diff)
downloadgpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.gz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.bz2
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.lz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.xz
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.zst
gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.zip
Diffstat (limited to 'g4f/Provider/helper.py')
-rw-r--r--g4f/Provider/helper.py26
1 files changed, 18 insertions, 8 deletions
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