fix(kb.gbapp): #276 use of NLP.js upgrade to v4.
This commit is contained in:
parent
01cf2803a0
commit
5c48d39620
6 changed files with 25 additions and 32 deletions
|
@ -65,6 +65,7 @@
|
||||||
"@google-cloud/translate": "7.0.4",
|
"@google-cloud/translate": "7.0.4",
|
||||||
"@hubspot/api-client": "7.1.2",
|
"@hubspot/api-client": "7.1.2",
|
||||||
"@microsoft/microsoft-graph-client": "3.0.4",
|
"@microsoft/microsoft-graph-client": "3.0.4",
|
||||||
|
"@nlpjs/basic": "4.26.1",
|
||||||
"@nosferatu500/textract": "3.1.2",
|
"@nosferatu500/textract": "3.1.2",
|
||||||
"@semantic-release/changelog": "5.0.1",
|
"@semantic-release/changelog": "5.0.1",
|
||||||
"@semantic-release/exec": "5.0.0",
|
"@semantic-release/exec": "5.0.0",
|
||||||
|
@ -89,6 +90,7 @@
|
||||||
"botframework-connector": "4.18.0",
|
"botframework-connector": "4.18.0",
|
||||||
"botlib": "3.0.9",
|
"botlib": "3.0.9",
|
||||||
"c3-chart-maker": "0.2.8",
|
"c3-chart-maker": "0.2.8",
|
||||||
|
"cd": "^0.3.3",
|
||||||
"chatgpt": "2.4.2",
|
"chatgpt": "2.4.2",
|
||||||
"chrome-remote-interface": "0.31.3",
|
"chrome-remote-interface": "0.31.3",
|
||||||
"cli-progress": "3.11.2",
|
"cli-progress": "3.11.2",
|
||||||
|
@ -120,7 +122,7 @@
|
||||||
"nexmo": "2.9.1",
|
"nexmo": "2.9.1",
|
||||||
"node-cron": "3.0.2",
|
"node-cron": "3.0.2",
|
||||||
"node-html-parser": "6.1.5",
|
"node-html-parser": "6.1.5",
|
||||||
"node-nlp": "4.24.0",
|
"node-nlp": "4.26.1",
|
||||||
"node-tesseract-ocr": "2.2.1",
|
"node-tesseract-ocr": "2.2.1",
|
||||||
"open": "8.4.0",
|
"open": "8.4.0",
|
||||||
"open-docxtemplater-image-module": "1.0.3",
|
"open-docxtemplater-image-module": "1.0.3",
|
||||||
|
|
|
@ -343,18 +343,17 @@ export class GBVMService extends GBService {
|
||||||
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: https://github.com/GeneralBots/BotServer/issues/217
|
|
||||||
// Auto-NLP generates BASIC variables related to entities.
|
// Auto-NLP generates BASIC variables related to entities.
|
||||||
|
|
||||||
// if (step && step.context.activity['originalText'] && min['nerEngine']) {
|
if (text && min['nerEngine']) {
|
||||||
// const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
|
const result = await min['nerEngine'].process(text);
|
||||||
|
|
||||||
// for (let i = 0; i < entities.length; i++) {
|
for (let i = 0; i < result.entities.length; i++) {
|
||||||
// const v = entities[i];
|
const v = result.entities[i];
|
||||||
// const variableName = `${v.entity}`;
|
const variableName = `${v.entity}`;
|
||||||
// sandbox[variableName] = v.option;
|
sandbox[variableName] = v.option;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
const botId = min.botId;
|
const botId = min.botId;
|
||||||
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
|
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
|
||||||
|
|
|
@ -633,7 +633,7 @@ ENDPOINT_UPDATE=true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a dynamic param from instance. Dynamic params are defined in Config.xlsx
|
* 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 name Name of param to get from instance.
|
||||||
* @param defaultValue Value returned when no param is defined in Config.xlsx.
|
* @param defaultValue Value returned when no param is defined in Config.xlsx.
|
||||||
|
|
|
@ -47,7 +47,7 @@ import path from 'path';
|
||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import arrayBufferToBuffer from 'arraybuffer-to-buffer';
|
import arrayBufferToBuffer from 'arraybuffer-to-buffer';
|
||||||
|
import { NlpManager } from 'node-nlp';
|
||||||
import {
|
import {
|
||||||
AutoSaveStateMiddleware,
|
AutoSaveStateMiddleware,
|
||||||
BotFrameworkAdapter,
|
BotFrameworkAdapter,
|
||||||
|
@ -85,7 +85,6 @@ import { GBDeployer } from './GBDeployer.js';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine.js';
|
import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleChatDirectLine.js';
|
||||||
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
|
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
|
||||||
import * as nlp from 'node-nlp';
|
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
import { GBSSR } from './GBSSR.js';
|
import { GBSSR } from './GBSSR.js';
|
||||||
|
|
||||||
|
@ -249,20 +248,13 @@ export class GBMinService {
|
||||||
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at custom domain: ${domain}.`);
|
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at custom domain: ${domain}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GBServer.globals.httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options);
|
GBServer.globals.httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmounts the bot web site (default.gbui) secure domain, if any.
|
* 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,
|
* Mount the instance by creating an BOT Framework bot object,
|
||||||
|
@ -325,8 +317,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Loads Named Entity data for this bot.
|
// 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.
|
// Calls the loadBot context.activity for all packages.
|
||||||
|
|
||||||
|
@ -376,7 +367,6 @@ export class GBMinService {
|
||||||
};
|
};
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(steps, async step => {
|
await CollectionUtil.asyncForEach(steps, async step => {
|
||||||
|
|
||||||
client.apis.Conversations.Conversations_PostActivity({
|
client.apis.Conversations.Conversations_PostActivity({
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
activity: {
|
activity: {
|
||||||
|
@ -619,7 +609,6 @@ export class GBMinService {
|
||||||
* Gets a Speech to Text / Text to Speech token from the provider.
|
* Gets a Speech to Text / Text to Speech token from the provider.
|
||||||
*/
|
*/
|
||||||
private async getSTSToken(instance: any) {
|
private async getSTSToken(instance: any) {
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -628,8 +617,7 @@ export class GBMinService {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const res = await fetch(instance.speechEndpoint, options);
|
||||||
const res = await fetch(instance.speechEndpoint, options)
|
|
||||||
return res.text();
|
return res.text();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const msg = `Error calling Speech to Text client. Error is: ${error}.`;
|
const msg = `Error calling Speech to Text client. Error is: ${error}.`;
|
||||||
|
@ -674,10 +662,14 @@ export class GBMinService {
|
||||||
min.sandBoxMap = {};
|
min.sandBoxMap = {};
|
||||||
min['scheduleMap'] = {};
|
min['scheduleMap'] = {};
|
||||||
min['conversationWelcomed'] = {};
|
min['conversationWelcomed'] = {};
|
||||||
min['nerEngine'] = new nlp.NlpManager(); // https://github.com/GeneralBots/BotServer/issues/217
|
|
||||||
min.packages = sysPackages;
|
min.packages = sysPackages;
|
||||||
min.appPackages = appPackages;
|
min.appPackages = appPackages;
|
||||||
|
|
||||||
|
// NLP Manager.
|
||||||
|
|
||||||
|
const manager = new NlpManager({ languages: ['en'], forceNER: true });
|
||||||
|
min['nerEngine'] = manager;
|
||||||
|
|
||||||
if (GBServer.globals.minBoot === undefined) {
|
if (GBServer.globals.minBoot === undefined) {
|
||||||
GBServer.globals.minBoot = min;
|
GBServer.globals.minBoot = min;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,14 +175,14 @@ export class GBSSR {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
await sleep(15000);
|
await sleep(6000);
|
||||||
|
|
||||||
// Inject <base> on page to relative resources load properly.
|
// Inject <base> on page to relative resources load properly.
|
||||||
|
|
||||||
await page.evaluate(url => {
|
await page.evaluate(url => {
|
||||||
const base = document.createElement('base');
|
const base = document.createElement('base');
|
||||||
base.href = url;
|
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);
|
document.head.prepend(base);
|
||||||
}, url);
|
}, url);
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ export class KBService implements IGBKBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAnswerById(instanceId: number, answerId: number): Promise<GuaribasAnswer> {
|
public async getAnswerById(instanceId: number, answerId: number): Promise<GuaribasAnswer> {
|
||||||
return GuaribasAnswer.findOne({
|
return await GuaribasAnswer.findOne({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instanceId,
|
instanceId: instanceId,
|
||||||
answerId: answerId
|
answerId: answerId
|
||||||
|
@ -332,7 +332,7 @@ export class KBService implements IGBKBService {
|
||||||
return { answer: value, questionId: result.document.questionId };
|
return { answer: value, questionId: result.document.questionId };
|
||||||
} else {
|
} else {
|
||||||
GBLog.info(
|
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}`
|
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue