Upload 36 files
Browse files- chatgpt/ChatService.py +6 -2
- chatgpt/refreshToken.py +4 -1
- gateway/backend.py +9 -2
- gateway/chatgpt.py +15 -6
- gateway/reverseProxy.py +7 -2
- gateway/share.py +6 -1
- gateway/v1.py +3 -0
- templates/chatgpt.html +1 -0
- templates/chatgpt_context_1.json +1 -1
- templates/initialize.json +0 -0
- version.txt +1 -1
chatgpt/ChatService.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import asyncio
|
|
|
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import uuid
|
|
@@ -86,9 +87,12 @@ class ChatService:
|
|
| 86 |
self.host_url = random.choice(chatgpt_base_url_list) if chatgpt_base_url_list else "https://chatgpt.com"
|
| 87 |
self.ark0se_token_url = random.choice(ark0se_token_url_list) if ark0se_token_url_list else None
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
if sentinel_proxy_url_list:
|
| 91 |
-
|
|
|
|
| 92 |
else:
|
| 93 |
self.ss = self.s
|
| 94 |
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
import hashlib
|
| 3 |
import json
|
| 4 |
import random
|
| 5 |
import uuid
|
|
|
|
| 87 |
self.host_url = random.choice(chatgpt_base_url_list) if chatgpt_base_url_list else "https://chatgpt.com"
|
| 88 |
self.ark0se_token_url = random.choice(ark0se_token_url_list) if ark0se_token_url_list else None
|
| 89 |
|
| 90 |
+
session_id = hashlib.md5(self.req_token.encode()).hexdigest()
|
| 91 |
+
proxy_url = self.proxy_url.replace("{}", session_id) if self.proxy_url else None
|
| 92 |
+
self.s = Client(proxy=proxy_url, impersonate=self.impersonate)
|
| 93 |
if sentinel_proxy_url_list:
|
| 94 |
+
sentinel_proxy_url = (random.choice(sentinel_proxy_url_list)).replace("{}", session_id) if sentinel_proxy_url_list else None
|
| 95 |
+
self.ss = Client(proxy=sentinel_proxy_url, impersonate=self.impersonate)
|
| 96 |
else:
|
| 97 |
self.ss = self.s
|
| 98 |
|
chatgpt/refreshToken.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import random
|
| 3 |
import time
|
|
@@ -34,7 +35,9 @@ async def chat_refresh(refresh_token):
|
|
| 34 |
"redirect_uri": "com.openai.chat://auth0.openai.com/ios/com.openai.chat/callback",
|
| 35 |
"refresh_token": refresh_token
|
| 36 |
}
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
r = await client.post("https://auth0.openai.com/oauth/token", json=data, timeout=15)
|
| 40 |
if r.status_code == 200:
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import time
|
|
|
|
| 35 |
"redirect_uri": "com.openai.chat://auth0.openai.com/ios/com.openai.chat/callback",
|
| 36 |
"refresh_token": refresh_token
|
| 37 |
}
|
| 38 |
+
session_id = hashlib.md5(refresh_token.encode()).hexdigest()
|
| 39 |
+
proxy_url = random.choice(proxy_url_list).replace("{}", session_id) if proxy_url_list else None
|
| 40 |
+
client = Client(proxy=proxy_url)
|
| 41 |
try:
|
| 42 |
r = await client.post("https://auth0.openai.com/oauth/token", json=data, timeout=15)
|
| 43 |
if r.status_code == 200:
|
gateway/backend.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import random
|
| 3 |
import re
|
|
@@ -295,9 +296,12 @@ if no_sentinel:
|
|
| 295 |
}
|
| 296 |
headers.update(fp)
|
| 297 |
headers.update({"authorization": f"Bearer {access_token}"})
|
|
|
|
|
|
|
| 298 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 299 |
if sentinel_proxy_url_list:
|
| 300 |
-
|
|
|
|
| 301 |
else:
|
| 302 |
clients = client
|
| 303 |
|
|
@@ -390,9 +394,12 @@ if no_sentinel:
|
|
| 390 |
headers.update({"authorization": f"Bearer {access_token}"})
|
| 391 |
|
| 392 |
try:
|
|
|
|
|
|
|
| 393 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 394 |
if sentinel_proxy_url_list:
|
| 395 |
-
|
|
|
|
| 396 |
else:
|
| 397 |
clients = client
|
| 398 |
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import re
|
|
|
|
| 296 |
}
|
| 297 |
headers.update(fp)
|
| 298 |
headers.update({"authorization": f"Bearer {access_token}"})
|
| 299 |
+
session_id = hashlib.md5(req_token.encode()).hexdigest()
|
| 300 |
+
proxy_url = proxy_url.replace("{}", session_id) if proxy_url else None
|
| 301 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 302 |
if sentinel_proxy_url_list:
|
| 303 |
+
sentinel_proxy_url = random.choice(sentinel_proxy_url_list).replace("{}", session_id) if sentinel_proxy_url_list else None
|
| 304 |
+
clients = Client(proxy=sentinel_proxy_url, impersonate=impersonate)
|
| 305 |
else:
|
| 306 |
clients = client
|
| 307 |
|
|
|
|
| 394 |
headers.update({"authorization": f"Bearer {access_token}"})
|
| 395 |
|
| 396 |
try:
|
| 397 |
+
session_id = hashlib.md5(req_token.encode()).hexdigest()
|
| 398 |
+
proxy_url = proxy_url.replace("{}", session_id) if proxy_url else None
|
| 399 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 400 |
if sentinel_proxy_url_list:
|
| 401 |
+
sentinel_proxy_url = random.choice(sentinel_proxy_url_list).replace("{}", session_id) if sentinel_proxy_url_list else None
|
| 402 |
+
clients = Client(proxy=sentinel_proxy_url, impersonate=impersonate)
|
| 403 |
else:
|
| 404 |
clients = client
|
| 405 |
|
gateway/chatgpt.py
CHANGED
|
@@ -32,20 +32,29 @@ async def chatgpt_html(request: Request):
|
|
| 32 |
set_value_for_key_list(user_chatgpt_context_1, "accessToken", token)
|
| 33 |
if request.cookies.get("oai-locale"):
|
| 34 |
set_value_for_key_list(user_chatgpt_context_1, "locale", request.cookies.get("oai-locale"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
user_chatgpt_context_1 = json.dumps(user_chatgpt_context_1, separators=(',', ':'), ensure_ascii=False)
|
| 37 |
user_chatgpt_context_2 = json.dumps(user_chatgpt_context_2, separators=(',', ':'), ensure_ascii=False)
|
| 38 |
|
| 39 |
-
escaped_context_1 = user_chatgpt_context_1.replace("\\", "\\\\")
|
| 40 |
-
escaped_context_2 = user_chatgpt_context_2.replace("\\", "\\\\")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
response = templates.TemplateResponse("chatgpt.html", {
|
| 46 |
-
"request": request,
|
| 47 |
"react_chatgpt_context_1": escaped_context_1,
|
| 48 |
-
"react_chatgpt_context_2": escaped_context_2
|
|
|
|
| 49 |
})
|
| 50 |
response.set_cookie("token", value=token, expires="Thu, 01 Jan 2099 00:00:00 GMT")
|
| 51 |
return response
|
|
|
|
|
|
| 32 |
set_value_for_key_list(user_chatgpt_context_1, "accessToken", token)
|
| 33 |
if request.cookies.get("oai-locale"):
|
| 34 |
set_value_for_key_list(user_chatgpt_context_1, "locale", request.cookies.get("oai-locale"))
|
| 35 |
+
else:
|
| 36 |
+
accept_language = request.headers.get("accept-language")
|
| 37 |
+
if accept_language:
|
| 38 |
+
set_value_for_key_list(user_chatgpt_context_1, "locale", accept_language.split(",")[0])
|
| 39 |
|
| 40 |
user_chatgpt_context_1 = json.dumps(user_chatgpt_context_1, separators=(',', ':'), ensure_ascii=False)
|
| 41 |
user_chatgpt_context_2 = json.dumps(user_chatgpt_context_2, separators=(',', ':'), ensure_ascii=False)
|
| 42 |
|
| 43 |
+
escaped_context_1 = user_chatgpt_context_1.replace("\\", "\\\\").replace('"', '\\"')
|
| 44 |
+
escaped_context_2 = user_chatgpt_context_2.replace("\\", "\\\\").replace('"', '\\"')
|
| 45 |
|
| 46 |
+
clear_localstorage_script = """
|
| 47 |
+
<script>
|
| 48 |
+
localStorage.clear();
|
| 49 |
+
</script>
|
| 50 |
+
"""
|
| 51 |
|
| 52 |
response = templates.TemplateResponse("chatgpt.html", {
|
| 53 |
+
"request": request,
|
| 54 |
"react_chatgpt_context_1": escaped_context_1,
|
| 55 |
+
"react_chatgpt_context_2": escaped_context_2,
|
| 56 |
+
"clear_localstorage_script": clear_localstorage_script
|
| 57 |
})
|
| 58 |
response.set_cookie("token", value=token, expires="Thu, 01 Jan 2099 00:00:00 GMT")
|
| 59 |
return response
|
| 60 |
+
|
gateway/reverseProxy.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import random
|
| 3 |
import time
|
|
@@ -211,6 +212,8 @@ async def chatgpt_reverse_proxy(request: Request, path: str):
|
|
| 211 |
req_token = await get_real_req_token(cookie_token)
|
| 212 |
fp = get_fp(req_token).copy()
|
| 213 |
|
|
|
|
|
|
|
| 214 |
proxy_url = fp.pop("proxy_url", None)
|
| 215 |
impersonate = fp.pop("impersonate", "safari15_3")
|
| 216 |
user_agent = fp.get("user-agent")
|
|
@@ -248,9 +251,11 @@ async def chatgpt_reverse_proxy(request: Request, path: str):
|
|
| 248 |
data = json.dumps(req_json).encode("utf-8")
|
| 249 |
|
| 250 |
|
| 251 |
-
if
|
| 252 |
-
|
|
|
|
| 253 |
else:
|
|
|
|
| 254 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 255 |
try:
|
| 256 |
background = BackgroundTask(client.close)
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import time
|
|
|
|
| 212 |
req_token = await get_real_req_token(cookie_token)
|
| 213 |
fp = get_fp(req_token).copy()
|
| 214 |
|
| 215 |
+
session_id = hashlib.md5(req_token.encode()).hexdigest()
|
| 216 |
+
|
| 217 |
proxy_url = fp.pop("proxy_url", None)
|
| 218 |
impersonate = fp.pop("impersonate", "safari15_3")
|
| 219 |
user_agent = fp.get("user-agent")
|
|
|
|
| 251 |
data = json.dumps(req_json).encode("utf-8")
|
| 252 |
|
| 253 |
|
| 254 |
+
if "backend-api/sentinel/chat-requirements" in path and sentinel_proxy_url_list:
|
| 255 |
+
sentinel_proxy_url = random.choice(sentinel_proxy_url_list).replace("{}", session_id) if sentinel_proxy_url_list else None
|
| 256 |
+
client = Client(proxy=sentinel_proxy_url)
|
| 257 |
else:
|
| 258 |
+
proxy_url = proxy_url.replace("{}", session_id) if proxy_url else None
|
| 259 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 260 |
try:
|
| 261 |
background = BackgroundTask(client.close)
|
gateway/share.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import random
|
| 3 |
import time
|
|
@@ -136,6 +137,8 @@ async def chatgpt_account_check(access_token):
|
|
| 136 |
headers.update(fp)
|
| 137 |
headers.update({"authorization": f"Bearer {access_token}"})
|
| 138 |
|
|
|
|
|
|
|
| 139 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 140 |
r = await client.get(f"{host_url}/backend-api/models?history_and_training_disabled=false", headers=headers,
|
| 141 |
timeout=10)
|
|
@@ -182,7 +185,9 @@ async def chatgpt_account_check(access_token):
|
|
| 182 |
|
| 183 |
|
| 184 |
async def chatgpt_refresh(refresh_token):
|
| 185 |
-
|
|
|
|
|
|
|
| 186 |
try:
|
| 187 |
data = {
|
| 188 |
"client_id": "pdlLIX2Y72MIl2rhLhTE9VV9bN905kBh",
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import time
|
|
|
|
| 137 |
headers.update(fp)
|
| 138 |
headers.update({"authorization": f"Bearer {access_token}"})
|
| 139 |
|
| 140 |
+
session_id = hashlib.md5(access_token.encode()).hexdigest()
|
| 141 |
+
proxy_url = random.choice(proxy_url_list).replace("{}", session_id) if proxy_url_list else None
|
| 142 |
client = Client(proxy=proxy_url, impersonate=impersonate)
|
| 143 |
r = await client.get(f"{host_url}/backend-api/models?history_and_training_disabled=false", headers=headers,
|
| 144 |
timeout=10)
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
async def chatgpt_refresh(refresh_token):
|
| 188 |
+
session_id = hashlib.md5(refresh_token.encode()).hexdigest()
|
| 189 |
+
proxy_url = random.choice(proxy_url_list).replace("{}", session_id) if proxy_url_list else None
|
| 190 |
+
client = Client(proxy=proxy_url)
|
| 191 |
try:
|
| 192 |
data = {
|
| 193 |
"client_id": "pdlLIX2Y72MIl2rhLhTE9VV9bN905kBh",
|
gateway/v1.py
CHANGED
|
@@ -7,6 +7,9 @@ from app import app
|
|
| 7 |
from gateway.reverseProxy import chatgpt_reverse_proxy
|
| 8 |
from utils.kv_utils import set_value_for_key_dict
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@app.post("/v1/initialize")
|
| 12 |
async def initialize(request: Request):
|
|
|
|
| 7 |
from gateway.reverseProxy import chatgpt_reverse_proxy
|
| 8 |
from utils.kv_utils import set_value_for_key_dict
|
| 9 |
|
| 10 |
+
with open("templates/initialize.json", "r") as f:
|
| 11 |
+
initialize_json = json.load(f)
|
| 12 |
+
|
| 13 |
|
| 14 |
@app.post("/v1/initialize")
|
| 15 |
async def initialize(request: Request):
|
templates/chatgpt.html
CHANGED
|
@@ -82,6 +82,7 @@
|
|
| 82 |
} catch {}
|
| 83 |
}();
|
| 84 |
</script>
|
|
|
|
| 85 |
</head>
|
| 86 |
<body class="">
|
| 87 |
<script>
|
|
|
|
| 82 |
} catch {}
|
| 83 |
}();
|
| 84 |
</script>
|
| 85 |
+
{{ clear_localstorage_script | safe }}
|
| 86 |
</head>
|
| 87 |
<body class="">
|
| 88 |
<script>
|
templates/chatgpt_context_1.json
CHANGED
|
@@ -128,7 +128,7 @@
|
|
| 128 |
"userCountry",
|
| 129 |
"US",
|
| 130 |
"locale",
|
| 131 |
-
"
|
| 132 |
"statsig",
|
| 133 |
{
|
| 134 |
"_65": 66
|
|
|
|
| 128 |
"userCountry",
|
| 129 |
"US",
|
| 130 |
"locale",
|
| 131 |
+
"",
|
| 132 |
"statsig",
|
| 133 |
{
|
| 134 |
"_65": 66
|
templates/initialize.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
version.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
1.8.
|
|
|
|
| 1 |
+
1.8.5-beta2
|