From 6a05a238d9a480e05f636b2987e6e50ac8b60169 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 22 Apr 2024 17:55:31 +0200 Subject: Fix "domain" KeyError with Firefox .har --- g4f/cookies.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/g4f/cookies.py b/g4f/cookies.py index 4f0899b4..e1d7b59c 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -26,6 +26,12 @@ from . import debug # Global variable to store cookies _cookies: Dict[str, Cookies] = {} +DOMAINS = [ + ".bing.com", + ".meta.ai", + ".google.com" +] + if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null": _LinuxPasswordManager.get_password = lambda a, b: b"secret" @@ -88,6 +94,15 @@ def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool return cookies def read_cookie_files(dirPath: str = "./har_and_cookies"): + def get_domain(v: dict) -> str: + host = [h["value"] for h in v['request']['headers'] if h["name"].lower() in ("host", ":authority")] + if not host: + return + host = host.pop() + for d in DOMAINS: + if d in host: + return d + global _cookies harFiles = [] cookieFiles = [] @@ -109,17 +124,15 @@ def read_cookie_files(dirPath: str = "./har_and_cookies"): print("Read .har file:", path) new_cookies = {} for v in harFile['log']['entries']: + domain = get_domain(v) + if domain is None: + continue v_cookies = {} for c in v['request']['cookies']: - if "domain" not in c: - continue - - if c['domain'] not in v_cookies: - v_cookies[c['domain']] = {} - v_cookies[c['domain']][c['name']] = c['value'] - for domain, c in v_cookies.items(): - _cookies[domain] = c - new_cookies[domain] = len(c) + v_cookies[c['name']] = c['value'] + if len(v_cookies) > 0: + _cookies[domain] = v_cookies + new_cookies[domain] = len(v_cookies) if debug.logging: for domain, new_values in new_cookies.items(): print(f"Cookies added: {new_values} from {domain}") -- cgit v1.2.3 From 6e064adb094bacd10bd8bbc8c18a405e1cf651cd Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 22 Apr 2024 18:08:04 +0200 Subject: Add gemini-1.5-pro-latest model --- README.md | 5 +++-- etc/tool/readme_table.py | 2 ++ g4f/Provider/GeminiPro.py | 9 +++++---- g4f/gui/client/index.html | 10 +++++----- g4f/gui/server/api.py | 28 ++++++++++++++++++++-------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 66398659..e9497dbc 100644 --- a/README.md +++ b/README.md @@ -404,11 +404,12 @@ While we wait for gpt-5, here is a list of new models that are at least better t | Label | Provider | Image Model | Vision Model | Website | | ----- | -------- | ----------- | ------------ | ------- | -| Microsoft Copilot in Bing | `g4f.Provider.Bing` | dall-e| gpt-4-vision | [bing.com](https://bing.com/chat) | +| Microsoft Copilot in Bing | `g4f.Provider.Bing` | dall-e-3 | gpt-4-vision | [bing.com](https://bing.com/chat) | | DeepInfra | `g4f.Provider.DeepInfra` | stability-ai/sdxl| llava-1.5-7b-hf | [deepinfra.com](https://deepinfra.com) | | Gemini | `g4f.Provider.Gemini` | gemini| gemini | [gemini.google.com](https://gemini.google.com) | +| Gemini API | `g4f.Provider.GeminiPro` | ❌| gemini-1.5-pro-latest | [ai.google.dev](https://ai.google.dev) | | Meta AI | `g4f.Provider.MetaAI` | meta| ❌ | [meta.ai](https://www.meta.ai) | -| OpenAI ChatGPT | `g4f.Provider.OpenaiChat` | dall-e| gpt-4-vision | [chat.openai.com](https://chat.openai.com) | +| OpenAI ChatGPT | `g4f.Provider.OpenaiChat` | dall-e-3 | gpt-4-vision | [chat.openai.com](https://chat.openai.com) | | Replicate | `g4f.Provider.Replicate` | stability-ai/sdxl| ❌ | [replicate.com](https://replicate.com) | | You.com | `g4f.Provider.You` | dall-e| agent | [you.com](https://you.com) | diff --git a/etc/tool/readme_table.py b/etc/tool/readme_table.py index 439b17fa..e89f861b 100644 --- a/etc/tool/readme_table.py +++ b/etc/tool/readme_table.py @@ -136,6 +136,8 @@ def print_image_models(): netloc = urlparse(provider_url).netloc.replace("www.", "") website = f"[{netloc}]({provider_url})" label = image_model["provider"] if image_model["label"] is None else image_model["label"] + if image_model["image_model"] is None: + image_model["image_model"] = "❌" if image_model["vision_model"] is None: image_model["vision_model"] = "❌" lines.append(f'| {label} | `g4f.Provider.{image_model["provider"]}` | {image_model["image_model"]}| {image_model["vision_model"]} | {website} |') diff --git a/g4f/Provider/GeminiPro.py b/g4f/Provider/GeminiPro.py index 214b7383..56c211ef 100644 --- a/g4f/Provider/GeminiPro.py +++ b/g4f/Provider/GeminiPro.py @@ -11,12 +11,14 @@ from ..errors import MissingAuthError from .helper import get_connector class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin): + label = "Gemini API" url = "https://ai.google.dev" working = True supports_message_history = True needs_auth = True - default_model = "gemini-pro" - models = ["gemini-pro", "gemini-pro-vision"] + default_model = "gemini-1.5-pro-latest" + default_vision_model = default_model + models = [default_model, "gemini-pro", "gemini-pro-vision"] @classmethod async def create_async_generator( @@ -32,11 +34,10 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin): connector: BaseConnector = None, **kwargs ) -> AsyncResult: - model = "gemini-pro-vision" if not model and image is not None else model model = cls.get_model(model) if not api_key: - raise MissingAuthError('Missing "api_key"') + raise MissingAuthError('Add a "api_key"') headers = params = None if use_auth_header: diff --git a/g4f/gui/client/index.html b/g4f/gui/client/index.html index d84bbbe9..cfca51a9 100644 --- a/g4f/gui/client/index.html +++ b/g4f/gui/client/index.html @@ -130,11 +130,7 @@
- - -
-
- +
@@ -157,6 +153,10 @@
+
+ + +