1d354b8b by Jonille Arreglo

update

1 parent 0c874f9b
......@@ -46,6 +46,7 @@ const tiktokenModels = [
'gpt-3.5-turbo-0301'
];
const encoding_for_model = tiktoken.encoding_for_model;
const user_secret_id = process.env.USER_SECRET_ID ? process.env.USER_SECRET_ID : "aiwp_logged_in";
// Open AI Configuration
// console.log(process.env.OPENAI_API_ORG)
......@@ -126,16 +127,16 @@ app.post('/api', async (req, res) => {
usage.prompt_tokens = (enc.encode(query_prompt)).length;
usage.completion_tokens = (enc.encode(input)).length;
usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
// TOKEN USAGE
axios.post(`${process.env.API_URL}e/set-chat-usage`,
{ aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
{ headers: { 'content-type': 'application/x-www-form-urlencoded' }
});
} catch (e) {
console.log('Error encoding prompt text', e);
}
// TOKEN USAGE
axios.post(`${process.env.API_URL}e/set-chat-usage`,
{ app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
{ headers: { 'content-type': 'application/x-www-form-urlencoded' }
});
res.json({
message: anchorme({
input,
......@@ -205,7 +206,7 @@ async function runGPTTurbo(req, res) {
// TOKEN USAGE
axios.post(`${process.env.API_URL}e/set-chat-usage`,
{ app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
{ aiwp_logged_in: req.cookies[user_secret_id], app: 'chatbot', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens },
{ headers: { 'content-type': 'application/x-www-form-urlencoded' }
});
} catch (e) {
......
......@@ -13,6 +13,8 @@
"anchorme": "^2.1.2",
"axios": "^1.5.1",
"body-parser": "^1.20.1",
"cookie": "0.5.0",
"cookie-parser": "1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"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!