fix(kb.gbapp): Adjustments in .gbkb engine.
This commit is contained in:
parent
36202ae010
commit
4927959a5c
4 changed files with 54 additions and 25 deletions
|
@ -596,8 +596,9 @@ export class GBConversationalService {
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
user.locale ? user.locale : 'pt'
|
user.locale ? user.locale : 'en'
|
||||||
);
|
);
|
||||||
|
GBLog.info(`Translated text(4): ${text}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await step.prompt('textPrompt', text ? text : {});
|
return await step.prompt('textPrompt', text ? text : {});
|
||||||
|
@ -615,8 +616,10 @@ export class GBConversationalService {
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
user.locale ? user.locale : 'pt'
|
user.locale ? user.locale : 'en'
|
||||||
);
|
);
|
||||||
|
GBLog.info(`Translated text(5): ${text}.`);
|
||||||
|
|
||||||
const analytics = new AnalyticsService();
|
const analytics = new AnalyticsService();
|
||||||
const userProfile = await min.userProfile.get(step.context, {});
|
const userProfile = await min.userProfile.get(step.context, {});
|
||||||
analytics.createMessage(min.instance.instanceId, userProfile.conversation, null, text);
|
analytics.createMessage(min.instance.instanceId, userProfile.conversation, null, text);
|
||||||
|
|
|
@ -764,9 +764,20 @@ export class GBMinService {
|
||||||
if (step.activeDialog !== undefined) {
|
if (step.activeDialog !== undefined) {
|
||||||
await step.continueDialog();
|
await step.continueDialog();
|
||||||
} else {
|
} else {
|
||||||
let query = context.activity.text;
|
let text = context.activity.text;
|
||||||
|
|
||||||
let locale = 'pt';
|
// Spells check the input text before translating.
|
||||||
|
|
||||||
|
const key = min.instance.spellcheckerKey ? min.instance.spellcheckerKey : min.instance.spellcheckerKey;
|
||||||
|
if (key) {
|
||||||
|
const data = await AzureText.getSpelledText(min.instance.spellcheckerKey, text);
|
||||||
|
if (data !== text) {
|
||||||
|
GBLog.info(`Spelling corrected: ${data}`);
|
||||||
|
text = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let locale = 'en';
|
||||||
if (
|
if (
|
||||||
process.env.TRANSLATOR_DISABLED !== 'true' ||
|
process.env.TRANSLATOR_DISABLED !== 'true' ||
|
||||||
min.core.getParam<boolean>(min.instance, 'Enable Worldwide Translator')
|
min.core.getParam<boolean>(min.instance, 'Enable Worldwide Translator')
|
||||||
|
@ -777,7 +788,7 @@ export class GBMinService {
|
||||||
minBoot.instance.textAnalyticsEndpoint
|
minBoot.instance.textAnalyticsEndpoint
|
||||||
? minBoot.instance.textAnalyticsEndpoint
|
? minBoot.instance.textAnalyticsEndpoint
|
||||||
: minBoot.instance.textAnalyticsEndpoint,
|
: minBoot.instance.textAnalyticsEndpoint,
|
||||||
query
|
text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,15 +799,15 @@ export class GBMinService {
|
||||||
user.locale = locale;
|
user.locale = locale;
|
||||||
await user.save();
|
await user.save();
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
const notTranslatedQuery = query;
|
const notTranslatedQuery = text;
|
||||||
query = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min,
|
min,
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
query,
|
text,
|
||||||
'en'
|
'en'
|
||||||
);
|
);
|
||||||
GBLog.info(`Translated text: ${query}.`);
|
GBLog.info(`Translated text (1): ${text}.`);
|
||||||
|
|
||||||
// Checks if any .gbapp will handle this answer, if not goes to kb.gbapp.
|
// Checks if any .gbapp will handle this answer, if not goes to kb.gbapp.
|
||||||
|
|
||||||
|
@ -804,7 +815,7 @@ export class GBMinService {
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
if (
|
if (
|
||||||
await e.onExchangeData(min, 'handleAnswer', {
|
await e.onExchangeData(min, 'handleAnswer', {
|
||||||
query: query,
|
query: text,
|
||||||
step: step,
|
step: step,
|
||||||
notTranslatedQuery: notTranslatedQuery,
|
notTranslatedQuery: notTranslatedQuery,
|
||||||
message: message ? message['dataValues'] : null,
|
message: message ? message['dataValues'] : null,
|
||||||
|
@ -817,7 +828,7 @@ export class GBMinService {
|
||||||
|
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
await step.beginDialog('/answer', {
|
await step.beginDialog('/answer', {
|
||||||
query: query,
|
query: text,
|
||||||
user: user ? user['dataValues'] : null,
|
user: user ? user['dataValues'] : null,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
|
|
|
@ -116,7 +116,7 @@ export class AskDialog extends IGBDialog {
|
||||||
|
|
||||||
let query = step.result;
|
let query = step.result;
|
||||||
|
|
||||||
let locale = 'pt';
|
let locale = 'en';
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
if (process.env.TRANSLATOR_DISABLED !== 'true' && translatorEnabled()) {
|
if (process.env.TRANSLATOR_DISABLED !== 'true' && translatorEnabled()) {
|
||||||
locale = await AzureText.getLocale(
|
locale = await AzureText.getLocale(
|
||||||
|
@ -142,7 +142,7 @@ export class AskDialog extends IGBDialog {
|
||||||
query,
|
query,
|
||||||
'en'
|
'en'
|
||||||
);
|
);
|
||||||
GBLog.info(`Translated text: ${query}.`);
|
GBLog.info(`Translated text (3): ${query}.`);
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
|
@ -183,13 +183,29 @@ export class AskDialog extends IGBDialog {
|
||||||
const member = step.context.activity.from;
|
const member = step.context.activity.from;
|
||||||
const userDb = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
const userDb = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
|
|
||||||
|
// Spells check the input text before translating.
|
||||||
|
|
||||||
|
const key = min.instance.spellcheckerKey ? minBoot.instance.spellcheckerKey : min.instance.spellcheckerKey;
|
||||||
|
if (key) {
|
||||||
|
const data = await AzureText.getSpelledText(min.instance.spellcheckerKey, text);
|
||||||
|
if (data !== text) {
|
||||||
|
GBLog.info(`Spelling corrected: ${data}`);
|
||||||
|
text = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translates text before sending Search or NLP.
|
||||||
|
|
||||||
text = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min,
|
min,
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
userDb.locale ? userDb.locale : 'pt'
|
userDb.locale ? userDb.locale : 'en'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
GBLog.info(`Translated text (2): ${text}`);
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
throw new Error(`/answer being called with no args query text.`);
|
throw new Error(`/answer being called with no args query text.`);
|
||||||
|
@ -203,20 +219,12 @@ export class AskDialog extends IGBDialog {
|
||||||
} else if (step.options && step.options.fromFaq) {
|
} else if (step.options && step.options.fromFaq) {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].going_answer);
|
await min.conversationalService.sendText(min, step, Messages[locale].going_answer);
|
||||||
}
|
}
|
||||||
// Spells check the input text before sending Search or NLP.
|
|
||||||
const key = min.instance.spellcheckerKey ? minBoot.instance.spellcheckerKey : min.instance.spellcheckerKey;
|
|
||||||
if (key) {
|
|
||||||
const data = await AzureText.getSpelledText(min.instance.spellcheckerKey, text);
|
|
||||||
if (data !== text) {
|
|
||||||
GBLog.info(`Spelling corrected: ${data}`);
|
|
||||||
text = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchScore = min.instance.searchScore ? min.instance.searchScore : minBoot.instance.searchScore;
|
const searchScore = min.instance.searchScore ? min.instance.searchScore : minBoot.instance.searchScore;
|
||||||
// Searches KB for the first time.
|
// Searches KB for the first time.
|
||||||
user.lastQuestion = text;
|
user.lastQuestion = text;
|
||||||
await min.userProfile.set(step.context, user);
|
await min.userProfile.set(step.context, user);
|
||||||
|
|
||||||
const resultsA = await service.ask(min.instance, text, searchScore, user.subjects);
|
const resultsA = await service.ask(min.instance, text, searchScore, user.subjects);
|
||||||
|
|
||||||
// If there is some result, answer immediately.
|
// If there is some result, answer immediately.
|
||||||
|
@ -246,6 +254,8 @@ export class AskDialog extends IGBDialog {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].wider_answer);
|
await min.conversationalService.sendText(min, step, Messages[locale].wider_answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Put braces in this IF statment.
|
||||||
|
|
||||||
if (resultsB.answer)
|
if (resultsB.answer)
|
||||||
// Sends the answer to all outputs, including projector.
|
// Sends the answer to all outputs, including projector.
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,8 @@ 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) {
|
if (values && values.length > 0 && values[0]['@search.score'] >= 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) {
|
||||||
|
@ -213,6 +215,7 @@ export class KBService implements IGBKBService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const data = await this.getAnswerByText(instance.instanceId, query);
|
const data = await this.getAnswerByText(instance.instanceId, query);
|
||||||
if (data) {
|
if (data) {
|
||||||
return { answer: data.answer, questionId: data.question.questionId };
|
return { answer: data.answer, questionId: data.question.questionId };
|
||||||
|
@ -298,6 +301,7 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
GBLog.info(`Now importing ${rows.length} rows from tabular file ${filePath}...`);
|
GBLog.info(`Now importing ${rows.length} rows from tabular file ${filePath}...`);
|
||||||
return asyncPromise.eachSeries(rows, async line => {
|
return asyncPromise.eachSeries(rows, async line => {
|
||||||
|
|
||||||
// Skips the first line.
|
// Skips the first line.
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -308,6 +312,7 @@ export class KBService implements IGBKBService {
|
||||||
line._cells[3] !== undefined &&
|
line._cells[3] !== undefined &&
|
||||||
line._cells[4] !== undefined
|
line._cells[4] !== undefined
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// Extracts values from columns in the current line.
|
// Extracts values from columns in the current line.
|
||||||
|
|
||||||
const subjectsText = line._cells[0].text;
|
const subjectsText = line._cells[0].text;
|
||||||
|
@ -443,7 +448,7 @@ export class KBService implements IGBKBService {
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
answer.content,
|
answer.content,
|
||||||
user.locale ? user.locale : 'pt'
|
user.locale ? user.locale : 'en'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Converts from Markdown to HTML.
|
// Converts from Markdown to HTML.
|
||||||
|
|
Loading…
Add table
Reference in a new issue