Update server.js
Browse files
server.js
CHANGED
|
@@ -2,6 +2,8 @@ const express = require('express');
|
|
| 2 |
const axios = require('axios');
|
| 3 |
const fs = require('fs');
|
| 4 |
const path = require('path');
|
|
|
|
|
|
|
| 5 |
//const swaggerUi = require('swagger-ui-express');
|
| 6 |
|
| 7 |
const app = express();
|
|
@@ -63,64 +65,27 @@ async function deepseek(sessionId, prompt) {
|
|
| 63 |
return response;
|
| 64 |
}
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
<input id="geminiQuestion" type="text" placeholder="Enter question"
|
| 85 |
-
class="w-full p-3 bg-zinc-800 text-white rounded-xl border border-gray-700 focus:ring-2 focus:ring-blue-500 outline-none mb-2">
|
| 86 |
-
<input id="geminiSession" type="text" placeholder="Session ID"
|
| 87 |
-
class="w-full p-3 bg-zinc-800 text-white rounded-xl border border-gray-700 focus:ring-2 focus:ring-blue-500 outline-none mb-2">
|
| 88 |
-
<button onclick="callApi('/google/gemini-1.5-pro', 'geminiQuestion', 'geminiSession')"
|
| 89 |
-
class="w-full p-3 bg-blue-600 hover:bg-blue-500 rounded-xl font-semibold transition shadow-md">Execute</button>
|
| 90 |
-
</div>
|
| 91 |
-
|
| 92 |
-
<!-- DeepSeek API -->
|
| 93 |
-
<div class="mb-4">
|
| 94 |
-
<h3 class="text-gray-400 mb-2">DeepSeek API</h3>
|
| 95 |
-
<input id="deepseekQuestion" type="text" placeholder="Enter question"
|
| 96 |
-
class="w-full p-3 bg-zinc-800 text-white rounded-xl border border-gray-700 focus:ring-2 focus:ring-blue-500 outline-none mb-2">
|
| 97 |
-
<input id="deepseekSession" type="text" placeholder="Session ID"
|
| 98 |
-
class="w-full p-3 bg-zinc-800 text-white rounded-xl border border-gray-700 focus:ring-2 focus:ring-blue-500 outline-none mb-2">
|
| 99 |
-
<button onclick="callApi('/deepseek-ai/deepseek-r1-distill-qwen-32b', 'deepseekQuestion', 'deepseekSession')"
|
| 100 |
-
class="w-full p-3 bg-blue-600 hover:bg-blue-500 rounded-xl font-semibold transition shadow-md">Execute</button>
|
| 101 |
-
</div>
|
| 102 |
-
|
| 103 |
-
<!-- Response -->
|
| 104 |
-
<h3 class="text-gray-400 mb-2">Response</h3>
|
| 105 |
-
<pre id="response"
|
| 106 |
-
class="w-full p-4 bg-zinc-800 text-gray-300 rounded-xl border border-gray-700 overflow-x-auto shadow-inner">Waiting for response...</pre>
|
| 107 |
-
</div>
|
| 108 |
-
|
| 109 |
-
<script>
|
| 110 |
-
function callApi(endpoint, questionId, sessionId) {
|
| 111 |
-
const question = document.getElementById(questionId).value;
|
| 112 |
-
const session = document.getElementById(sessionId).value;
|
| 113 |
-
if (!question || !session) return alert("Please fill in all fields");
|
| 114 |
-
|
| 115 |
-
fetch(endpoint + "?question=" + encodeURIComponent(question) + "&sessionId=" + encodeURIComponent(session))
|
| 116 |
-
.then(res => res.json())
|
| 117 |
-
.then(data => document.getElementById("response").innerText = JSON.stringify(data, null, 2))
|
| 118 |
-
.catch(err => document.getElementById("response").innerText = "Error: " + err);
|
| 119 |
-
}
|
| 120 |
-
</script>
|
| 121 |
-
</body>
|
| 122 |
-
</html>`)
|
| 123 |
-
});
|
| 124 |
|
| 125 |
app.get('/google/gemini-1.5-pro', async (req, res) => {
|
| 126 |
try {
|
|
|
|
| 2 |
const axios = require('axios');
|
| 3 |
const fs = require('fs');
|
| 4 |
const path = require('path');
|
| 5 |
+
const os = require('os');
|
| 6 |
+
const bytes = require('bytes');
|
| 7 |
//const swaggerUi = require('swagger-ui-express');
|
| 8 |
|
| 9 |
const app = express();
|
|
|
|
| 65 |
return response;
|
| 66 |
}
|
| 67 |
|
| 68 |
+
const utils = {
|
| 69 |
+
formatSize: (n) => bytes(+n, { unitSeparator: ' ' })
|
| 70 |
+
}
|
| 71 |
|
| 72 |
+
app.all('/', (_, res) => {
|
| 73 |
+
const status = {}
|
| 74 |
+
status['diskUsage'] = cp.execSync('du -sh').toString().split('M')[0] + ' MB'
|
| 75 |
+
|
| 76 |
+
const used = process.memoryUsage()
|
| 77 |
+
for (let x in used) status[x] = utils.formatSize(used[x])
|
| 78 |
+
|
| 79 |
+
const totalmem = os.totalmem()
|
| 80 |
+
const freemem = os.freemem()
|
| 81 |
+
status['memoryUsage'] =
|
| 82 |
+
`${utils.formatSize(totalmem - freemem)} / ${utils.formatSize(totalmem)}`
|
| 83 |
+
res.json({
|
| 84 |
+
router: ['/google/gemini-1.5-pro', '/deepseek-ai/deepseek-r1-distill-qwen-32b'],
|
| 85 |
+
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 86 |
+
status
|
| 87 |
+
})
|
| 88 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
app.get('/google/gemini-1.5-pro', async (req, res) => {
|
| 91 |
try {
|