Update Dockerfile
Browse files- Dockerfile +89 -75
Dockerfile
CHANGED
|
@@ -1,81 +1,95 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
EXPOSE 7860
|
| 80 |
|
| 81 |
-
CMD ["
|
|
|
|
| 1 |
+
FROM node:20-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
RUN cat << EOF > package.json
|
| 6 |
+
{
|
| 7 |
+
"name": "gemini-proxy-server",
|
| 8 |
+
"version": "1.0.0",
|
| 9 |
+
"main": "index.js",
|
| 10 |
+
"scripts": {
|
| 11 |
+
"start": "node index.js"
|
| 12 |
+
},
|
| 13 |
+
"dependencies": {
|
| 14 |
+
"axios": "^1.7.2",
|
| 15 |
+
"cors": "^2.8.5",
|
| 16 |
+
"express": "^4.19.2"
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
EOF
|
| 20 |
+
|
| 21 |
+
RUN npm install --only=production
|
| 22 |
+
|
| 23 |
+
RUN cat << EOF > index.js
|
| 24 |
+
const express = require('express');
|
| 25 |
+
const cors = require('cors');
|
| 26 |
+
const axios = require('axios');
|
| 27 |
+
|
| 28 |
+
const app = express();
|
| 29 |
+
const PORT = 7860;
|
| 30 |
+
const MODEL_ID = "gemini-flash-lite-latest";
|
| 31 |
+
const API_URL_BASE = "https://generativelanguage.googleapis.com/v1beta/models";
|
| 32 |
+
|
| 33 |
+
const apiKeys = [
|
| 34 |
+
"apikey1",
|
| 35 |
+
"apikey2",
|
| 36 |
+
"apikey3",
|
| 37 |
+
"apikey4",
|
| 38 |
+
"apikey5"
|
| 39 |
+
];
|
| 40 |
+
|
| 41 |
+
const getRandomApiKey = () => {
|
| 42 |
+
const randomIndex = Math.floor(Math.random() * apiKeys.length);
|
| 43 |
+
return apiKeys[randomIndex];
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
app.use(cors());
|
| 47 |
+
app.use(express.json());
|
| 48 |
+
|
| 49 |
+
app.post('/api/generate', async (req, res) => {
|
| 50 |
+
const { prompt } = req.body;
|
| 51 |
+
|
| 52 |
+
if (!prompt) {
|
| 53 |
+
return res.status(400).json({ error: 'Request body harus menyertakan "prompt"' });
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
try {
|
| 57 |
+
const apiKey = getRandomApiKey();
|
| 58 |
+
const apiUrl = `\${API_URL_BASE}/\${MODEL_ID}:streamGenerateContent?key=\${apiKey}`;
|
| 59 |
+
|
| 60 |
+
const requestBody = {
|
| 61 |
+
contents: [{
|
| 62 |
+
role: "user",
|
| 63 |
+
parts: [{ "text": prompt }],
|
| 64 |
+
}],
|
| 65 |
+
generationConfig: {
|
| 66 |
+
thinkingConfig: {
|
| 67 |
+
thinkingBudget: 0,
|
| 68 |
+
},
|
| 69 |
+
},
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
const geminiResponse = await axios.post(apiUrl, requestBody, {
|
| 73 |
+
headers: { 'Content-Type': 'application/json' },
|
| 74 |
+
responseType: 'stream'
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
res.setHeader('Content-Type', geminiResponse.headers['content-type']);
|
| 78 |
+
geminiResponse.data.pipe(res);
|
| 79 |
+
|
| 80 |
+
} catch (error) {
|
| 81 |
+
console.error("Error saat menghubungi Gemini API:", error.message);
|
| 82 |
+
const status = error.response ? error.response.status : 500;
|
| 83 |
+
const data = error.response ? error.response.data : { message: "Internal Server Error" };
|
| 84 |
+
res.status(status).json(data);
|
| 85 |
+
}
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
app.listen(PORT, () => {
|
| 89 |
+
console.log(`Server berjalan di http://localhost:\${PORT}`);
|
| 90 |
+
});
|
| 91 |
+
EOF
|
| 92 |
|
| 93 |
EXPOSE 7860
|
| 94 |
|
| 95 |
+
CMD ["npm", "start"]
|