AIMaster7 commited on
Commit
cbea1f1
Β·
verified Β·
1 Parent(s): 6e7886f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -7
main.py CHANGED
@@ -36,17 +36,30 @@ CONNECTION_LIMIT_PER_HOST = 50
36
  REQUEST_TIMEOUT = 300
37
  WORKER_COUNT = 10
38
 
39
- # ─── Static Headers ───
40
  HEADERS = {
 
 
 
 
41
  "accept": "*/*",
42
- "content-type": "application/json",
 
43
  "origin": "https://www.blackbox.ai",
 
44
  "referer": "https://www.blackbox.ai/",
 
 
 
 
 
 
45
  "user-agent": (
46
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
47
  "AppleWebKit/537.36 (KHTML, like Gecko) "
48
  "Chrome/136.0.0.0 Safari/537.36"
49
  ),
 
50
  }
51
 
52
  # ─── FastAPI Setup ───
@@ -72,7 +85,6 @@ class RetryableStatusError(Exception):
72
 
73
  RETRYABLE_STATUSES = {400, 429, 500, 502, 503, 504}
74
 
75
- # ─── Random Data ───
76
  _ascii = string.ascii_letters + string.digits
77
  def _rand(n, pool=_ascii): return "".join(random.choice(pool) for _ in range(n))
78
  def random_email(): return _rand(12) + "@gmail.com"
@@ -81,10 +93,13 @@ def random_customer_id(): return "cus_" + _rand(12)
81
 
82
  # ─── Payload Generator ───
83
  def build_payload(messages: List[Dict[str, Any]]) -> Dict[str, Any]:
 
84
  return {
85
  "messages": messages,
86
- "id": _rand(8),
87
  "agentMode": {},
 
 
 
88
  "codeModelMode": True,
89
  "trendingAgentMode": {},
90
  "isMicMode": False,
@@ -101,7 +116,7 @@ def build_payload(messages: List[Dict[str, Any]]) -> Dict[str, Any]:
101
  "isMemoryEnabled": False,
102
  "mobileClient": False,
103
  "userSelectedModel": None,
104
- "validated": str(uuid.uuid4()),
105
  "imageGenerationMode": False,
106
  "webSearchModePrompt": False,
107
  "deepSearchMode": True,
@@ -117,7 +132,7 @@ def build_payload(messages: List[Dict[str, Any]]) -> Dict[str, Any]:
117
  },
118
  "session": {
119
  "user": {
120
- "name": "S.C gaming",
121
  "email": random_email(),
122
  "image": "https://lh3.googleusercontent.com/a/default",
123
  "id": random_id()
@@ -214,7 +229,6 @@ async def chat_completions(request: Request):
214
  if not messages:
215
  raise HTTPException(status_code=400, detail="Missing 'messages'")
216
  stream = body.get("stream", False)
217
-
218
  payload = build_payload(messages)
219
 
220
  if not stream:
 
36
  REQUEST_TIMEOUT = 300
37
  WORKER_COUNT = 10
38
 
39
+ # ─── Required Headers ───
40
  HEADERS = {
41
+ "authority": "www.blackbox.ai",
42
+ "method": "POST",
43
+ "path": "/api/chat",
44
+ "scheme": "https",
45
  "accept": "*/*",
46
+ "accept-encoding": "gzip, deflate, br, zstd",
47
+ "accept-language": "en-US,en;q=0.9",
48
  "origin": "https://www.blackbox.ai",
49
+ "priority": "u=1, i",
50
  "referer": "https://www.blackbox.ai/",
51
+ "sec-ch-ua": '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
52
+ "sec-ch-ua-mobile": "?0",
53
+ "sec-ch-ua-platform": '"Windows"',
54
+ "sec-fetch-dest": "empty",
55
+ "sec-fetch-mode": "cors",
56
+ "sec-fetch-site": "same-origin",
57
  "user-agent": (
58
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
59
  "AppleWebKit/537.36 (KHTML, like Gecko) "
60
  "Chrome/136.0.0.0 Safari/537.36"
61
  ),
62
+ "content-type": "application/json",
63
  }
64
 
65
  # ─── FastAPI Setup ───
 
85
 
86
  RETRYABLE_STATUSES = {400, 429, 500, 502, 503, 504}
87
 
 
88
  _ascii = string.ascii_letters + string.digits
89
  def _rand(n, pool=_ascii): return "".join(random.choice(pool) for _ in range(n))
90
  def random_email(): return _rand(12) + "@gmail.com"
 
93
 
94
  # ─── Payload Generator ───
95
  def build_payload(messages: List[Dict[str, Any]]) -> Dict[str, Any]:
96
+ unique_id = str(uuid.uuid4())
97
  return {
98
  "messages": messages,
 
99
  "agentMode": {},
100
+ "id": messages[-1]["id"] if messages else _rand(8),
101
+ "previewToken": None,
102
+ "userId": None,
103
  "codeModelMode": True,
104
  "trendingAgentMode": {},
105
  "isMicMode": False,
 
116
  "isMemoryEnabled": False,
117
  "mobileClient": False,
118
  "userSelectedModel": None,
119
+ "validated": unique_id,
120
  "imageGenerationMode": False,
121
  "webSearchModePrompt": False,
122
  "deepSearchMode": True,
 
132
  },
133
  "session": {
134
  "user": {
135
+ "name": _rand(10),
136
  "email": random_email(),
137
  "image": "https://lh3.googleusercontent.com/a/default",
138
  "id": random_id()
 
229
  if not messages:
230
  raise HTTPException(status_code=400, detail="Missing 'messages'")
231
  stream = body.get("stream", False)
 
232
  payload = build_payload(messages)
233
 
234
  if not stream: