fix(core.gbapp): Start dialog done and log improvements.

This commit is contained in:
Rodrigo Rodriguez 2020-12-06 16:22:34 -03:00
parent d04a4804a8
commit 1ff24290f0
6 changed files with 94 additions and 24 deletions

View file

@ -481,7 +481,7 @@ export class GBConversationalService {
try { try {
const saved = step.context.activity.text; const saved = step.context.activity.text;
step.context.activity.text = text; step.context.activity.text = text;
nlp = await model.recognize(step.context); nlp = await model.recognize(step.context,{},{},{IncludeAllIntents:false, IncludeInstanceData: false, includeAPIResults: true});
step.context.activity.text = saved; step.context.activity.text = saved;
} catch (error) { } catch (error) {
// tslint:disable:no-unsafe-any // tslint:disable:no-unsafe-any
@ -498,12 +498,15 @@ export class GBConversationalService {
// tslint:enable:no-unsafe-any // tslint:enable:no-unsafe-any
} }
const minBoot = GBServer.globals.minBoot as any;
let nlpActive = false; let nlpActive = false;
let score = 0; let score = 0;
const instanceScore = min.core.getParam(min.instance, 'NLP Score',
min.instance.nlpScore ? min.instance.nlpScore : minBoot.instance.nlpScore);
Object.keys(nlp.intents).forEach(name => { Object.keys(nlp.intents).forEach(name => {
score = nlp.intents[name].score; score = nlp.intents[name].score;
if (score > min.instance.nlpScore) { if (score > instanceScore) {
nlpActive = true; nlpActive = true;
} }
}); });
@ -518,7 +521,7 @@ export class GBConversationalService {
} }
GBLog.info( GBLog.info(
`NLP called: ${intent}, entities: ${nlp.entities.length}, score: ${score} > required (nlpScore): ${min.instance.nlpScore}` `NLP called: ${intent}, entities: ${nlp.entities.length}, score: ${score} > required (nlpScore): ${instanceScore}`
); );
try { try {
@ -548,7 +551,7 @@ export class GBConversationalService {
} }
GBLog.info( GBLog.info(
`NLP NOT called: score: ${score} > required (nlpScore): ${min.instance.nlpScore}` `NLP NOT called: score: ${score} > required (nlpScore): ${instanceScore}`
); );
return false; return false;

View file

@ -587,7 +587,7 @@ STORAGE_SYNC=true
return value ? value : defaultValue; return value ? value : defaultValue;
} }
if (typeof defaultValue === 'number') { if (typeof defaultValue === 'number') {
return new Number(value ? defaultValue : defaultValue ? defaultValue : 0); return new Number(value ? value : defaultValue ? defaultValue : 0);
} }
if (instance['dataValues'] && !value) { if (instance['dataValues'] && !value) {

View file

@ -614,6 +614,7 @@ export class GBMinService {
// Get loaded user state // Get loaded user state
const step = await min.dialogs.createContext(context); const step = await min.dialogs.createContext(context);
step.context.activity.locale = 'pt-BR'; step.context.activity.locale = 'pt-BR';
let firstTime = false;
try { try {
const user = await min.userProfile.get(context, {}); const user = await min.userProfile.get(context, {});
@ -622,6 +623,7 @@ export class GBMinService {
const sec = new SecService(); const sec = new SecService();
if (!user.loaded) { if (!user.loaded) {
firstTime = true;
await min.conversationalService.sendEvent(min, step, 'loadInstance', { await min.conversationalService.sendEvent(min, step, 'loadInstance', {
instanceId: instance.instanceId, instanceId: instance.instanceId,
botId: instance.botId, botId: instance.botId,
@ -668,7 +670,19 @@ export class GBMinService {
await CollectionUtil.asyncForEach(appPackages, async e => { await CollectionUtil.asyncForEach(appPackages, async e => {
await e.onNewSession(min, step); await e.onNewSession(min, step);
}); });
const startDialog = min.core.getParam(min.instance, 'Start Dialog', null);
if (startDialog)
{
GBLog.info(`Auto start dialog is now being called: ${startDialog}...`);
await GBVMService.callVM(context.activity.text, min, step, this.deployer);
}
else
{
await step.beginDialog('/'); await step.beginDialog('/');
}
} else { } else {
GBLog.info(`Member added to conversation: ${member.name}`); GBLog.info(`Member added to conversation: ${member.name}`);
} }

View file

@ -487,6 +487,15 @@ export class GBVMService extends GBService {
const mainMethod = text.toLowerCase(); const mainMethod = text.toLowerCase();
sandbox[mainMethod].bind(sandbox); sandbox[mainMethod].bind(sandbox);
return await sandbox[mainMethod](step);
let ret = null;
try {
ret = await sandbox[mainMethod](step);
} catch (error) {
GBLog.error(`BASIC ERROR: ${error.message} ${error.stack}`);
}
return ret;
} }
} }

View file

@ -172,7 +172,9 @@ export class AskDialog extends IGBDialog {
// Searches KB for the first time. // Searches KB for the first time.
const searchScore = min.instance.searchScore ? min.instance.searchScore : minBoot.instance.searchScore; const searchScore = min.core.getParam(min.instance, 'Search Score',
min.instance.searchScore ? min.instance.searchScore : minBoot.instance.searchScore);
user.lastQuestion = text; user.lastQuestion = text;
await min.userProfile.set(step.context, user); await min.userProfile.set(step.context, user);
@ -192,15 +194,14 @@ export class AskDialog extends IGBDialog {
answer = resultsA.answer; answer = resultsA.answer;
// If this search was restricted to some subjects... // If this search was restricted to some subjects...
} else if (user.subjects) { } else if (user.subjects && user.subjects.length > 0) {
// ...second time running Search, now with no filter. // ...second time running Search, now with no filter.
const resultsB = await service.ask(min.instance, text, searchScore, undefined); const resultsB = await service.ask(min.instance, text, searchScore, undefined);
// If there is some result, answer immediately. // If there is some result, answer immediately.
if (resultsB !== undefined && resultsB.answer !== undefined) if (resultsB !== undefined && resultsB.answer !== undefined) {
{
// Saves some context info. // Saves some context info.
const user2 = await min.userProfile.get(step.context, {}); const user2 = await min.userProfile.get(step.context, {});

View file

@ -177,6 +177,8 @@ export class KBService implements IGBKBService {
): Promise<KBServiceSearchResults> { ): Promise<KBServiceSearchResults> {
// Builds search query. // Builds search query.
query = query.toLowerCase(); query = query.toLowerCase();
query = query.replace('?', ' '); query = query.replace('?', ' ');
query = query.replace('!', ' '); query = query.replace('!', ' ');
@ -192,6 +194,8 @@ export class KBService implements IGBKBService {
} }
} }
let notSearched = true;
// tslint:disable:no-unsafe-any // tslint:disable:no-unsafe-any
if (instance.searchKey !== null && GBConfigService.get('STORAGE_DIALECT') === 'mssql') { if (instance.searchKey !== null && GBConfigService.get('STORAGE_DIALECT') === 'mssql') {
const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey); const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey);
@ -205,22 +209,61 @@ export class KBService implements IGBKBService {
const values = results.result.value; const values = results.result.value;
if (values && values.length > 0 && values[0]['@search.score'] >= searchScore) { let returnedScore = 0;
// Searches via Search (Azure Search).
if (values && values.length > 0) {
returnedScore = values[0]['@search.score'];
if (returnedScore >= searchScore) {
const value = await this.getAnswerById(instance.instanceId, values[0].answerId); const value = await this.getAnswerById(instance.instanceId, values[0].answerId);
if (value !== null) { if (value !== null) {
GBLog.info(
`SEARCH WILL BE USED with score: ${returnedScore} > required (searchScore): ${searchScore}`
);
notSearched = false;
return { answer: value, questionId: values[0].questionId }; return { answer: value, questionId: values[0].questionId };
} else { } else {
GBLog.info(
`SEARCH WILL NOT be used as answerId ${values[0].answerId} was not found in database,
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
);
return { answer: undefined, questionId: 0 };
}
} else {
GBLog.info(
`SEARCH called but returned LOW level score,
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
);
return { answer: undefined, questionId: 0 };
}
} else {
GBLog.info(
`SEARCH called but NO answer could be found (zero results).`
);
return { answer: undefined, questionId: 0 }; return { answer: undefined, questionId: 0 };
} }
} }
} else {
const data = await this.getAnswerByText(instance.instanceId, query); // DISABLED: Searches via Database "WHERE" command.
if (data) {
return { answer: data.answer, questionId: data.question.questionId }; // if (notSearched) {
} else { // const data = await this.getAnswerByText(instance.instanceId, query);
return { answer: undefined, questionId: 0 }; // if (data) {
} // GBLog.info(
} // `SEARCH called.`
// );
// return { answer: data.answer, questionId: data.question.questionId };
// } else {
// GBLog.info(`SEARCH NOT called getAnswerByText not found answers in database.`);
// return { answer: undefined, questionId: 0 };
// }
// }
// TODO: Add more sources....
} }
public async getSubjectItems(instanceId: number, parentId: number): Promise<GuaribasSubject[]> { public async getSubjectItems(instanceId: number, parentId: number): Promise<GuaribasSubject[]> {