9751bbbd by Jonille Arreglo

28594_usage_tracking

1 parent 3fc61a14
...@@ -124,6 +124,9 @@ function App() { ...@@ -124,6 +124,9 @@ function App() {
124 }); 124 });
125 userModifiedInput = ""; 125 userModifiedInput = "";
126 } 126 }
127 if(data.usage) {
128 btutil_setChatUsage('chatbot+', data.usage.prompt_tokens, data.usage.total_tokens);
129 }
127 chatLogTurboNew.push({ role: "user", content: userModifiedInput }); 130 chatLogTurboNew.push({ role: "user", content: userModifiedInput });
128 chatLogTurboNew.push({ role: "assistant", content: parsedData }); 131 chatLogTurboNew.push({ role: "assistant", content: parsedData });
129 setChatLogTurbo(chatLogTurboNew); 132 setChatLogTurbo(chatLogTurboNew);
......
...@@ -127,17 +127,12 @@ app.post('/api', async (req, res) => { ...@@ -127,17 +127,12 @@ app.post('/api', async (req, res) => {
127 usage.prompt_tokens = (enc.encode(query_prompt)).length; 127 usage.prompt_tokens = (enc.encode(query_prompt)).length;
128 usage.completion_tokens = (enc.encode(input)).length; 128 usage.completion_tokens = (enc.encode(input)).length;
129 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens; 129 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
130
131 // TOKEN USAGE
132 axios.post(`${process.env.API_URL}/e/set-chat-usage`,
133 { aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
134 { headers: { 'content-type': 'application/x-www-form-urlencoded' }
135 });
136 } catch (e) { 130 } catch (e) {
137 console.log('Error encoding prompt text', e); 131 console.log('Error encoding prompt text', e);
138 } 132 }
139 133
140 res.json({ 134 res.json({
135 usage: usage,
141 message: anchorme({ 136 message: anchorme({
142 input, 137 input,
143 options: { 138 options: {
...@@ -203,18 +198,13 @@ async function runGPTTurbo(req, res) { ...@@ -203,18 +198,13 @@ async function runGPTTurbo(req, res) {
203 usage.prompt_tokens = (enc.encode(query_prompt)).length; 198 usage.prompt_tokens = (enc.encode(query_prompt)).length;
204 usage.completion_tokens = (enc.encode(input)).length; 199 usage.completion_tokens = (enc.encode(input)).length;
205 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens; 200 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
206
207 // TOKEN USAGE
208 axios.post(`${process.env.API_URL}/e/set-chat-usage`,
209 { aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
210 { headers: { 'content-type': 'application/x-www-form-urlencoded' }
211 });
212 } catch (e) { 201 } catch (e) {
213 console.log('Error encoding prompt text', e); 202 console.log('Error encoding prompt text', e);
214 } 203 }
215 204
216 res.json({ 205 res.json({
217 prompt: JSON.parse(message), 206 prompt: JSON.parse(message),
207 usage: usage,
218 message: anchorme({ 208 message: anchorme({
219 input, 209 input,
220 options: { 210 options: {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!