216d3b57 by Jonille Arreglo

Merge branch '28594_usage_tracking' into 'master'

28594_usage_tracking

See merge request !78
2 parents 006c6848 c1504d56
...@@ -6,7 +6,7 @@ require('dotenv').config() ...@@ -6,7 +6,7 @@ require('dotenv').config()
6 const rateLimit = require('express-rate-limit') 6 const rateLimit = require('express-rate-limit')
7 const anchorme = require("anchorme").default; 7 const anchorme = require("anchorme").default;
8 const axios = require('axios'); 8 const axios = require('axios');
9 const tiktoken = require('@dqbd/tiktoken'); 9 const { encodingForModel } = require('js-tiktoken');
10 const tiktokenModels = [ 10 const tiktokenModels = [
11 'text-davinci-003', 11 'text-davinci-003',
12 'text-davinci-002', 12 'text-davinci-002',
...@@ -45,8 +45,6 @@ const tiktokenModels = [ ...@@ -45,8 +45,6 @@ const tiktokenModels = [
45 'gpt-3.5-turbo', 45 'gpt-3.5-turbo',
46 'gpt-3.5-turbo-0301' 46 'gpt-3.5-turbo-0301'
47 ]; 47 ];
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";
50 48
51 // Open AI Configuration 49 // Open AI Configuration
52 // console.log(process.env.OPENAI_API_ORG) 50 // console.log(process.env.OPENAI_API_ORG)
...@@ -123,7 +121,7 @@ app.post('/api', async (req, res) => { ...@@ -123,7 +121,7 @@ app.post('/api', async (req, res) => {
123 let usage = {}; 121 let usage = {};
124 let enc = null; 122 let enc = null;
125 try { 123 try {
126 enc = encoding_for_model(tiktokenModels.includes(currentModel) ? currentModel : 'gpt-3.5-turbo'); 124 enc = encodingForModel(tiktokenModels.includes(currentModel) ? currentModel : 'gpt-3.5-turbo');
127 usage.prompt_tokens = (enc.encode(query_prompt)).length; 125 usage.prompt_tokens = (enc.encode(query_prompt)).length;
128 usage.completion_tokens = (enc.encode(input)).length; 126 usage.completion_tokens = (enc.encode(input)).length;
129 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens; 127 usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
9 "author": "", 9 "author": "",
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 "@dqbd/tiktoken": "^1.0.7", 12 "js-tiktoken": "1.0.7",
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",
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!