235e9839 by Administrator

Merge branch '30852_chatbot_chatgpt' into 'master'

30852 chatbot chatgpt

See merge request !100
2 parents 2530d769 cbee02a0
...@@ -71,14 +71,6 @@ function App() { ...@@ -71,14 +71,6 @@ function App() {
71 TPLogicRun(); 71 TPLogicRun();
72 } 72 }
73 73
74 // eslint-disable-next-line
75 btutil_getChatUsage();
76 // eslint-disable-next-line
77 let maxTokens = btutilCommon_getCookie("mucnxwlyxt");
78 if (maxTokens==='1'){
79 return;
80 }
81
82 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who']; 74 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who'];
83 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); 75 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi');
84 const inputMatches = chatInput.match(userInputRegex); 76 const inputMatches = chatInput.match(userInputRegex);
...@@ -120,6 +112,7 @@ function App() { ...@@ -120,6 +112,7 @@ function App() {
120 } 112 }
121 113
122 let intervalId = startInterval(); 114 let intervalId = startInterval();
115
123 try { 116 try {
124 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 117 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
125 method: "POST", 118 method: "POST",
...@@ -133,7 +126,20 @@ function App() { ...@@ -133,7 +126,20 @@ function App() {
133 }) 126 })
134 }); 127 });
135 const data = await response.json(); 128 const data = await response.json();
136 const parsedData = data.message.trim(); 129 const parsedData = data.message ? data.message.trim() : "";
130
131 if(data.status === 'invalid'){
132 if(data.limited) {
133 window.btutil_modalRegisterUpgrade();
134 return;
135 }
136 if(data && data.status === 'max-tokens') {
137 window.btutil_maxUsage();
138 return;
139 }
140 window.btutil_modalRegisterUpgrade(true);
141 return;
142 }
137 // "gpt-3.5-turbo" 143 // "gpt-3.5-turbo"
138 let chatLogTurboNew = chatLogTurbo; 144 let chatLogTurboNew = chatLogTurbo;
139 let chatLogOpenSourceNew = chatLogOpenSource; 145 let chatLogOpenSourceNew = chatLogOpenSource;
...@@ -144,9 +150,7 @@ function App() { ...@@ -144,9 +150,7 @@ function App() {
144 }); 150 });
145 userModifiedInput = ""; 151 userModifiedInput = "";
146 } 152 }
147 if(data.usage) { 153
148 window.btutil_setChatUsage('chatbot+', data.usage.prompt_tokens, data.usage.total_tokens);
149 }
150 chatLogTurboNew.push({ role: "user", content: userModifiedInput }); 154 chatLogTurboNew.push({ role: "user", content: userModifiedInput });
151 chatLogTurboNew.push({ role: "assistant", content: parsedData }); 155 chatLogTurboNew.push({ role: "assistant", content: parsedData });
152 156
...@@ -187,6 +191,7 @@ function App() { ...@@ -187,6 +191,7 @@ function App() {
187 } 191 }
188 192
189 } catch (error) { 193 } catch (error) {
194 console.log(error)
190 const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again."; 195 const errorMsg = "We apologize for any inconvenience caused due to the delay in the response time. Please try again.";
191 setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ]) 196 setChatLog([...chatLogNew, { user: "gpt", message: `<div class="errormsg"><span>i</span><div class="msg">${errorMsg}</div></div>`} ])
192 } 197 }
......
1 const { Configuration, OpenAIApi } = require("openai"); 1 const { Configuration, OpenAIApi } = require("openai");
2 const express = require('express') 2 const express = require('express')
3 const bodyParser = require('body-parser') 3 const bodyParser = require('body-parser')
4 const cookieParser = require("cookie-parser")
4 const cors = require('cors') 5 const cors = require('cors')
5 require('dotenv').config() 6 require('dotenv').config()
6 const rateLimit = require('express-rate-limit') 7 const rateLimit = require('express-rate-limit')
8 const fetch = require('node-fetch');
7 const anchorme = require("anchorme").default; 9 const anchorme = require("anchorme").default;
8 const axios = require('axios'); 10 const axios = require('axios');
9 const { encodingForModel } = require('js-tiktoken'); 11 const { encodingForModel } = require('js-tiktoken');
...@@ -68,10 +70,13 @@ app.use(bodyParser.json()) ...@@ -68,10 +70,13 @@ app.use(bodyParser.json())
68 app.use(cors()) 70 app.use(cors())
69 app.use(require('morgan')('dev')) 71 app.use(require('morgan')('dev'))
70 app.use(rateLimiter) 72 app.use(rateLimiter)
73 app.use(cookieParser());
71 74
72 const max_tokens = process.env.MAX_TOKENS_chatbot_plus ? parseInt(process.env.MAX_TOKENS_chatbot_plus) : 512; 75 const max_tokens = process.env.MAX_TOKENS_chatbot_plus ? parseInt(process.env.MAX_TOKENS_chatbot_plus) : 512;
73 // Routing 76 // Routing
74 77 const hostapi = process.env.REACT_APP_HOST_API || "https://api.ai-pro.org";
78 const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in";
79 const aiwp_app_id = "chatbot+";
75 // Primary Open AI Route 80 // Primary Open AI Route
76 app.post('/api', async (req, res) => { 81 app.post('/api', async (req, res) => {
77 if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) { 82 if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) {
...@@ -83,14 +88,20 @@ app.post('/api', async (req, res) => { ...@@ -83,14 +88,20 @@ app.post('/api', async (req, res) => {
83 88
84 if (currentModel == "gpt-3.5-turbo" || currentModel == "gpt-3.5-turbo-0301") { 89 if (currentModel == "gpt-3.5-turbo" || currentModel == "gpt-3.5-turbo-0301") {
85 runGPTTurbo(req, res); 90 runGPTTurbo(req, res);
91
86 return; 92 return;
87 } 93 }
88 94
89 if (currentModel == "openchat_3.5" || currentModel == "zephyr-7B-beta") { 95 if (currentModel == "openchat_3.5" || currentModel == "zephyr-7B-beta") {
90 runOpensource(req, res); 96 runOpensource(req, res);
97
91 return; 98 return;
92 } 99 }
93 100
101 const validate = await validation(aiwp_app_id, req, res);
102 if(!validate) return;
103 const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
104
94 let greetingPrompt = 'Hello, how can I assist you?' 105 let greetingPrompt = 'Hello, how can I assist you?'
95 const greetings = ['hi', 'hello', 'hey'] 106 const greetings = ['hi', 'hello', 'hey']
96 if (greetings.some((greeting) => message.toLowerCase().includes(greeting))) { 107 if (greetings.some((greeting) => message.toLowerCase().includes(greeting))) {
...@@ -136,10 +147,15 @@ app.post('/api', async (req, res) => { ...@@ -136,10 +147,15 @@ app.post('/api', async (req, res) => {
136 usage.prompt_tokens = (enc.encode(query_prompt)).length; 147 usage.prompt_tokens = (enc.encode(query_prompt)).length;
137 usage.completion_tokens = (enc.encode(input)).length; 148 usage.completion_tokens = (enc.encode(input)).length;
138 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens; 149 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
150
139 } catch (e) { 151 } catch (e) {
140 console.log('Error encoding prompt text', e); 152 console.log('Error encoding prompt text', e);
141 } 153 }
142 154 if(IS_FREE_USER) {
155 await setUsage({
156 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
157 });
158 }
143 res.json({ 159 res.json({
144 usage: usage, 160 usage: usage,
145 message: anchorme({ 161 message: anchorme({
...@@ -174,6 +190,10 @@ async function runGPTTurbo(req, res) { ...@@ -174,6 +190,10 @@ async function runGPTTurbo(req, res) {
174 const moderation = await axios.post("https://api.openai.com/v1/moderations", { 190 const moderation = await axios.post("https://api.openai.com/v1/moderations", {
175 input: query_prompt 191 input: query_prompt
176 }, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } }); 192 }, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } });
193
194 const validate = await validation(aiwp_app_id, req, res);
195 if(!validate) return;
196 const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
177 197
178 if (moderation.data.results[0].flagged) { 198 if (moderation.data.results[0].flagged) {
179 res.json({ 199 res.json({
...@@ -210,7 +230,11 @@ async function runGPTTurbo(req, res) { ...@@ -210,7 +230,11 @@ async function runGPTTurbo(req, res) {
210 } catch (e) { 230 } catch (e) {
211 console.log('Error encoding prompt text', e); 231 console.log('Error encoding prompt text', e);
212 } 232 }
213 233 if(IS_FREE_USER) {
234 await setUsage({
235 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
236 });
237 }
214 res.json({ 238 res.json({
215 prompt: JSON.parse(message), 239 prompt: JSON.parse(message),
216 usage: usage, 240 usage: usage,
...@@ -244,7 +268,11 @@ async function runOpensource(req, res) { ...@@ -244,7 +268,11 @@ async function runOpensource(req, res) {
244 var input = ''; 268 var input = '';
245 const message_history = JSON.parse(message); 269 const message_history = JSON.parse(message);
246 const query_prompt = message_history.length ? message_history[message_history.length - 1].content : ""; 270 const query_prompt = message_history.length ? message_history[message_history.length - 1].content : "";
247 271
272 const validate = await validation(aiwp_app_id, req, res);
273 if(!validate) return;
274 const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
275
248 try { 276 try {
249 let error_msg = ""; 277 let error_msg = "";
250 const endpoint_api_url = get_endpoint_api_url(currentModel); 278 const endpoint_api_url = get_endpoint_api_url(currentModel);
...@@ -303,6 +331,114 @@ async function runOpensource(req, res) { ...@@ -303,6 +331,114 @@ async function runOpensource(req, res) {
303 } 331 }
304 } 332 }
305 333
334 async function authenticate(params) {
335 let data = await fetch(`${hostapi}/e/authenticate/v2`, {
336 method: "POST",
337 headers: {
338 "Content-Type": "application/json"
339 },
340 body: JSON.stringify(params),
341 referrer: "https://chatgpt.ai-pro.org"
342 });
343 return await data.json();
344 }
345
346 async function getLimitedUsage(params) {
347 let data = await fetch(`${hostapi}/e/get-usage`, {
348 method: "POST",
349 headers: {
350 "Content-Type": "application/json"
351 },
352 body: JSON.stringify(params),
353 referrer: "https://chatgpt.ai-pro.org"
354 });
355 return await data.json();
356 }
357 async function getUsage(params) {
358 let data = await fetch(`${hostapi}/e/get-chat-usage`, {
359 method: "POST",
360 headers: {
361 "Content-Type": "application/json"
362 },
363 body: JSON.stringify(params),
364 referrer: "https://chatgpt.ai-pro.org"
365 });
366 return await data.json();
367 }
368 async function setUsage(params) {
369 fetch(`${hostapi}/e/set-usage`, {
370 method: "POST",
371 headers: {
372 "Content-Type": "application/json"
373 },
374 body: JSON.stringify(params),
375 referrer: "https://chatgpt.ai-pro.org"
376 });
377 fetch(`${hostapi}/e/set-chat-usage`, {
378 method: "POST",
379 headers: {
380 "Content-Type": "application/json"
381 },
382 body: JSON.stringify(params),
383 referrer: "https://chatgpt.ai-pro.org"
384 });
385 }
386
387 async function validation (aiwp_app_id, req, res) {
388 const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : "";
389 const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : 3;
390 let IS_FREE_USER = false;
391 let TRIED_USAGE = 0;
392
393 if (aiwp_logged_in) {
394 let auth = await authenticate({ aiwp_logged_in, user_event_data: {}, user_event: 'endpoint' });
395 if (!auth.success) {
396 IS_FREE_USER = true;
397 if (auth.is_restrict) {
398 res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
399 res.end();
400 return false;
401 } else if (typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
402 res.json({ status: "invalid", restrict: true });
403 res.end();
404 return false;
405 }
406 }
407 if (!auth.subscription_type || (auth.auth_version === 'v2' && auth.subscription_type.toLowerCase() === 'basic')) {
408 res.json({ status: "invalid" });
409 res.status(200);
410 return false;
411 }
412 let data = await getUsage({
413 aiwp_logged_in, app: 'chatbot+'
414 });
415
416 if (!(data.success === 1 && data.status === 'valid')) {
417 res.json({ status: "invalid", data });
418 res.status(200);
419 return false;
420 }
421 } else {
422 IS_FREE_USER = true;
423 let data = await getLimitedUsage({
424 aiwp_app_id
425 });
426
427 if (data.usage !== null) {
428 TRIED_USAGE = parseInt(data.usage);
429 }
430
431 }
432 if (IS_FREE_USER && TRIED_USAGE >= limit) {
433 res.json({ status: "invalid", limited: true });
434 res.end();
435 return false;
436 }
437 if (IS_FREE_USER) TRIED_USAGE++;
438
439 return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE };
440 };
441
306 442
307 443
308 // Get Models Route 444 // Get Models Route
......
...@@ -13,13 +13,14 @@ ...@@ -13,13 +13,14 @@
13 "axios": "^1.5.1", 13 "axios": "^1.5.1",
14 "body-parser": "^1.20.1", 14 "body-parser": "^1.20.1",
15 "cookie": "0.5.0", 15 "cookie": "0.5.0",
16 "cookie-parser": "1.4.6", 16 "cookie-parser": "^1.4.6",
17 "cors": "^2.8.5", 17 "cors": "^2.8.5",
18 "dotenv": "^16.0.3", 18 "dotenv": "^16.0.3",
19 "express": "^4.18.2", 19 "express": "^4.18.2",
20 "express-rate-limit": "^6.7.0", 20 "express-rate-limit": "^6.7.0",
21 "js-tiktoken": "1.0.7", 21 "js-tiktoken": "1.0.7",
22 "morgan": "^1.10.0", 22 "morgan": "^1.10.0",
23 "node-fetch": "^2.7.0",
23 "openai": "^3.2.0" 24 "openai": "^3.2.0"
24 } 25 }
25 }, 26 },
...@@ -51,11 +52,11 @@ ...@@ -51,11 +52,11 @@
51 "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" 52 "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
52 }, 53 },
53 "node_modules/axios": { 54 "node_modules/axios": {
54 "version": "1.6.2", 55 "version": "1.6.8",
55 "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", 56 "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
56 "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", 57 "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
57 "dependencies": { 58 "dependencies": {
58 "follow-redirects": "^1.15.0", 59 "follow-redirects": "^1.15.6",
59 "form-data": "^4.0.0", 60 "form-data": "^4.0.0",
60 "proxy-from-env": "^1.1.0" 61 "proxy-from-env": "^1.1.0"
61 } 62 }
...@@ -96,12 +97,12 @@ ...@@ -96,12 +97,12 @@
96 "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 97 "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
97 }, 98 },
98 "node_modules/body-parser": { 99 "node_modules/body-parser": {
99 "version": "1.20.1", 100 "version": "1.20.2",
100 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", 101 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
101 "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", 102 "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
102 "dependencies": { 103 "dependencies": {
103 "bytes": "3.1.2", 104 "bytes": "3.1.2",
104 "content-type": "~1.0.4", 105 "content-type": "~1.0.5",
105 "debug": "2.6.9", 106 "debug": "2.6.9",
106 "depd": "2.0.0", 107 "depd": "2.0.0",
107 "destroy": "1.2.0", 108 "destroy": "1.2.0",
...@@ -109,7 +110,7 @@ ...@@ -109,7 +110,7 @@
109 "iconv-lite": "0.4.24", 110 "iconv-lite": "0.4.24",
110 "on-finished": "2.4.1", 111 "on-finished": "2.4.1",
111 "qs": "6.11.0", 112 "qs": "6.11.0",
112 "raw-body": "2.5.1", 113 "raw-body": "2.5.2",
113 "type-is": "~1.6.18", 114 "type-is": "~1.6.18",
114 "unpipe": "1.0.0" 115 "unpipe": "1.0.0"
115 }, 116 },
...@@ -127,12 +128,18 @@ ...@@ -127,12 +128,18 @@
127 } 128 }
128 }, 129 },
129 "node_modules/call-bind": { 130 "node_modules/call-bind": {
130 "version": "1.0.2", 131 "version": "1.0.7",
131 "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", 132 "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz",
132 "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", 133 "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
133 "dependencies": { 134 "dependencies": {
134 "function-bind": "^1.1.1", 135 "es-define-property": "^1.0.0",
135 "get-intrinsic": "^1.0.2" 136 "es-errors": "^1.3.0",
137 "function-bind": "^1.1.2",
138 "get-intrinsic": "^1.2.4",
139 "set-function-length": "^1.2.1"
140 },
141 "engines": {
142 "node": ">= 0.4"
136 }, 143 },
137 "funding": { 144 "funding": {
138 "url": "https://github.com/sponsors/ljharb" 145 "url": "https://github.com/sponsors/ljharb"
...@@ -221,6 +228,22 @@ ...@@ -221,6 +228,22 @@
221 "ms": "2.0.0" 228 "ms": "2.0.0"
222 } 229 }
223 }, 230 },
231 "node_modules/define-data-property": {
232 "version": "1.1.4",
233 "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz",
234 "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
235 "dependencies": {
236 "es-define-property": "^1.0.0",
237 "es-errors": "^1.3.0",
238 "gopd": "^1.0.1"
239 },
240 "engines": {
241 "node": ">= 0.4"
242 },
243 "funding": {
244 "url": "https://github.com/sponsors/ljharb"
245 }
246 },
224 "node_modules/delayed-stream": { 247 "node_modules/delayed-stream": {
225 "version": "1.0.0", 248 "version": "1.0.0",
226 "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 249 "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
...@@ -247,11 +270,14 @@ ...@@ -247,11 +270,14 @@
247 } 270 }
248 }, 271 },
249 "node_modules/dotenv": { 272 "node_modules/dotenv": {
250 "version": "16.0.3", 273 "version": "16.4.5",
251 "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", 274 "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
252 "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", 275 "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
253 "engines": { 276 "engines": {
254 "node": ">=12" 277 "node": ">=12"
278 },
279 "funding": {
280 "url": "https://dotenvx.com"
255 } 281 }
256 }, 282 },
257 "node_modules/ee-first": { 283 "node_modules/ee-first": {
...@@ -267,6 +293,25 @@ ...@@ -267,6 +293,25 @@
267 "node": ">= 0.8" 293 "node": ">= 0.8"
268 } 294 }
269 }, 295 },
296 "node_modules/es-define-property": {
297 "version": "1.0.0",
298 "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
299 "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
300 "dependencies": {
301 "get-intrinsic": "^1.2.4"
302 },
303 "engines": {
304 "node": ">= 0.4"
305 }
306 },
307 "node_modules/es-errors": {
308 "version": "1.3.0",
309 "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
310 "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
311 "engines": {
312 "node": ">= 0.4"
313 }
314 },
270 "node_modules/escape-html": { 315 "node_modules/escape-html": {
271 "version": "1.0.3", 316 "version": "1.0.3",
272 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 317 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
...@@ -281,16 +326,16 @@ ...@@ -281,16 +326,16 @@
281 } 326 }
282 }, 327 },
283 "node_modules/express": { 328 "node_modules/express": {
284 "version": "4.18.2", 329 "version": "4.19.2",
285 "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", 330 "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz",
286 "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", 331 "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==",
287 "dependencies": { 332 "dependencies": {
288 "accepts": "~1.3.8", 333 "accepts": "~1.3.8",
289 "array-flatten": "1.1.1", 334 "array-flatten": "1.1.1",
290 "body-parser": "1.20.1", 335 "body-parser": "1.20.2",
291 "content-disposition": "0.5.4", 336 "content-disposition": "0.5.4",
292 "content-type": "~1.0.4", 337 "content-type": "~1.0.4",
293 "cookie": "0.5.0", 338 "cookie": "0.6.0",
294 "cookie-signature": "1.0.6", 339 "cookie-signature": "1.0.6",
295 "debug": "2.6.9", 340 "debug": "2.6.9",
296 "depd": "2.0.0", 341 "depd": "2.0.0",
...@@ -322,9 +367,9 @@ ...@@ -322,9 +367,9 @@
322 } 367 }
323 }, 368 },
324 "node_modules/express-rate-limit": { 369 "node_modules/express-rate-limit": {
325 "version": "6.11.1", 370 "version": "6.11.2",
326 "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.11.1.tgz", 371 "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-6.11.2.tgz",
327 "integrity": "sha512-8+UpWtQY25lJaa4+3WxDBGDcAu4atcTruSs3QSL5VPEplYy6kmk84wutG9rUkkK5LmMQQ7TFHWLZYITwVNbbEg==", 372 "integrity": "sha512-a7uwwfNTh1U60ssiIkuLFWHt4hAC5yxlLGU2VP0X4YNlyEDZAqF4tK3GD3NSitVBrCQmQ0++0uOyFOgC2y4DDw==",
328 "engines": { 373 "engines": {
329 "node": ">= 14" 374 "node": ">= 14"
330 }, 375 },
...@@ -332,6 +377,14 @@ ...@@ -332,6 +377,14 @@
332 "express": "^4 || ^5" 377 "express": "^4 || ^5"
333 } 378 }
334 }, 379 },
380 "node_modules/express/node_modules/cookie": {
381 "version": "0.6.0",
382 "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
383 "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
384 "engines": {
385 "node": ">= 0.6"
386 }
387 },
335 "node_modules/finalhandler": { 388 "node_modules/finalhandler": {
336 "version": "1.2.0", 389 "version": "1.2.0",
337 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", 390 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
...@@ -350,9 +403,9 @@ ...@@ -350,9 +403,9 @@
350 } 403 }
351 }, 404 },
352 "node_modules/follow-redirects": { 405 "node_modules/follow-redirects": {
353 "version": "1.15.2", 406 "version": "1.15.6",
354 "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", 407 "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
355 "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", 408 "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
356 "funding": [ 409 "funding": [
357 { 410 {
358 "type": "individual", 411 "type": "individual",
...@@ -398,32 +451,62 @@ ...@@ -398,32 +451,62 @@
398 } 451 }
399 }, 452 },
400 "node_modules/function-bind": { 453 "node_modules/function-bind": {
401 "version": "1.1.1", 454 "version": "1.1.2",
402 "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", 455 "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
403 "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" 456 "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
457 "funding": {
458 "url": "https://github.com/sponsors/ljharb"
459 }
404 }, 460 },
405 "node_modules/get-intrinsic": { 461 "node_modules/get-intrinsic": {
406 "version": "1.2.0", 462 "version": "1.2.4",
407 "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", 463 "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
408 "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", 464 "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
465 "dependencies": {
466 "es-errors": "^1.3.0",
467 "function-bind": "^1.1.2",
468 "has-proto": "^1.0.1",
469 "has-symbols": "^1.0.3",
470 "hasown": "^2.0.0"
471 },
472 "engines": {
473 "node": ">= 0.4"
474 },
475 "funding": {
476 "url": "https://github.com/sponsors/ljharb"
477 }
478 },
479 "node_modules/gopd": {
480 "version": "1.0.1",
481 "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
482 "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
409 "dependencies": { 483 "dependencies": {
410 "function-bind": "^1.1.1", 484 "get-intrinsic": "^1.1.3"
411 "has": "^1.0.3",
412 "has-symbols": "^1.0.3"
413 }, 485 },
414 "funding": { 486 "funding": {
415 "url": "https://github.com/sponsors/ljharb" 487 "url": "https://github.com/sponsors/ljharb"
416 } 488 }
417 }, 489 },
418 "node_modules/has": { 490 "node_modules/has-property-descriptors": {
419 "version": "1.0.3", 491 "version": "1.0.2",
420 "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", 492 "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
421 "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", 493 "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
422 "dependencies": { 494 "dependencies": {
423 "function-bind": "^1.1.1" 495 "es-define-property": "^1.0.0"
424 }, 496 },
497 "funding": {
498 "url": "https://github.com/sponsors/ljharb"
499 }
500 },
501 "node_modules/has-proto": {
502 "version": "1.0.3",
503 "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz",
504 "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==",
425 "engines": { 505 "engines": {
426 "node": ">= 0.4.0" 506 "node": ">= 0.4"
507 },
508 "funding": {
509 "url": "https://github.com/sponsors/ljharb"
427 } 510 }
428 }, 511 },
429 "node_modules/has-symbols": { 512 "node_modules/has-symbols": {
...@@ -437,6 +520,17 @@ ...@@ -437,6 +520,17 @@
437 "url": "https://github.com/sponsors/ljharb" 520 "url": "https://github.com/sponsors/ljharb"
438 } 521 }
439 }, 522 },
523 "node_modules/hasown": {
524 "version": "2.0.2",
525 "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
526 "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
527 "dependencies": {
528 "function-bind": "^1.1.2"
529 },
530 "engines": {
531 "node": ">= 0.4"
532 }
533 },
440 "node_modules/http-errors": { 534 "node_modules/http-errors": {
441 "version": "2.0.0", 535 "version": "2.0.0",
442 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", 536 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
...@@ -574,6 +668,25 @@ ...@@ -574,6 +668,25 @@
574 "node": ">= 0.6" 668 "node": ">= 0.6"
575 } 669 }
576 }, 670 },
671 "node_modules/node-fetch": {
672 "version": "2.7.0",
673 "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
674 "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
675 "dependencies": {
676 "whatwg-url": "^5.0.0"
677 },
678 "engines": {
679 "node": "4.x || >=6.0.0"
680 },
681 "peerDependencies": {
682 "encoding": "^0.1.0"
683 },
684 "peerDependenciesMeta": {
685 "encoding": {
686 "optional": true
687 }
688 }
689 },
577 "node_modules/object-assign": { 690 "node_modules/object-assign": {
578 "version": "4.1.1", 691 "version": "4.1.1",
579 "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 692 "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
...@@ -583,9 +696,9 @@ ...@@ -583,9 +696,9 @@
583 } 696 }
584 }, 697 },
585 "node_modules/object-inspect": { 698 "node_modules/object-inspect": {
586 "version": "1.12.3", 699 "version": "1.13.1",
587 "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", 700 "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",
588 "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", 701 "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==",
589 "funding": { 702 "funding": {
590 "url": "https://github.com/sponsors/ljharb" 703 "url": "https://github.com/sponsors/ljharb"
591 } 704 }
...@@ -679,9 +792,9 @@ ...@@ -679,9 +792,9 @@
679 } 792 }
680 }, 793 },
681 "node_modules/raw-body": { 794 "node_modules/raw-body": {
682 "version": "2.5.1", 795 "version": "2.5.2",
683 "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", 796 "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
684 "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", 797 "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
685 "dependencies": { 798 "dependencies": {
686 "bytes": "3.1.2", 799 "bytes": "3.1.2",
687 "http-errors": "2.0.0", 800 "http-errors": "2.0.0",
...@@ -758,19 +871,39 @@ ...@@ -758,19 +871,39 @@
758 "node": ">= 0.8.0" 871 "node": ">= 0.8.0"
759 } 872 }
760 }, 873 },
874 "node_modules/set-function-length": {
875 "version": "1.2.2",
876 "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz",
877 "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",
878 "dependencies": {
879 "define-data-property": "^1.1.4",
880 "es-errors": "^1.3.0",
881 "function-bind": "^1.1.2",
882 "get-intrinsic": "^1.2.4",
883 "gopd": "^1.0.1",
884 "has-property-descriptors": "^1.0.2"
885 },
886 "engines": {
887 "node": ">= 0.4"
888 }
889 },
761 "node_modules/setprototypeof": { 890 "node_modules/setprototypeof": {
762 "version": "1.2.0", 891 "version": "1.2.0",
763 "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", 892 "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
764 "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" 893 "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
765 }, 894 },
766 "node_modules/side-channel": { 895 "node_modules/side-channel": {
767 "version": "1.0.4", 896 "version": "1.0.6",
768 "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", 897 "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
769 "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", 898 "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==",
770 "dependencies": { 899 "dependencies": {
771 "call-bind": "^1.0.0", 900 "call-bind": "^1.0.7",
772 "get-intrinsic": "^1.0.2", 901 "es-errors": "^1.3.0",
773 "object-inspect": "^1.9.0" 902 "get-intrinsic": "^1.2.4",
903 "object-inspect": "^1.13.1"
904 },
905 "engines": {
906 "node": ">= 0.4"
774 }, 907 },
775 "funding": { 908 "funding": {
776 "url": "https://github.com/sponsors/ljharb" 909 "url": "https://github.com/sponsors/ljharb"
...@@ -792,6 +925,11 @@ ...@@ -792,6 +925,11 @@
792 "node": ">=0.6" 925 "node": ">=0.6"
793 } 926 }
794 }, 927 },
928 "node_modules/tr46": {
929 "version": "0.0.3",
930 "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
931 "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
932 },
795 "node_modules/type-is": { 933 "node_modules/type-is": {
796 "version": "1.6.18", 934 "version": "1.6.18",
797 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 935 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
...@@ -827,6 +965,20 @@ ...@@ -827,6 +965,20 @@
827 "engines": { 965 "engines": {
828 "node": ">= 0.8" 966 "node": ">= 0.8"
829 } 967 }
968 },
969 "node_modules/webidl-conversions": {
970 "version": "3.0.1",
971 "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
972 "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
973 },
974 "node_modules/whatwg-url": {
975 "version": "5.0.0",
976 "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
977 "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
978 "dependencies": {
979 "tr46": "~0.0.3",
980 "webidl-conversions": "^3.0.0"
981 }
830 } 982 }
831 } 983 }
832 } 984 }
......
...@@ -10,17 +10,18 @@ ...@@ -10,17 +10,18 @@
10 "author": "", 10 "author": "",
11 "license": "ISC", 11 "license": "ISC",
12 "dependencies": { 12 "dependencies": {
13 "js-tiktoken": "1.0.7",
14 "anchorme": "^2.1.2", 13 "anchorme": "^2.1.2",
15 "axios": "^1.5.1", 14 "axios": "^1.5.1",
16 "body-parser": "^1.20.1", 15 "body-parser": "^1.20.1",
17 "cookie": "0.5.0", 16 "cookie": "0.5.0",
18 "cookie-parser": "1.4.6", 17 "cookie-parser": "^1.4.6",
19 "cors": "^2.8.5", 18 "cors": "^2.8.5",
20 "dotenv": "^16.0.3", 19 "dotenv": "^16.0.3",
21 "express": "^4.18.2", 20 "express": "^4.18.2",
22 "express-rate-limit": "^6.7.0", 21 "express-rate-limit": "^6.7.0",
22 "js-tiktoken": "1.0.7",
23 "morgan": "^1.10.0", 23 "morgan": "^1.10.0",
24 "node-fetch": "^2.7.0",
24 "openai": "^3.2.0" 25 "openai": "^3.2.0"
25 } 26 }
26 } 27 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!