summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/helper.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-07 22:03:50 +0200
committerGitHub <noreply@github.com>2023-10-07 22:03:50 +0200
commit6334dac211898fb607d0281e9f23176172de4feb (patch)
tree45fad72c866cb03db744ae53e2993a4f31b29f0d /g4f/Provider/helper.py
parent ~ | g4f `v-0.1.5.4` [new gui & interference] (diff)
parentRemove Aivvm from working providers (diff)
downloadgpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.gz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.bz2
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.lz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.xz
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.tar.zst
gpt4free-6334dac211898fb607d0281e9f23176172de4feb.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/helper.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py
index c127f241..5a9a9329 100644
--- a/g4f/Provider/helper.py
+++ b/g4f/Provider/helper.py
@@ -1,8 +1,10 @@
from __future__ import annotations
-import asyncio, sys
+import asyncio
+import sys
from asyncio import AbstractEventLoop
from os import path
+from typing import Dict, List
import browser_cookie3
# Change event loop policy on windows
@@ -13,7 +15,7 @@ if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# Local Cookie Storage
-_cookies: dict[str, dict[str, str]] = {}
+_cookies: Dict[str, Dict[str, str]] = {}
# If event loop is already running, handle nested event loops
# If "nest_asyncio" is installed, patch the event loop.
@@ -34,11 +36,13 @@ def get_event_loop() -> AbstractEventLoop:
return event_loop
except ImportError:
raise RuntimeError(
- 'Use "create_async" instead of "create" function in a running event loop. Or install the "nest_asyncio" package.')
+ 'Use "create_async" instead of "create" function in a running event loop. Or install the "nest_asyncio" package.'
+ )
+
-# Load cookies for a domain from all supported browser.
-# Cache the results in the "_cookies" variable
-def get_cookies(cookie_domain: str) -> dict:
+# Load cookies for a domain from all supported browsers.
+# Cache the results in the "_cookies" variable.
+def get_cookies(cookie_domain: str) -> Dict[str, str]:
if cookie_domain not in _cookies:
_cookies[cookie_domain] = {}
try:
@@ -49,15 +53,18 @@ def get_cookies(cookie_domain: str) -> dict:
return _cookies[cookie_domain]
-def format_prompt(messages: list[dict[str, str]], add_special_tokens=False):
+def format_prompt(messages: List[Dict[str, str]], add_special_tokens=False) -> str:
if add_special_tokens or len(messages) > 1:
formatted = "\n".join(
- ["%s: %s" % ((message["role"]).capitalize(), message["content"]) for message in messages]
+ [
+ "%s: %s" % ((message["role"]).capitalize(), message["content"])
+ for message in messages
+ ]
)
return f"{formatted}\nAssistant:"
else:
return messages[0]["content"]
-
+
def get_browser(user_data_dir: str = None):
from undetected_chromedriver import Chrome