1d354b8b by Jonille Arreglo

update

1 parent 0c874f9b
...@@ -46,6 +46,7 @@ const tiktokenModels = [ ...@@ -46,6 +46,7 @@ const tiktokenModels = [
46 'gpt-3.5-turbo-0301' 46 'gpt-3.5-turbo-0301'
47 ]; 47 ];
48 const encoding_for_model = tiktoken.encoding_for_model; 48 const encoding_for_model = tiktoken.encoding_for_model;
49 const user_secret_id = process.env.USER_SECRET_ID ? process.env.USER_SECRET_ID : "aiwp_logged_in";
49 50
50 // Open AI Configuration 51 // Open AI Configuration
51 // console.log(process.env.OPENAI_API_ORG) 52 // console.log(process.env.OPENAI_API_ORG)
...@@ -126,15 +127,15 @@ app.post('/api', async (req, res) => { ...@@ -126,15 +127,15 @@ app.post('/api', async (req, res) => {
126 usage.prompt_tokens = (enc.encode(query_prompt)).length; 127 usage.prompt_tokens = (enc.encode(query_prompt)).length;
127 usage.completion_tokens = (enc.encode(input)).length; 128 usage.completion_tokens = (enc.encode(input)).length;
128 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens; 129 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
129 } catch (e) {
130 console.log('Error encoding prompt text', e);
131 }
132 130
133 // TOKEN USAGE 131 // TOKEN USAGE
134 axios.post(`${process.env.API_URL}e/set-chat-usage`, 132 axios.post(`${process.env.API_URL}e/set-chat-usage`,
135 { app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens }, 133 { aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
136 { headers: { 'content-type': 'application/x-www-form-urlencoded' } 134 { headers: { 'content-type': 'application/x-www-form-urlencoded' }
137 }); 135 });
136 } catch (e) {
137 console.log('Error encoding prompt text', e);
138 }
138 139
139 res.json({ 140 res.json({
140 message: anchorme({ 141 message: anchorme({
...@@ -205,7 +206,7 @@ async function runGPTTurbo(req, res) { ...@@ -205,7 +206,7 @@ async function runGPTTurbo(req, res) {
205 206
206 // TOKEN USAGE 207 // TOKEN USAGE
207 axios.post(`${process.env.API_URL}e/set-chat-usage`, 208 axios.post(`${process.env.API_URL}e/set-chat-usage`,
208 { app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens }, 209 { aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
209 { headers: { 'content-type': 'application/x-www-form-urlencoded' } 210 { headers: { 'content-type': 'application/x-www-form-urlencoded' }
210 }); 211 });
211 } catch (e) { 212 } catch (e) {
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
13 "anchorme": "^2.1.2", 13 "anchorme": "^2.1.2",
14 "axios": "^1.5.1", 14 "axios": "^1.5.1",
15 "body-parser": "^1.20.1", 15 "body-parser": "^1.20.1",
16 "cookie": "0.5.0",
17 "cookie-parser": "1.4.6",
16 "cors": "^2.8.5", 18 "cors": "^2.8.5",
17 "dotenv": "^16.0.3", 19 "dotenv": "^16.0.3",
18 "express": "^4.18.2", 20 "express": "^4.18.2",
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!