Skip to content

Commit

Permalink
Code clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Troisi committed Feb 9, 2024
1 parent 79c9c7f commit 3457abe
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 127 deletions.
1 change: 0 additions & 1 deletion routes/faq.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ router.put('/:faqid', function (req, res) {
// DELETE REMOTE AND LOCAL FAQ
router.delete('/:faqid', function (req, res) {

console.log("delete called")
winston.debug('DELETE FAQ - FAQ ID ', req.params.faqid);

let faqid = req.params.faqid;
Expand Down
11 changes: 3 additions & 8 deletions routes/faq_kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,15 @@ router.post('/fork/:id_faq_kb', async (req, res) => {

let globals = req.query.globals;
winston.debug("export globals " + globals);
console.log("export globals? --> globals ", globals);


let token = req.headers.authorization;

let cs = req.app.get('chatbot_service')

let chatbot = await cs.getBotById(id_faq_kb, public, api_url, chatbot_templates_api_url, token, current_project_id, globals);
winston.debug("chatbot: ", chatbot)
console.log("/fork chatbot after getBotById: ", chatbot);

if (!chatbot) {
return res.status(500).send({ success: false, message: "Unable to get chatbot" });
}
Expand Down Expand Up @@ -982,8 +982,6 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
router.get('/exportjson/:id_faq_kb', (req, res) => {

winston.debug("exporting bot...")
console.log("exportjson req.query.globals: ", req.query.globals);


let id_faq_kb = req.params.id_faq_kb;

Expand All @@ -1000,12 +998,10 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
const intents = faqs.map(({ _id, id_project, topic, status, id_faq_kb, createdBy, createdAt, updatedAt, __v, ...keepAttrs }) => keepAttrs)

if (!req.query.globals) {
console.log("Delete globals from attributes!")
winston.verbose("Delete globals from attributes!")
if (faq_kb.attributes) {
delete faq_kb.attributes.globals;
}
} else {
console.log("Keep globals")
}

let json = {
Expand Down Expand Up @@ -1033,7 +1029,6 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
// return res.status(200).send(json);
// }
let json_string = JSON.stringify(json);
console.log("json_string: ", json_string)
res.set({ "Content-Disposition": "attachment; filename=\"bot.json\"" });
return res.send(json_string);
}
Expand Down
2 changes: 0 additions & 2 deletions routes/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ router.post('/', async (req, res) => {

let project_id = req.projectid;
let body = req.body;
console.log("create new kb project_id " + project_id);
console.log("create new kb body ", body);

let new_kb = {
id_project: project_id,
Expand Down
30 changes: 5 additions & 25 deletions services/QuoteManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ const requestEvent = require('../event/requestEvent');
const messageEvent = require('../event/messageEvent');
const emailEvent = require('../event/emailEvent');

// const PLANS_LIST = {
// FREE_TRIAL: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 }, // same as PREMIUM
// SANDBOX: { users: 1, requests: 200, chatbots: 2, kbs: 1, kb_pages: 50, tokens: 10000 },
// BASIC: { users: 1, requests: 810, chatbots: 5, kbs: 2, kb_pages: 250, tokens: 50000 },
// PREMIUM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 },
// CUSTOM: { users: 100, conversations: 10000, chatbots: 100, kbs: 100, kb_pages: 1000, tokens: 100000 } // manage it --> get limit directly from project info
// }

// const PLANS_LIST = {
// FREE_TRIAL: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 }, // same as PREMIUM
// SANDBOX: { users: 1, requests: 200, chatbots: 2, kbs: 1, kb_pages: 50, tokens: 10000 },
// BASIC: { users: 1, requests: 800, chatbots: 5, kbs: 2, kb_pages: 250, tokens: 50000 },
// PREMIUM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 },
// CUSTOM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 5000, tokens: 1000000 }
// }

const PLANS_LIST = {
FREE_TRIAL: { requests: 3000, messages: 0, tokens: 250000, email: 200 }, // same as PREMIUM
SANDBOX: { requests: 200, messages: 0, tokens: 10000, email: 200 },
Expand Down Expand Up @@ -142,18 +126,15 @@ class QuoteManager {

let quotes = {}
for (let type of typesList) {
console.log("*** get all quotes --> search for type: ", type);

let key = await this.generateKey(obj, type);
console.log("*** get all quotes --> key generated: ", key);
let quote = await this.tdCache.get(key);
console.log("*** get all quotes --> quote retrieved: ", quote);

quotes[type] = {
quote: Number(quote)
};
}
return quotes;

}

/**
Expand All @@ -170,7 +151,7 @@ class QuoteManager {

this.project = project;
let limits = await this.getPlanLimits();
console.log("limits for current plan: ", limits)
winston.verbose("limits for current plan: ", limits)
let quote = await this.getCurrentQuote(project, object, type);

if (quote == null) {
Expand Down Expand Up @@ -258,8 +239,7 @@ class QuoteManager {
let result = await this.incrementRequestsCount(payload.project, payload.request);
return result;
} else {
console.log("QUOTES DISABLED - request.create.quote event")
winston.debug("QUOTES DISABLED - request.create.quote event")
winston.info("QUOTES DISABLED - request.create.quote event")
}
})
// REQUESTS EVENTS - END
Expand All @@ -282,7 +262,7 @@ class QuoteManager {
let result = await this.incrementMessagesCount(payload.project, payload.message);
return result;
} else {
winston.debug("QUOTES DISABLED - message.create.quote event")
winston.info("QUOTES DISABLED - message.create.quote event")
}
})
// MESSAGES EVENTS - END
Expand All @@ -305,7 +285,7 @@ class QuoteManager {
let result = await this.incrementEmailCount(payload.project, payload.email);
return result;
} else {
winston.debug("QUOTES DISABLED - email.send event")
winston.info("QUOTES DISABLED - email.send event")
}
})
// EMAIL EVENTS - END
Expand Down
1 change: 0 additions & 1 deletion services/chatbotService.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ChatbotService {
async getBotById(id_faq_kb, published, api_url, chatbot_templates_api_url, token, project_id, globals) {

winston.debug("[CHATBOT SERVICE] getBotById");
console.log("getBotById globals: ", globals);

// private bot
if (published == "false") {
Expand Down
59 changes: 4 additions & 55 deletions services/messageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,9 @@ class MessageService {

save(message) {

let total_1;
let total_e;
let total_1_end_e;
let total_2;

var that = this;
winston.debug('message.save called');

message.createdAt = new Date();

// let start1 = Date.now();
// let project;
// let payload;
// let q = Project.findOne({ _id: message.id_project, status: 100 });
// if (cacheEnabler.project) {
// q.cache(cacheUtil.longTTL, "projects:id:" + message.id_project) //project_cache
// winston.debug('project cache enabled for /project detail');
// }
// q.exec(async function (err, p) {
// if (err) {
// winston.error('Error getting project ', err);
// }
// if (!p) {
// winston.warn('Project not found ');
// }
// //TODO REMOVE settings from project
// project = p;
// payload = {
// project: project,
// message: message
// }

// let end1 = Date.now();
// total_1 = end1 - start1;

// let start_e = Date.now();
// let result = await messageEvent.emit('message.create.quote.before', payload);
// let end_e = Date.now();
// total_e = end_e - start_e;
// if (result === false) {
// winston.info("Messages limits reached for project " + project._id)
// // return false in the second phase
// }
// });

// let start2 = Date.now();
let sender = message.sender;
let senderFullname = message.senderFullname;
let recipient = message.recipient;
Expand All @@ -111,6 +68,9 @@ class MessageService {

return new Promise(function (resolve, reject) {

//let q = Project.findOne({ _id: request.id_project, status: 100 });
// Continue quotes code here (see at requestService)

if (!createdBy) {
createdBy = sender;
}
Expand Down Expand Up @@ -196,11 +156,7 @@ class MessageService {
message: message
}

let result = await messageEvent.emit('message.create.quote', payload);
if (result === false) {
winston.info("Messages limits reached for project " + p._id)
// return false in the second phase
}
messageEvent.emit('message.create.quote', payload);
});


Expand All @@ -212,13 +168,6 @@ class MessageService {
// messageEvent.emit('message.sending.simple', savedMessage);
// }

// console.log("total 1: ", total_1);
// console.log("total e: ", total_e);
// total_1_end_e = total_1 + total_e;
// console.log("total 1 + e: ", total_1_end_e);
// console.log("total 2: ", total_2);


return resolve(savedMessage);
});

Expand Down
20 changes: 9 additions & 11 deletions services/openaiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OpenaiService {
// OPEN AI
completions(data, gptkey) {

winston.debug("[OPENAI SERVICE] openai endpoint: ", openai_endpoint);
winston.debug("[OPENAI SERVICE] openai endpoint: " + openai_endpoint);

return new Promise((resolve, reject) => {

Expand All @@ -36,7 +36,7 @@ class OpenaiService {

// PUGLIA AI
checkStatus(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);

return new Promise((resolve, reject) => {

Expand All @@ -50,15 +50,14 @@ class OpenaiService {
}).then((resbody) => {
resolve(resbody);
}).catch((err) => {
console.log("checkStatus err: ", err)
reject(err);
})

})
}

startScrape(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);

return new Promise((resolve, reject) => {

Expand All @@ -79,7 +78,7 @@ class OpenaiService {
}

ask(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);

return new Promise((resolve, reject) => {

Expand All @@ -93,7 +92,6 @@ class OpenaiService {
}).then((resbody) => {
resolve(resbody);
}).catch((err) => {
console.log("err: ", err);
reject(err);
})

Expand All @@ -102,7 +100,7 @@ class OpenaiService {

// PUGLIA AI V2
singleScrape(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);

return new Promise((resolve, reject) => {

Expand All @@ -123,7 +121,7 @@ class OpenaiService {
}

scrapeStatus(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);

return new Promise((resolve, reject) => {

Expand All @@ -143,7 +141,7 @@ class OpenaiService {
}

askNamespace(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);

return new Promise((resolve, reject) => {

Expand All @@ -164,7 +162,7 @@ class OpenaiService {
}

deleteIndex(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);

return new Promise((resolve, reject) => {

Expand All @@ -184,7 +182,7 @@ class OpenaiService {
}

deleteNamespace(data) {
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);

return new Promise((resolve, reject) => {

Expand Down
24 changes: 0 additions & 24 deletions services/requestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,31 +709,7 @@ class RequestService {
winston.verbose("Performance Request created in millis: " + endDate - startDate);

requestEvent.emit('request.create.simple', savedRequest);

// let q = Project.findOne({ _id: request.id_project, status: 100 });
// if (cacheEnabler.project) {
// q.cache(cacheUtil.longTTL, "projects:id:" + request.id_project) //project_cache
// winston.debug('project cache enabled for /project detail');
// }
// q.exec(async function (err, p) {
// if (err) {
// winston.error('Error getting project ', err);
// }
// if (!p) {
// winston.warn('Project not found ');
// }
// //TODO REMOVE settings from project
// let payload = {
// project: p,
// request: request
// }

// });
requestEvent.emit('request.create.quote', payload);;
// if (result === false) {
// winston.info("Requests limits reached for project " + p._id)
// // return false in the second phase
// }

return resolve(savedRequest);

Expand Down

0 comments on commit 3457abe

Please sign in to comment.