summaryrefslogtreecommitdiffstats
path: root/g4f/Provider
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-27 15:45:57 +0200
committerGitHub <noreply@github.com>2024-04-27 15:45:57 +0200
commit5575031f0975b31e53988c58bf8c5bb1735c6d91 (patch)
tree8ede3885c7f3add4c262ae141f4c2e314cb387fa /g4f/Provider
parentMerge pull request #1891 from eienmojiki206/main (diff)
parentUpdate reka vision (diff)
downloadgpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar.gz
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar.bz2
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar.lz
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar.xz
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.tar.zst
gpt4free-5575031f0975b31e53988c58bf8c5bb1735c6d91.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Reka.py28
1 files changed, 14 insertions, 14 deletions
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']