nirkyy commited on
Commit
b0ad504
·
verified ·
1 Parent(s): 1c1ad2c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +126 -38
Dockerfile CHANGED
@@ -12,7 +12,7 @@ COPY <<EOF /app/package.json
12
  "start": "node index.js"
13
  },
14
  "dependencies": {
15
- "@google/generative-ai": "^0.15.0",
16
  "cors": "^2.8.5",
17
  "express": "^4.19.2"
18
  }
@@ -24,63 +24,151 @@ RUN npm install --only=production
24
  COPY <<EOF /app/index.js
25
  const express = require('express');
26
  const cors = require('cors');
27
- const { GoogleGenerativeAI } = require('@google/generative-ai');
 
28
 
29
  const app = express();
30
  const PORT = 7860;
31
- const MODEL_NAME = "gemini-flash-lite-latest";
32
-
33
- const apiKeys = [
34
- "AIzaSyCL6KXbZDbJ5fBgI4BOrdhJbEDLnuzUL-Y",
35
- "AIzaSyCAI1oirZPlmTyKAOeDUWusKIg9tpNK0zM",
36
- "AIzaSyArvi5HfcPtuFKG2_Kx_C_4Z3voZ31katA",
37
- "AIzaSyBpEJS9KWtnjEhxe5UfmygrRVh0Qx-tydI"
38
- ];
39
-
40
- const getRandomApiKey = () => {
41
- const randomIndex = Math.floor(Math.random() * apiKeys.length);
42
- return apiKeys[randomIndex];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  };
44
 
45
  app.use(cors());
46
  app.use(express.json());
47
 
48
  app.post('/api/generate', async (req, res) => {
49
- const { prompt } = req.body;
50
 
51
  if (!prompt) {
52
  return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
53
  }
54
 
55
  try {
56
- const apiKey = getRandomApiKey();
57
- const genAI = new GoogleGenerativeAI(apiKey);
58
- const model = genAI.getGenerativeModel({ model: MODEL_NAME });
59
-
60
- const generationConfig = {
61
- temperature: 0.9,
62
- topK: 1,
63
- topP: 1,
64
- maxOutputTokens: 2048,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  };
66
 
67
- const result = await model.generateContentStream({
68
- contents: [{ role: "user", parts: [{ text: prompt }] }],
69
- generationConfig,
70
- });
71
-
72
- res.setHeader('Content-Type', 'text/plain; charset=utf-8');
73
- res.setHeader('Transfer-Encoding', 'chunked');
74
-
75
- for await (const chunk of result.stream) {
76
- const chunkText = chunk.text();
77
- res.write(chunkText);
78
- }
79
 
80
- res.end();
81
 
82
  } catch (error) {
83
- console.error("Error saat streaming dari Gemini API:", error);
84
  res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan Anda.");
85
  }
86
  });
 
12
  "start": "node index.js"
13
  },
14
  "dependencies": {
15
+ "axios": "^1.6.8",
16
  "cors": "^2.8.5",
17
  "express": "^4.19.2"
18
  }
 
24
  COPY <<EOF /app/index.js
25
  const express = require('express');
26
  const cors = require('cors');
27
+ const axios = require('axios');
28
+ const crypto = require('crypto');
29
 
30
  const app = express();
31
  const PORT = 7860;
