Skip to content

Commit

Permalink
fix(kb.gbapp): #276 use of NLP.js upgrade to v4.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Feb 27, 2023
1 parent 01cf280 commit 5c48d39
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@google-cloud/translate": "7.0.4",
"@hubspot/api-client": "7.1.2",
"@microsoft/microsoft-graph-client": "3.0.4",
"@nlpjs/basic": "4.26.1",
"@nosferatu500/textract": "3.1.2",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/exec": "5.0.0",
Expand All @@ -89,6 +90,7 @@
"botframework-connector": "4.18.0",
"botlib": "3.0.9",
"c3-chart-maker": "0.2.8",
"cd": "^0.3.3",
"chatgpt": "2.4.2",
"chrome-remote-interface": "0.31.3",
"cli-progress": "3.11.2",
Expand Down Expand Up @@ -120,7 +122,7 @@
"nexmo": "2.9.1",
"node-cron": "3.0.2",
"node-html-parser": "6.1.5",
"node-nlp": "4.24.0",
"node-nlp": "4.26.1",
"node-tesseract-ocr": "2.2.1",
"open": "8.4.0",
"open-docxtemplater-image-module": "1.0.3",
Expand Down
17 changes: 8 additions & 9 deletions packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,17 @@ export class GBVMService extends GBService {
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);

// TODO: https://github.com/GeneralBots/BotServer/issues/217
// Auto-NLP generates BASIC variables related to entities.

// if (step && step.context.activity['originalText'] && min['nerEngine']) {
// const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
if (text && min['nerEngine']) {
const result = await min['nerEngine'].process(text);

// for (let i = 0; i < entities.length; i++) {
// const v = entities[i];
// const variableName = `${v.entity}`;
// sandbox[variableName] = v.option;
// }
// }
for (let i = 0; i < result.entities.length; i++) {
const v = result.entities[i];
const variableName = `${v.entity}`;
sandbox[variableName] = v.option;
}
}

const botId = min.botId;
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ ENDPOINT_UPDATE=true

/**
* Get a dynamic param from instance. Dynamic params are defined in Config.xlsx
* and loaded into the work folder from /publish command.
* and loaded into the work folder from comida command.
*
* @param name Name of param to get from instance.
* @param defaultValue Value returned when no param is defined in Config.xlsx.
Expand Down
26 changes: 9 additions & 17 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import path from 'path';
import mkdirp from 'mkdirp';
import Fs from 'fs';
import arrayBufferToBuffer from 'arraybuffer-to-buffer';

import { NlpManager } from 'node-nlp';
import {
AutoSaveStateMiddleware,
BotFrameworkAdapter,
Expand Down Expand Up @@ -85,7 +85,6 @@ import { GBDeployer } from './GBDeployer.js';
import urlJoin from 'url-join';
import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine.js';
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
import * as nlp from 'node-nlp';
import Path from 'path';
import { GBSSR } from './GBSSR.js';

Expand Down Expand Up @@ -249,20 +248,13 @@ export class GBMinService {
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at custom domain: ${domain}.`);
}


GBServer.globals.httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options);
}

/**
* Unmounts the bot web site (default.gbui) secure domain, if any.
*/
public async unloadDomain(instance: IGBInstance) {





}
public async unloadDomain(instance: IGBInstance) {}

/**
* Mount the instance by creating an BOT Framework bot object,
Expand Down Expand Up @@ -325,8 +317,7 @@ export class GBMinService {

// Loads Named Entity data for this bot.

// https://github.com/GeneralBots/BotServer/issues/217
// await KBService.RefreshNER(min);
await KBService.RefreshNER(min);

// Calls the loadBot context.activity for all packages.

Expand Down Expand Up @@ -376,7 +367,6 @@ export class GBMinService {
};

await CollectionUtil.asyncForEach(steps, async step => {

client.apis.Conversations.Conversations_PostActivity({
conversationId: conversationId,
activity: {
Expand Down Expand Up @@ -619,7 +609,6 @@ export class GBMinService {
* Gets a Speech to Text / Text to Speech token from the provider.
*/
private async getSTSToken(instance: any) {

const options = {
method: 'POST',
headers: {
Expand All @@ -628,8 +617,7 @@ export class GBMinService {
};

try {

const res = await fetch(instance.speechEndpoint, options)
const res = await fetch(instance.speechEndpoint, options);
return res.text();
} catch (error) {
const msg = `Error calling Speech to Text client. Error is: ${error}.`;
Expand Down Expand Up @@ -674,10 +662,14 @@ export class GBMinService {
min.sandBoxMap = {};
min['scheduleMap'] = {};
min['conversationWelcomed'] = {};
min['nerEngine'] = new nlp.NlpManager(); // https://github.com/GeneralBots/BotServer/issues/217
min.packages = sysPackages;
min.appPackages = appPackages;

// NLP Manager.

const manager = new NlpManager({ languages: ['en'], forceNER: true });
min['nerEngine'] = manager;

if (GBServer.globals.minBoot === undefined) {
GBServer.globals.minBoot = min;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core.gbapp/services/GBSSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ export class GBSSR {
});
};

await sleep(15000);
await sleep(6000);

// Inject <base> on page to relative resources load properly.

await page.evaluate(url => {
const base = document.createElement('base');
base.href = url;
// Add to top of head, beeeEEEfore all other resources.
// Add to top of head, before all other resources.
document.head.prepend(base);
}, url);

Expand Down
4 changes: 2 additions & 2 deletions packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class KBService implements IGBKBService {
}

public async getAnswerById(instanceId: number, answerId: number): Promise<GuaribasAnswer> {
return GuaribasAnswer.findOne({
return await GuaribasAnswer.findOne({
where: {
instanceId: instanceId,
answerId: answerId
Expand Down Expand Up @@ -332,7 +332,7 @@ export class KBService implements IGBKBService {
return { answer: value, questionId: result.document.questionId };
} else {
GBLog.info(
`SEARCH WILL NOT be used as answerId ${result.document.answerId} was not found in database,
`Index problem. SEARCH WILL NOT be used as answerId ${result.document.answerId} was not found in database,
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
);

Expand Down

0 comments on commit 5c48d39

Please sign in to comment.