Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Troisi committed Dec 9, 2024
1 parent 3b05fa0 commit 6ba479e
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions routes/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,41 +298,20 @@ router.post('/qa', async (req, res) => {
winston.debug("qa resp: ", resp.data);
let answer = resp.data;

let id = answer.id;
let index = id.indexOf("#");
if (index != -1) {
id = id.substring(index + 1);
}

KB.findById(id, (err, resource) => {

if (publicKey === true) {
let multiplier = MODELS_MULTIPLIER[data.model];
if (!multiplier) {
multiplier = 1;
winston.info("No multiplier found for AI model")
}
obj.multiplier = multiplier;
obj.tokens = answer.prompt_token_size;

let incremented_key = quoteManager.incrementTokenCount(req.project, obj);
winston.verbose("incremented_key: ", incremented_key);
}

if (err) {
winston.error("Unable to find resource with id " + id + " in namespace " + answer.namespace + ". The standard answer is returned.")
return res.status(200).send(resp.data);
}

if (!resource) {
winston.error("Resource with id " + id + " not found in namespace " + answer.namespace + ". The standard answer is returned.")
return res.status(200).send(resp.data);
if (publicKey === true) {
let multiplier = MODELS_MULTIPLIER[data.model];
if (!multiplier) {
multiplier = 1;
winston.info("No multiplier found for AI model")
}
obj.multiplier = multiplier;
obj.tokens = answer.prompt_token_size;

answer.source = resource.name;
return res.status(200).send(answer);
})

let incremented_key = quoteManager.incrementTokenCount(req.project, obj);
winston.verbose("incremented_key: ", incremented_key);
}

return res.status(200).send(answer);

}).catch((err) => {
winston.error("qa err: ", err);
Expand Down

0 comments on commit 6ba479e

Please sign in to comment.