32
+ const VALIDATED_TOKEN = 'a38f5889-8fef-46d4-8ede-bf4668b6a9bb';
33
+
34
+ const firstNames = ['John', 'Jane', 'Alex', 'Emily', 'Chris', 'Katie', 'Michael', 'Sarah', 'David', 'Laura', 'James', 'Linda'];
35
+ const lastNames = ['Smith', 'Doe', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez', 'Wilson'];
36
+
37
+ const generateRandomUser = () => {
38
+ const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
39
+ const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
40
+ const fullName = `${firstName} ${lastName}`;
41
+ const emailUsername = `${firstName.toLowerCase()}.${lastName.toLowerCase()}${Math.floor(Math.random() * 999)}`;
42
+ const email = `${emailUsername}@gmail.com`;
43
+ const id = Array.from({ length: 21 }, () => Math.floor(Math.random() * 10)).join('');
44
+ const image = `https://robohash.org/${id}.png?set=set2&bgset=bg1&size=96x96`;
45
+
46
+ return { name: fullName, email, image, id };
47
+ };
48
+
49
+ const generateId = (size = 7) => {
50
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
51
+ const randomBytes = crypto.randomBytes(size);
52
+ return Array.from({ length: size }, (_, i) => alphabet[randomBytes[i] % alphabet.length]).join('');
53
+ };
54
+
55
+ const parseApiResponse = (data) => {
56
+ const delimiter = '$~~~$';
57
+ if (typeof data === 'string' && data.includes(delimiter)) {
58
+ const parts = data.split(delimiter);
59
+ try {
60
+ const sources = JSON.parse(parts[1]);
61
+ const answer = parts[2] ? parts[2].trim() : '';
62
+ return { answer, sources };
63
+ } catch {
64
+ return { answer: data, sources: [] };
65
+ }
66
+ }
67
+ return { answer: data, sources: [] };
68
  };
69
 
70
  app.use(cors());
71
  app.use(express.json());
72
 
73
  app.post('/api/generate', async (req, res) => {
74
+ const { prompt, system, web } = req.body;
75
 
76
  if (!prompt) {
77
  return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
78
  }
79
 
80
  try {
81
+ const newUserMessage = { role: 'user', content: prompt, id: generateId() };
82
+ const messagesForPayload = [newUserMessage];
83
+
84
+ let webSearchModeOption = { autoMode: true, webMode: false, offlineMode: false };
85
+ if (web) {
86
+ const webMode = String(web).toLowerCase();
87
+ if (webMode === 'true') webSearchModeOption = { autoMode: false, webMode: true, offlineMode: false };
88
+ else if (webMode === 'false') webSearchModeOption = { autoMode: false, webMode: false, offlineMode: true };
89
+ }
90
+
91
+ const randomUser = generateRandomUser();
92
+ const expiresDate = new Date();
93
+ expiresDate.setFullYear(expiresDate.getFullYear() + 1);
94
+
95
+ const payload = {
96
+ messages: messagesForPayload,
97
+ id: newUserMessage.id,
98
+ userSystemPrompt: system || 'You are a helpful assistant.',
99
+ validated: VALIDATED_TOKEN,
100
+ previewToken: null,
101
+ userId: null,
102
+ codeModelMode: true,
103
+ trendingAgentMode: {},
104
+ isMicMode: false,
105
+ maxTokens: 1024,
106
+ playgroundTopP: null,
107
+ playgroundTemperature: null,
108
+ isChromeExt: false,
109
+ githubToken: '',
110
+ clickedAnswer2: false,
111
+ clickedAnswer3: false,
112
+ clickedForceWebSearch: false,
113
+ visitFromDelta: false,
114
+ isMemoryEnabled: false, // Set to false based on prompt instruction "tanpa user dan memory"
115
+ mobileClient: false,
116
+ userSelectedModel: null,
117
+ userSelectedAgent: 'VscodeAgent',
118
+ imageGenerationMode: false,
119
+ imageGenMode: 'autoMode',
120
+ webSearchModePrompt: false,
121
+ deepSearchMode: false,
122
+ domains: null,
123
+ vscodeClient: false,
124
+ codeInterpreterMode: false,
125
+ customProfile: {
126
+ name: '',
127
+ occupation: '',
128
+ traits: [],
129
+ additionalInfo: '',
130
+ enableNewChats: false,
131
+ },
132
+ webSearchModeOption,
133
+ session: {
134
+ user: randomUser,
135
+ expires: expiresDate.toISOString(),
136
+ isNewUser: Math.random() < 0.1,
137
+ },
138
+ isPremium: false,
139
+ subscriptionCache: {
140
+ status: 'FREE',
141
+ expiryTimestamp: null,
142
+ lastChecked: Date.now(),
143
+ isTrialSubscription: false,
144
+ },
145
+ beastMode: false,
146
+ reasoningMode: false,
147
+ designerMode: false,
148
+ workspaceId: '',
149
+ asyncMode: false,
150
+ integrations: {},
151
+ isTaskPersistent: false,
152
+ selectedElement: null,
153
  };
154
 
155
+ const chatApiUrl = 'https://www.blackbox.ai/api/chat';
156
+ const headers = {
157
+ Accept: '*/*',
158
+ 'Content-Type': 'application/json',
159
+ Origin: 'https://www.blackbox.ai',
160
+ Referer: 'https://www.blackbox.ai/',
161
+ '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',
162
+ };
163
+
164
+ const chatResponse = await axios.post(chatApiUrl, payload, { headers });
165
+ const assistantRawResponse = chatResponse.data;
166
+ const parsedResult = parseApiResponse(assistantRawResponse);
167
 
168
+ res.send(parsedResult.answer);
169
 
170
  } catch (error) {
171
+ console.error("Error saat scraping Blackbox AI:", error);
172
  res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan Anda.");
173
  }
174
  });