scnario commited on
Commit
a661e3d
·
verified ·
1 Parent(s): 0e1d42f

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +22 -57
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
- app.all('/', async(req, res) => {
69
- res.send(`<!DOCTYPE html>
70
- <html lang="en">
71
- <head>
72
- <meta charset="UTF-8">
73
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
74
- <title>API Explorer</title>
75
- <script src="https://cdn.tailwindcss.com"></script>
76
- </head>
77
- <body class="bg-black text-white flex justify-center items-center min-h-screen p-4">
78
- <div class="w-full max-w-lg bg-zinc-900 p-6 rounded-2xl shadow-lg">
79
- <h1 class="text-2xl font-semibold text-center mb-4">API Explorer</h1>
80
-
81
- <!-- Gemini API -->
82
- <div class="mb-4">
83
- <h3 class="text-gray-400 mb-2">Gemini API</h3>
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 {