Ayeantics commited on
Commit
e5b45d3
·
verified ·
1 Parent(s): dd4dc21

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +20 -2
server.js CHANGED
@@ -13,6 +13,16 @@ const openaiKey = process.env.OPENAI_KEY;
13
  const port = 7860;
14
  const baseUrl = getExternalUrl(process.env.SPACE_ID);
15
 
 
 
 
 
 
 
 
 
 
 
16
  let requestDetails = [];
17
  let apiKeyDetails = {}; // Track API key usage and first use timestamp
18
 
@@ -71,8 +81,16 @@ function authenticateApiKey(req, res, next) {
71
  }
72
 
73
  app.use('/api', authenticateApiKey, (req, res, next) => {
 
 
 
 
 
 
 
 
74
  const timestamp = moment().tz("Asia/Tbilisi").format("DD-MMM-YYYY HH:mm");
75
- const displayKey = req.apiKey.substring(0, 4);
76
  const requestData = {
77
  requestNumber: apiKeyDetails[req.apiKey].count,
78
  apiKey: displayKey,
@@ -81,7 +99,7 @@ app.use('/api', authenticateApiKey, (req, res, next) => {
81
  };
82
  requestDetails.push(requestData);
83
 
84
- const detailedLog = `Request ${requestData.requestNumber} on ${requestData.timestamp} from API Key ${displayKey}... with method "${req.method}" and text "${requestData.text}"`;
85
  logAndEmit(detailedLog, true);
86
 
87
  next();
 
13
  const port = 7860;
14
  const baseUrl = getExternalUrl(process.env.SPACE_ID);
15
 
16
+ const allowedModels = [
17
+ 'gpt-3.5-turbo-0125',
18
+ 'gpt-3.5-turbo',
19
+ 'gpt-3.5-turbo-1106',
20
+ 'gpt-3.5-turbo-instruct',
21
+ 'gpt-3.5-turbo-16k',
22
+ 'gpt-3.5-turbo-0613',
23
+ 'gpt-3.5-turbo-16k-0613'
24
+ ];
25
+
26
  let requestDetails = [];
27
  let apiKeyDetails = {}; // Track API key usage and first use timestamp
28
 
 
81
  }
82
 
83
  app.use('/api', authenticateApiKey, (req, res, next) => {
84
+ const urlParts = req.url.split('/');
85
+ const modelId = urlParts.length > 1 ? urlParts[1] : null;
86
+
87
+ // Check if the model ID is part of the allowed models.
88
+ if (!modelId || !allowedModels.includes(modelId)) {
89
+ return res.status(403).send("Access Denied: This model is not allowed.");
90
+ }
91
+
92
  const timestamp = moment().tz("Asia/Tbilisi").format("DD-MMM-YYYY HH:mm");
93
+ const displayKey = req.apiKey.substring(0, 10);
94
  const requestData = {
95
  requestNumber: apiKeyDetails[req.apiKey].count,
96
  apiKey: displayKey,
 
99
  };
100
  requestDetails.push(requestData);
101
 
102
+ const detailedLog = `Request ${requestData.requestNumber} on ${requestData.timestamp} from API Key ${displayKey}... with method "${req.method}" and URL line "${req.url}"`;
103
  logAndEmit(detailedLog, true);
104
 
105
  next();