Skip to content

Commit

Permalink
fix(basic.gblib): Fixes /answer bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Aug 31, 2021
1 parent 943546a commit 339e850
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
8 changes: 5 additions & 3 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ export class GBMinService {
if (!min["conversationWelcomed"][step.context.activity.conversation.id]) {

min["conversationWelcomed"][step.context.activity.conversation.id] = true;

GBLog.info(`Auto start (web) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...`);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
}
Expand Down Expand Up @@ -1255,10 +1255,12 @@ export class GBMinService {
user: user ? user.dataValues : null
};
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
nextDialog = await e.onExchangeData(min, 'handleAnswer', data);
if (!nextDialog) {
nextDialog = await e.onExchangeData(min, 'handleAnswer', data);
}
});
data.step = null;
GBLog.info(`/answer being called from processMessageActivity.`);
GBLog.info(`/answer being called from processMessageActivity (nextDialog=${nextDialog}).`);
await step.beginDialog(nextDialog ? nextDialog : '/answer', {
data: data,
query: text,
Expand Down
54 changes: 31 additions & 23 deletions packages/kb.gbapp/dialogs/AskDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,43 +248,51 @@ export class AskDialog extends IGBDialog {
}
}

// Answers using Search or NLP responses.
// Try to answer by search.

if (answer) {
return await AskDialog.handleAnswer(service, min, step, answer);
} else if (!(await min.conversationalService.routeNLP(step, min, text))) {
}

if (process.env.GBMODELS_SERVER) {
text = await min.conversationalService.translate(min, text, 'en');
let answered = false;
// Tries to answer by NLP.

const docs = await min.kbService['getDocs'](min.instance.instanceId);
if (await min.conversationalService.routeNLP(step, min, text)) {
return await step.replaceDialog('/ask', { isReturning: true });
}

await CollectionUtil.asyncForEach(docs, async (doc: GuaribasAnswer) => {
// Tries to answer by Reading Comprehension.

if (!answered) {
if (process.env.GBMODELS_SERVER) {
text = await min.conversationalService.translate(min, text, 'en');
let answered = false;

const answerText = await min.kbService['readComprehension'](min.instance.instanceId, doc.content, text);
answered = true;
text = await min.conversationalService.translate(min, text, user.systemUser.locale
? user.systemUser.locale
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE')));
await min.conversationalService.sendText(min, step, answerText);
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
}
const docs = await min.kbService['getDocs'](min.instance.instanceId);

});
return await step.replaceDialog('/ask', { isReturning: true });
}
await CollectionUtil.asyncForEach(docs, async (doc: GuaribasAnswer) => {

if (!answered) {

} else {
const message = min.core.getParam<string>(min.instance, 'Not Found Message',
Messages[locale].did_not_find);
const answerText = await min.kbService['readComprehension'](min.instance.instanceId, doc.content, text);
answered = true;
text = await min.conversationalService.translate(min, text, user.systemUser.locale
? user.systemUser.locale
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE')));
await min.conversationalService.sendText(min, step, answerText);
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
}

await min.conversationalService.sendText(min, step, message);
});
return await step.replaceDialog('/ask', { isReturning: true });
}

// Not found.

const message = min.core.getParam<string>(min.instance, 'Not Found Message',
Messages[locale].did_not_find);

await min.conversationalService.sendText(min, step, message);
return await step.replaceDialog('/ask', { isReturning: true });

}
];
}
Expand Down

0 comments on commit 339e850

Please sign in to comment.