diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-27 11:48:10 +0200 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-27 11:48:10 +0200 |
commit | 0cc5b07dafe501f4e6f97945264a597f437cbf67 (patch) | |
tree | 8ede3885c7f3add4c262ae141f4c2e314cb387fa | |
parent | Merge pull request #1891 from eienmojiki206/main (diff) | |
download | gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar.gz gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar.bz2 gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar.lz gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar.xz gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.tar.zst gpt4free-0cc5b07dafe501f4e6f97945264a597f437cbf67.zip |
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | g4f/Provider/Reka.py | 28 | ||||
-rw-r--r-- | g4f/cookies.py | 3 |
3 files changed, 33 insertions, 15 deletions
@@ -413,9 +413,26 @@ While we wait for gpt-5, here is a list of new models that are at least better t | Gemini API | `g4f.Provider.GeminiPro` | ❌ | gemini-1.5-pro | [ai.google.dev](https://ai.google.dev) | | Meta AI | `g4f.Provider.MetaAI` | ✔️ | ❌ | [meta.ai](https://www.meta.ai) | | OpenAI ChatGPT | `g4f.Provider.OpenaiChat` | dall-e-3 | gpt-4-vision | [chat.openai.com](https://chat.openai.com) | +| Reka | `g4f.Provider.Reka` | ❌ | ✔️ | [chat.reka.ai](https://chat.reka.ai/) | | Replicate | `g4f.Provider.Replicate` | stability-ai/sdxl| llava-v1.6-34b | [replicate.com](https://replicate.com) | | You.com | `g4f.Provider.You` | dall-e-3| ✔️ | [you.com](https://you.com) | +```python +from g4f.client import Client +from g4f.Provider.GeminiPro import GeminiPro + +client = Client( + api_key="...", + provider=GeminiPro +) +response = client.chat.completions.create( + model="gemini-pro-vision", + messages=[{"role": "user", "content": "What are on this image?"}], + image=open("docs/waterfall.jpeg", "rb") +) +print(response.choices[0].message.content) +``` + ## 🔗 Powered by gpt4free <table> diff --git a/g4f/Provider/Reka.py b/g4f/Provider/Reka.py index 9a6e479d..09164b07 100644 --- a/g4f/Provider/Reka.py +++ b/g4f/Provider/Reka.py @@ -4,11 +4,13 @@ import os, requests, time, json from ..typing import CreateResult, Messages, ImageType from .base_provider import AbstractProvider from ..cookies import get_cookies +from ..image import to_bytes class Reka(AbstractProvider): url = "https://chat.reka.ai/" working = True supports_stream = True + default_vision_model = "reka" cookies = {} @classmethod @@ -19,21 +21,19 @@ class Reka(AbstractProvider): stream: bool, proxy: str = None, timeout: int = 180, - bearer_auth: str = None, - image: ImageType = None, **kwargs) -> CreateResult: - + api_key: str = None, + image: ImageType = None, + **kwargs + ) -> CreateResult: cls.proxy = proxy - if not bearer_auth: - cls.cookies = get_cookies("chat.reka.ai") - + if not api_key: + cls.cookies = get_cookies("chat.reka.ai") if not cls.cookies: raise ValueError("No cookies found for chat.reka.ai") - elif "appSession" not in cls.cookies: raise ValueError("No appSession found in cookies for chat.reka.ai, log in or provide bearer_auth") - - bearer_auth = cls.get_access_token(cls) + api_key = cls.get_access_token(cls) conversation = [] for message in messages: @@ -43,14 +43,14 @@ class Reka(AbstractProvider): }) if image: - image_url = cls.upload_image(cls, bearer_auth, image) + image_url = cls.upload_image(cls, api_key, image) conversation[-1]["image_url"] = image_url conversation[-1]["media_type"] = "image" headers = { 'accept': '*/*', 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', - 'authorization': f'Bearer {bearer_auth}', + 'authorization': f'Bearer {api_key}', 'cache-control': 'no-cache', 'content-type': 'application/json', 'origin': 'https://chat.reka.ai', @@ -109,7 +109,7 @@ class Reka(AbstractProvider): 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', } - image_data = image.read() + image_data = to_bytes(image) boundary = f'----WebKitFormBoundary{boundary_token}' data = f'--{boundary}\r\nContent-Disposition: form-data; name="image"; filename="image.png"\r\nContent-Type: image/png\r\n\r\n' @@ -117,7 +117,7 @@ class Reka(AbstractProvider): data += f'\r\n--{boundary}--\r\n' response = requests.post('https://chat.reka.ai/api/upload-image', - cookies=Reka.cookies, headers=headers, proxies=cls.proxy, data=data.encode('latin-1')) + cookies=cls.cookies, headers=headers, proxies=cls.proxy, data=data.encode('latin-1')) return response.json()['media_url'] @@ -140,7 +140,7 @@ class Reka(AbstractProvider): try: response = requests.get('https://chat.reka.ai/bff/auth/access_token', - cookies=cls.cookies, headers=headers) + cookies=cls.cookies, headers=headers, proxies=cls.proxy) return response.json()['accessToken'] diff --git a/g4f/cookies.py b/g4f/cookies.py index 3c082abc..9dfe0ca5 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -31,7 +31,8 @@ DOMAINS = [ ".meta.ai", ".google.com", "www.whiterabbitneo.com", - "huggingface.co" + "huggingface.co", + "chat.reka.ai", ] if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null": |