summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-03 23:04:10 +0200
committerGitHub <noreply@github.com>2023-10-03 23:04:10 +0200
commitd9e527eb327e6e991435332b20f15b30c596ba0d (patch)
tree0616d74ff183e905cc81e97c44326f73d06c5b93 /g4f/Provider/helper.py
parent~ (diff)
parentAdd streaming in openai chat (diff)
downloadgpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar.gz
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar.bz2
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar.lz
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar.xz
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.tar.zst
gpt4free-d9e527eb327e6e991435332b20f15b30c596ba0d.zip
Diffstat (limited to 'g4f/Provider/helper.py')
-rw-r--r--g4f/Provider/helper.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py
index 234cdaa1..8f09239a 100644
--- a/g4f/Provider/helper.py
+++ b/g4f/Provider/helper.py
@@ -56,4 +56,28 @@ def format_prompt(messages: list[dict[str, str]], add_special_tokens=False):
)
return f"{formatted}\nAssistant:"
else:
- return messages[0]["content"] \ No newline at end of file
+ return messages[0]["content"]
+
+
+def get_browser(user_data_dir: str = None):
+ try:
+ from undetected_chromedriver import Chrome
+ except ImportError:
+ return None
+
+ def get_user_data_dir():
+ dirs = [
+ '~/.config/google-chrome/Default',
+ '~/.var/app/com.google.Chrome/config/google-chrome/Default',
+ '%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default',
+ '~/Library/Application Support/Google/Chrome/Default',
+ ]
+ from os import path
+ for dir in dirs:
+ dir = path.expandvars(dir)
+ if path.exists(dir):
+ return dir
+ if not user_data_dir:
+ user_data_dir = get_user_data_dir()
+
+ return Chrome(user_data_dir=user_data_dir) \ No newline at end of file