Update Dockerfile
Browse files- Dockerfile +124 -89
Dockerfile
CHANGED
|
@@ -41,7 +41,6 @@ const generateRandomUser = () => {
|
|
| 41 |
const email = `${emailUsername}@gmail.com`;
|
| 42 |
const id = Array.from({ length: 21 }, () => Math.floor(Math.random() * 10)).join('');
|
| 43 |
const image = `https://robohash.org/${id}.png?set=set2&bgset=bg1&size=96x96`;
|
| 44 |
-
|
| 45 |
return { name: fullName, email, image, id };
|
| 46 |
};
|
| 47 |
|
|
@@ -66,114 +65,150 @@ const parseApiResponse = (data) => {
|
|
| 66 |
return { answer: data, sources: [] };
|
| 67 |
};
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
app.use(cors());
|
| 70 |
app.use(express.json());
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
app.post('/api/generate', async (req, res) => {
|
| 73 |
const { prompt, system, web } = req.body;
|
| 74 |
-
|
| 75 |
if (!prompt) {
|
| 76 |
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 77 |
}
|
| 78 |
-
|
| 79 |
try {
|
| 80 |
-
const
|
| 81 |
-
const messagesForPayload = [newUserMessage];
|
| 82 |
-
|
| 83 |
-
let webSearchModeOption = { autoMode: true, webMode: false, offlineMode: false };
|
| 84 |
-
if (web) {
|
| 85 |
-
const webMode = String(web).toLowerCase();
|
| 86 |
-
if (webMode === 'true') webSearchModeOption = { autoMode: false, webMode: true, offlineMode: false };
|
| 87 |
-
else if (webMode === 'false') webSearchModeOption = { autoMode: false, webMode: false, offlineMode: true };
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
const randomUser = generateRandomUser();
|
| 91 |
-
const expiresDate = new Date();
|
| 92 |
-
expiresDate.setFullYear(expiresDate.getFullYear() + 1);
|
| 93 |
-
|
| 94 |
-
const payload = {
|
| 95 |
-
messages: messagesForPayload,
|
| 96 |
-
id: newUserMessage.id,
|
| 97 |
-
userSystemPrompt: system || null,
|
| 98 |
-
validated: VALIDATED_TOKEN,
|
| 99 |
-
previewToken: null,
|
| 100 |
-
userId: null,
|
| 101 |
-
codeModelMode: true,
|
| 102 |
-
trendingAgentMode: {},
|
| 103 |
-
isMicMode: false,
|
| 104 |
-
maxTokens: 1024,
|
| 105 |
-
playgroundTopP: null,
|
| 106 |
-
playgroundTemperature: null,
|
| 107 |
-
isChromeExt: false,
|
| 108 |
-
githubToken: '',
|
| 109 |
-
clickedAnswer2: false,
|
| 110 |
-
clickedAnswer3: false,
|
| 111 |
-
clickedForceWebSearch: false,
|
| 112 |
-
visitFromDelta: false,
|
| 113 |
-
isMemoryEnabled: false,
|
| 114 |
-
mobileClient: false,
|
| 115 |
-
userSelectedModel: null,
|
| 116 |
-
userSelectedAgent: 'VscodeAgent',
|
| 117 |
-
imageGenerationMode: false,
|
| 118 |
-
imageGenMode: 'autoMode',
|
| 119 |
-
webSearchModePrompt: false,
|
| 120 |
-
deepSearchMode: false,
|
| 121 |
-
domains: null,
|
| 122 |
-
vscodeClient: false,
|
| 123 |
-
codeInterpreterMode: false,
|
| 124 |
-
customProfile: {
|
| 125 |
-
name: '',
|
| 126 |
-
occupation: '',
|
| 127 |
-
traits: [],
|
| 128 |
-
additionalInfo: '',
|
| 129 |
-
enableNewChats: false,
|
| 130 |
-
},
|
| 131 |
-
webSearchModeOption,
|
| 132 |
-
session: {
|
| 133 |
-
user: randomUser,
|
| 134 |
-
expires: expiresDate.toISOString(),
|
| 135 |
-
isNewUser: Math.random() < 0.1,
|
| 136 |
-
},
|
| 137 |
-
isPremium: false,
|
| 138 |
-
subscriptionCache: {
|
| 139 |
-
status: 'FREE',
|
| 140 |
-
expiryTimestamp: null,
|
| 141 |
-
lastChecked: Date.now(),
|
| 142 |
-
isTrialSubscription: false,
|
| 143 |
-
},
|
| 144 |
-
beastMode: false,
|
| 145 |
-
reasoningMode: false,
|
| 146 |
-
designerMode: false,
|
| 147 |
-
workspaceId: '',
|
| 148 |
-
asyncMode: false,
|
| 149 |
-
integrations: {},
|
| 150 |
-
isTaskPersistent: false,
|
| 151 |
-
selectedElement: null,
|
| 152 |
-
};
|
| 153 |
-
|
| 154 |
-
const chatApiUrl = 'https://www.blackbox.ai/api/chat';
|
| 155 |
-
const headers = {
|
| 156 |
-
Accept: '*/*',
|
| 157 |
-
'Content-Type': 'application/json',
|
| 158 |
-
Origin: 'https://www.blackbox.ai',
|
| 159 |
-
Referer: 'https://www.blackbox.ai/',
|
| 160 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
|
| 161 |
-
};
|
| 162 |
-
|
| 163 |
const chatResponse = await axios.post(chatApiUrl, payload, { headers });
|
| 164 |
const assistantRawResponse = chatResponse.data;
|
| 165 |
const parsedResult = parseApiResponse(assistantRawResponse);
|
| 166 |
-
|
| 167 |
res.send(parsedResult.answer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
} catch (error) {
|
| 170 |
-
console.error("Error
|
| 171 |
-
res.
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
});
|
| 174 |
|
| 175 |
app.listen(PORT, () => {
|
| 176 |
console.log(`Server berjalan di http://localhost:${PORT}`);
|
|
|
|
|
|
|
|
|
|
| 177 |
});
|
| 178 |
EOF
|
| 179 |
|
|
|
|
| 41 |
const email = `${emailUsername}@gmail.com`;
|
| 42 |
const id = Array.from({ length: 21 }, () => Math.floor(Math.random() * 10)).join('');
|
| 43 |
const image = `https://robohash.org/${id}.png?set=set2&bgset=bg1&size=96x96`;
|
|
|
|
| 44 |
return { name: fullName, email, image, id };
|
| 45 |
};
|
| 46 |
|
|
|
|
| 65 |
return { answer: data, sources: [] };
|
| 66 |
};
|
| 67 |
|
| 68 |
+
const createPayload = (prompt, system, web, asyncMode = false) => {
|
| 69 |
+
const newUserMessage = { role: 'user', content: prompt, id: generateId() };
|
| 70 |
+
const messagesForPayload = [newUserMessage];
|
| 71 |
+
|
| 72 |
+
let webSearchModeOption = { autoMode: true, webMode: false, offlineMode: false };
|
| 73 |
+
if (web) {
|
| 74 |
+
const webMode = String(web).toLowerCase();
|
| 75 |
+
if (webMode === 'true') webSearchModeOption = { autoMode: false, webMode: true, offlineMode: false };
|
| 76 |
+
else if (webMode === 'false') webSearchModeOption = { autoMode: false, webMode: false, offlineMode: true };
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
const randomUser = generateRandomUser();
|
| 80 |
+
const expiresDate = new Date();
|
| 81 |
+
expiresDate.setFullYear(expiresDate.getFullYear() + 1);
|
| 82 |
+
|
| 83 |
+
return {
|
| 84 |
+
messages: messagesForPayload,
|
| 85 |
+
id: newUserMessage.id,
|
| 86 |
+
userSystemPrompt: system || null,
|
| 87 |
+
validated: VALIDATED_TOKEN,
|
| 88 |
+
previewToken: null,
|
| 89 |
+
userId: null,
|
| 90 |
+
codeModelMode: true,
|
| 91 |
+
trendingAgentMode: {},
|
| 92 |
+
isMicMode: false,
|
| 93 |
+
maxTokens: 1024,
|
| 94 |
+
playgroundTopP: null,
|
| 95 |
+
playgroundTemperature: null,
|
| 96 |
+
isChromeExt: false,
|
| 97 |
+
githubToken: '',
|
| 98 |
+
clickedAnswer2: false,
|
| 99 |
+
clickedAnswer3: false,
|
| 100 |
+
clickedForceWebSearch: false,
|
| 101 |
+
visitFromDelta: false,
|
| 102 |
+
isMemoryEnabled: false,
|
| 103 |
+
mobileClient: false,
|
| 104 |
+
userSelectedModel: null,
|
| 105 |
+
userSelectedAgent: 'VscodeAgent',
|
| 106 |
+
imageGenerationMode: false,
|
| 107 |
+
imageGenMode: 'autoMode',
|
| 108 |
+
webSearchModePrompt: false,
|
| 109 |
+
deepSearchMode: false,
|
| 110 |
+
domains: null,
|
| 111 |
+
vscodeClient: false,
|
| 112 |
+
codeInterpreterMode: false,
|
| 113 |
+
customProfile: {
|
| 114 |
+
name: '',
|
| 115 |
+
occupation: '',
|
| 116 |
+
traits: [],
|
| 117 |
+
additionalInfo: '',
|
| 118 |
+
enableNewChats: false,
|
| 119 |
+
},
|
| 120 |
+
webSearchModeOption,
|
| 121 |
+
session: {
|
| 122 |
+
user: randomUser,
|
| 123 |
+
expires: expiresDate.toISOString(),
|
| 124 |
+
isNewUser: Math.random() < 0.1,
|
| 125 |
+
},
|
| 126 |
+
isPremium: false,
|
| 127 |
+
subscriptionCache: {
|
| 128 |
+
status: 'FREE',
|
| 129 |
+
expiryTimestamp: null,
|
| 130 |
+
lastChecked: Date.now(),
|
| 131 |
+
isTrialSubscription: false,
|
| 132 |
+
},
|
| 133 |
+
beastMode: false,
|
| 134 |
+
reasoningMode: false,
|
| 135 |
+
designerMode: false,
|
| 136 |
+
workspaceId: '',
|
| 137 |
+
asyncMode,
|
| 138 |
+
integrations: {},
|
| 139 |
+
isTaskPersistent: false,
|
| 140 |
+
selectedElement: null,
|
| 141 |
+
};
|
| 142 |
+
};
|
| 143 |
+
|
| 144 |
app.use(cors());
|
| 145 |
app.use(express.json());
|
| 146 |
|
| 147 |
+
const chatApiUrl = 'https://www.blackbox.ai/api/chat';
|
| 148 |
+
const headers = {
|
| 149 |
+
Accept: '*/*',
|
| 150 |
+
'Content-Type': 'application/json',
|
| 151 |
+
Origin: 'https://www.blackbox.ai',
|
| 152 |
+
Referer: 'https://www.blackbox.ai/',
|
| 153 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
app.post('/api/generate', async (req, res) => {
|
| 157 |
const { prompt, system, web } = req.body;
|
|
|
|
| 158 |
if (!prompt) {
|
| 159 |
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 160 |
}
|
|
|
|
| 161 |
try {
|
| 162 |
+
const payload = createPayload(prompt, system, web, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
const chatResponse = await axios.post(chatApiUrl, payload, { headers });
|
| 164 |
const assistantRawResponse = chatResponse.data;
|
| 165 |
const parsedResult = parseApiResponse(assistantRawResponse);
|
|
|
|
| 166 |
res.send(parsedResult.answer);
|
| 167 |
+
} catch (error) {
|
| 168 |
+
console.error("Error pada /api/generate:", error.message);
|
| 169 |
+
res.status(500).send("Terjadi kesalahan pada server.");
|
| 170 |
+
}
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
app.post('/api/stream', async (req, res) => {
|
| 174 |
+
const { prompt, system, web } = req.body;
|
| 175 |
+
if (!prompt) {
|
| 176 |
+
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 177 |
+
}
|
| 178 |
+
try {
|
| 179 |
+
const payload = createPayload(prompt, system, web, true);
|
| 180 |
+
const chatResponse = await axios.post(chatApiUrl, payload, {
|
| 181 |
+
headers,
|
| 182 |
+
responseType: 'stream'
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
| 186 |
+
res.setHeader('Cache-Control', 'no-cache');
|
| 187 |
+
res.setHeader('Connection', 'keep-alive');
|
| 188 |
+
|
| 189 |
+
chatResponse.data.pipe(res);
|
| 190 |
+
|
| 191 |
+
chatResponse.data.on('error', (err) => {
|
| 192 |
+
console.error("Stream error:", err.message);
|
| 193 |
+
if (!res.headersSent) {
|
| 194 |
+
res.status(500).send("Terjadi kesalahan pada stream.");
|
| 195 |
+
}
|
| 196 |
+
res.end();
|
| 197 |
+
});
|
| 198 |
|
| 199 |
} catch (error) {
|
| 200 |
+
console.error("Error pada /api/stream:", error.message);
|
| 201 |
+
if (!res.headersSent) {
|
| 202 |
+
res.status(500).send("Terjadi kesalahan pada server saat memulai stream.");
|
| 203 |
+
}
|
| 204 |
}
|
| 205 |
});
|
| 206 |
|
| 207 |
app.listen(PORT, () => {
|
| 208 |
console.log(`Server berjalan di http://localhost:${PORT}`);
|
| 209 |
+
console.log('Endpoints tersedia:');
|
| 210 |
+
console.log(' - POST /api/generate (non-streaming)');
|
| 211 |
+
console.log(' - POST /api/stream (streaming)');
|
| 212 |
});
|
| 213 |
EOF
|
| 214 |
|