Update Dockerfile
Browse files- Dockerfile +26 -26
Dockerfile
CHANGED
|
@@ -5,14 +5,14 @@ WORKDIR /app
|
|
| 5 |
|
| 6 |
COPY <<EOF /app/package.json
|
| 7 |
{
|
| 8 |
-
"name": "gemini-
|
| 9 |
"version": "1.0.0",
|
| 10 |
"main": "index.js",
|
| 11 |
"scripts": {
|
| 12 |
"start": "node index.js"
|
| 13 |
},
|
| 14 |
"dependencies": {
|
| 15 |
-
"
|
| 16 |
"cors": "^2.8.5",
|
| 17 |
"express": "^4.19.2"
|
| 18 |
}
|
|
@@ -24,12 +24,11 @@ RUN npm install --only=production
|
|
| 24 |
COPY <<EOF /app/index.js
|
| 25 |
const express = require('express');
|
| 26 |
const cors = require('cors');
|
| 27 |
-
const
|
| 28 |
|
| 29 |
const app = express();
|
| 30 |
const PORT = 7860;
|
| 31 |
-
const
|
| 32 |
-
const API_URL_BASE = "https://generativelanguage.googleapis.com/v1beta/models";
|
| 33 |
|
| 34 |
const apiKeys = [
|
| 35 |
"AIzaSyCL6KXbZDbJ5fBgI4BOrdhJbEDLnuzUL-Y"
|
|
@@ -52,33 +51,34 @@ app.post('/api/generate', async (req, res) => {
|
|
| 52 |
|
| 53 |
try {
|
| 54 |
const apiKey = getRandomApiKey();
|
| 55 |
-
const
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
thinkingConfig: {
|
| 64 |
-
thinkingBudget: 0,
|
| 65 |
-
},
|
| 66 |
-
},
|
| 67 |
};
|
| 68 |
|
| 69 |
-
const
|
| 70 |
-
|
| 71 |
-
|
| 72 |
});
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
} catch (error) {
|
| 78 |
-
console.error("Error saat
|
| 79 |
-
|
| 80 |
-
const data = error.response ? error.response.data : { message: "Internal Server Error" };
|
| 81 |
-
res.status(status).json(data);
|
| 82 |
}
|
| 83 |
});
|
| 84 |
|
|
|
|
| 5 |
|
| 6 |
COPY <<EOF /app/package.json
|
| 7 |
{
|
| 8 |
+
"name": "gemini-api-server",
|
| 9 |
"version": "1.0.0",
|
| 10 |
"main": "index.js",
|
| 11 |
"scripts": {
|
| 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 |
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"
|
|
|
|
| 51 |
|
| 52 |
try {
|
| 53 |
const apiKey = getRandomApiKey();
|
| 54 |
+
const genAI = new GoogleGenerativeAI(apiKey);
|
| 55 |
+
const model = genAI.getGenerativeModel({ model: MODEL_NAME });
|
| 56 |
+
|
| 57 |
+
const generationConfig = {
|
| 58 |
+
temperature: 0.9,
|
| 59 |
+
topK: 1,
|
| 60 |
+
topP: 1,
|
| 61 |
+
maxOutputTokens: 2048,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
};
|
| 63 |
|
| 64 |
+
const result = await model.generateContentStream({
|
| 65 |
+
contents: [{ role: "user", parts: [{ text: prompt }] }],
|
| 66 |
+
generationConfig,
|
| 67 |
});
|
| 68 |
+
|
| 69 |
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
| 70 |
+
res.setHeader('Transfer-Encoding', 'chunked');
|
| 71 |
|
| 72 |
+
for await (const chunk of result.stream) {
|
| 73 |
+
const chunkText = chunk.text();
|
| 74 |
+
res.write(chunkText);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
res.end();
|
| 78 |
|
| 79 |
} catch (error) {
|
| 80 |
+
console.error("Error saat streaming dari Gemini API:", error);
|
| 81 |
+
res.status(500).send("Terjadi kesalahan pada server saat memproses permintaan Anda.");
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
});
|
| 84 |
|