summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2023-11-18 04:38:31 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2023-11-18 04:38:31 +0100
commitcadc507fad2fee59b23d1d8e73c472c077f468fc (patch)
tree42b1c0c0ccf5e3aa7a843a3766d4d19b6a7ade8e /g4f/Provider/helper.py
parentImprove providers (diff)
downloadgpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar.gz
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar.bz2
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar.lz
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar.xz
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.tar.zst
gpt4free-cadc507fad2fee59b23d1d8e73c472c077f468fc.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