fix(basic.gblib): Fixes /answer bug.
This commit is contained in:
parent
943546a8a0
commit
339e8501a9
2 changed files with 43 additions and 33 deletions
|
@ -921,7 +921,7 @@ export class GBMinService {
|
||||||
if (!min["conversationWelcomed"][step.context.activity.conversation.id]) {
|
if (!min["conversationWelcomed"][step.context.activity.conversation.id]) {
|
||||||
|
|
||||||
min["conversationWelcomed"][step.context.activity.conversation.id] = true;
|
min["conversationWelcomed"][step.context.activity.conversation.id] = true;
|
||||||
|
|
||||||
GBLog.info(`Auto start (web) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...`);
|
GBLog.info(`Auto start (web) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...`);
|
||||||
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
|
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
|
||||||
}
|
}
|
||||||
|
@ -1255,10 +1255,12 @@ export class GBMinService {
|
||||||
user: user ? user.dataValues : null
|
user: user ? user.dataValues : null
|
||||||
};
|
};
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
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;
|
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', {
|
await step.beginDialog(nextDialog ? nextDialog : '/answer', {
|
||||||
data: data,
|
data: data,
|
||||||
query: text,
|
query: text,
|
||||||
|
|
|
@ -248,43 +248,51 @@ export class AskDialog extends IGBDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Answers using Search or NLP responses.
|
// Try to answer by search.
|
||||||
|
|
||||||
if (answer) {
|
if (answer) {
|
||||||
return await AskDialog.handleAnswer(service, min, step, answer);
|
return await AskDialog.handleAnswer(service, min, step, answer);
|
||||||
} else if (!(await min.conversationalService.routeNLP(step, min, text))) {
|
}
|
||||||
|
|
||||||
if (process.env.GBMODELS_SERVER) {
|
// Tries to answer by NLP.
|
||||||
text = await min.conversationalService.translate(min, text, 'en');
|
|
||||||
let answered = false;
|
|
||||||
|
|
||||||
const docs = await min.kbService['getDocs'](min.instance.instanceId);
|
if (await min.conversationalService.routeNLP(step, min, text)) {
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(docs, async (doc: GuaribasAnswer) => {
|
|
||||||
|
|
||||||
if (!answered) {
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
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 });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tries to answer by Reading Comprehension.
|
||||||
|
|
||||||
|
if (process.env.GBMODELS_SERVER) {
|
||||||
|
text = await min.conversationalService.translate(min, text, 'en');
|
||||||
|
let answered = false;
|
||||||
|
|
||||||
|
const docs = await min.kbService['getDocs'](min.instance.instanceId);
|
||||||
|
|
||||||
|
await CollectionUtil.asyncForEach(docs, async (doc: GuaribasAnswer) => {
|
||||||
|
|
||||||
|
if (!answered) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
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 });
|
||||||
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue