XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update reka vision

0cc5b07d
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +33 -15
Modified README.md +17 -0
@@ -413,9 +413,26 @@ While we wait for gpt-5, here is a list of new models that are at least better t
413 413 | Gemini API | `g4f.Provider.GeminiPro` | ❌ | gemini-1.5-pro | [ai.google.dev](https://ai.google.dev) |
414 414 | Meta AI | `g4f.Provider.MetaAI` | ✔️ | ❌ | [meta.ai](https://www.meta.ai) |
415 415 | OpenAI ChatGPT | `g4f.Provider.OpenaiChat` | dall-e-3 | gpt-4-vision | [chat.openai.com](https://chat.openai.com) |
416 | Reka | `g4f.Provider.Reka` | ❌ | ✔️ | [chat.reka.ai](https://chat.reka.ai/) |
416 417 | Replicate | `g4f.Provider.Replicate` | stability-ai/sdxl| llava-v1.6-34b | [replicate.com](https://replicate.com) |
417 418 | You.com | `g4f.Provider.You` | dall-e-3| ✔️ | [you.com](https://you.com) |
418 419
420 ```python
421 from g4f.client import Client
422 from g4f.Provider.GeminiPro import GeminiPro
423
424 client = Client(
425 api_key="...",
426 provider=GeminiPro
427 )
428 response = client.chat.completions.create(
429 model="gemini-pro-vision",
430 messages=[{"role": "user", "content": "What are on this image?"}],
431 image=open("docs/waterfall.jpeg", "rb")
432 )
433 print(response.choices[0].message.content)
434 ```
435
419 436 ## 🔗 Powered by gpt4free
420 437
421 438 <table>
Modified g4f/Provider/Reka.py +14 -14
@@ -4,11 +4,13 @@ import os, requests, time, json
4 4 from ..typing import CreateResult, Messages, ImageType
5 5 from .base_provider import AbstractProvider
6 6 from ..cookies import get_cookies
7 from ..image import to_bytes
7 8
8 9 class Reka(AbstractProvider):
9 10 url = "https://chat.reka.ai/"
10 11 working = True
11 12 supports_stream = True
13 default_vision_model = "reka"
12 14 cookies = {}
13 15
14 16 @classmethod
@@ -19,21 +21,19 @@ class Reka(AbstractProvider):
19 21 stream: bool,
20 22 proxy: str = None,
21 23 timeout: int = 180,
22 bearer_auth: str = None,
23 image: ImageType = None, **kwargs) -> CreateResult:
24
24 api_key: str = None,
25 image: ImageType = None,
26 **kwargs
27 ) -> CreateResult:
25 28 cls.proxy = proxy
26 29
27 if not bearer_auth:
28 cls.cookies = get_cookies("chat.reka.ai")
29
30 if not api_key:
31 cls.cookies = get_cookies("chat.reka.ai")
30 32 if not cls.cookies:
31 33 raise ValueError("No cookies found for chat.reka.ai")
32
33 34 elif "appSession" not in cls.cookies:
34 35 raise ValueError("No appSession found in cookies for chat.reka.ai, log in or provide bearer_auth")
35
36 bearer_auth = cls.get_access_token(cls)
36 api_key = cls.get_access_token(cls)
37 37
38 38 conversation = []
39 39 for message in messages:
@@ -43,14 +43,14 @@ class Reka(AbstractProvider):
43 43 })
44 44
45 45 if image:
46 image_url = cls.upload_image(cls, bearer_auth, image)
46 image_url = cls.upload_image(cls, api_key, image)
47 47 conversation[-1]["image_url"] = image_url
48 48 conversation[-1]["media_type"] = "image"
49 49
50 50 headers = {
51 51 'accept': '*/*',
52 52 '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',
53 'authorization': f'Bearer {bearer_auth}',
53 'authorization': f'Bearer {api_key}',
54 54 'cache-control': 'no-cache',
55 55 'content-type': 'application/json',
56 56 'origin': 'https://chat.reka.ai',
@@ -109,7 +109,7 @@ class Reka(AbstractProvider):
109 109 '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',
110 110 }
111 111
112 image_data = image.read()
112 image_data = to_bytes(image)
113 113
114 114 boundary = f'----WebKitFormBoundary{boundary_token}'
115 115 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):
117 117 data += f'\r\n--{boundary}--\r\n'
118 118
119 119 response = requests.post('https://chat.reka.ai/api/upload-image',
120 cookies=Reka.cookies, headers=headers, proxies=cls.proxy, data=data.encode('latin-1'))
120 cookies=cls.cookies, headers=headers, proxies=cls.proxy, data=data.encode('latin-1'))
121 121
122 122 return response.json()['media_url']
123 123
@@ -140,7 +140,7 @@ class Reka(AbstractProvider):
140 140
141 141 try:
142 142 response = requests.get('https://chat.reka.ai/bff/auth/access_token',
143 cookies=cls.cookies, headers=headers)
143 cookies=cls.cookies, headers=headers, proxies=cls.proxy)
144 144
145 145 return response.json()['accessToken']
146 146
Modified g4f/cookies.py +2 -1
@@ -31,7 +31,8 @@ DOMAINS = [
31 31 ".meta.ai",
32 32 ".google.com",
33 33 "www.whiterabbitneo.com",
34 "huggingface.co"
34 "huggingface.co",
35 "chat.reka.ai",
35 36 ]
36 37
37 38 if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":