返回提交历史
Modified
g4f/Provider/needs_auth/Reka.py
+13
-12
XFEstudio/gpt4free
Refactor Reka provider class: Update URL and url handling (#2823)
* Refactor Reka class: Update URL and url handling - Change old URL to new - Updated error messages/body content to reference cls.domain/cls.url instead of hardcoded values for better maintainability.
dfc2160f
代码差异
1 个文件
+13
-12
@@ -7,7 +7,8 @@ from ...cookies import get_cookies
7
7
from ...image import to_bytes
8
8
9
9
class Reka(AbstractProvider):
10
url = "https://chat.reka.ai/"
10
domain = "space.reka.ai"
11
url = f"https://{domain}"
11
12
working = True
12
13
needs_auth = True
13
14
supports_stream = True
@@ -28,11 +29,11 @@ class Reka(AbstractProvider):
28
29
cls.proxy = proxy
29
30
30
31
if not api_key:
31
cls.cookies = get_cookies("chat.reka.ai")
32
cls.cookies = get_cookies(cls.domain)
32
33
if not cls.cookies:
33
raise ValueError("No cookies found for chat.reka.ai")
34
raise ValueError(f"No cookies found for {cls.domain}")
34
35
elif "appSession" not in cls.cookies:
35
raise ValueError("No appSession found in cookies for chat.reka.ai, log in or provide bearer_auth")
36
raise ValueError(f"No appSession found in cookies for {cls.domain}, log in or provide bearer_auth")
36
37
api_key = cls.get_access_token(cls)
37
38
38
39
conversation = []
@@ -53,7 +54,7 @@ class Reka(AbstractProvider):
53
54
'authorization': f'Bearer {api_key}',
54
55
'cache-control': 'no-cache',
55
56
'content-type': 'application/json',
56
'origin': 'https://chat.reka.ai',
57
'origin': cls.url,
57
58
'pragma': 'no-cache',
58
59
'priority': 'u=1, i',
59
60
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
@@ -76,7 +77,7 @@ class Reka(AbstractProvider):
76
77
77
78
tokens = ''
78
79
79
response = requests.post('https://chat.reka.ai/api/chat',
80
response = requests.post(f'{cls.url}/api/chat',
80
81
cookies=cls.cookies, headers=headers, json=json_data, proxies=cls.proxy, stream=True)
81
82
82
83
for completion in response.iter_lines():
@@ -96,10 +97,10 @@ class Reka(AbstractProvider):
96
97
'cache-control': 'no-cache',
97
98
'authorization': f'Bearer {access_token}',
98
99
'content-type': f'multipart/form-data; boundary=----WebKitFormBoundary{boundary_token}',
99
'origin': 'https://chat.reka.ai',
100
'origin': cls.url,
100
101
'pragma': 'no-cache',
101
102
'priority': 'u=1, i',
102
'referer': 'https://chat.reka.ai/chat/hPReZExtDOPvUfF8vCPC',
103
'referer': f'{cls.url}/chat/hPReZExtDOPvUfF8vCPC',
103
104
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
104
105
'sec-ch-ua-mobile': '?0',
105
106
'sec-ch-ua-platform': '"macOS"',
@@ -116,7 +117,7 @@ class Reka(AbstractProvider):
116
117
data += image_data.decode('latin-1')
117
118
data += f'\r\n--{boundary}--\r\n'
118
119
119
response = requests.post('https://chat.reka.ai/api/upload-image',
120
response = requests.post(f'{cls.url}/api/upload-image',
120
121
cookies=cls.cookies, headers=headers, proxies=cls.proxy, data=data.encode('latin-1'))
121
122
122
123
return response.json()['media_url']
@@ -128,7 +129,7 @@ class Reka(AbstractProvider):
128
129
'cache-control': 'no-cache',
129
130
'pragma': 'no-cache',
130
131
'priority': 'u=1, i',
131
'referer': 'https://chat.reka.ai/chat',
132
'referer': f'{cls.url}/chat',
132
133
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
133
134
'sec-ch-ua-mobile': '?0',
134
135
'sec-ch-ua-platform': '"macOS"',
@@ -139,10 +140,10 @@ class Reka(AbstractProvider):
139
140
}
140
141
141
142
try:
142
response = requests.get('https://chat.reka.ai/bff/auth/access_token',
143
response = requests.get(f'{cls.url}/bff/auth/access_token',
143
144
cookies=cls.cookies, headers=headers, proxies=cls.proxy)
144
145
145
146
return response.json()['accessToken']
146
147
147
148
except Exception as e:
148
raise ValueError(f"Failed to get access token: {e}, refresh your cookies / log in into chat.reka.ai")
149
raise ValueError(f"Failed to get access token: {e}, refresh your cookies / log in into {cls.domain}")