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.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale ? user.locale : 'pt'
|
||||
user.locale ? user.locale : 'en'
|
||||
);
|
||||
GBLog.info(`Translated text(4): ${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.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale ? user.locale : 'pt'
|
||||
user.locale ? user.locale : 'en'
|
||||
);
|
||||
GBLog.info(`Translated text(5): ${text}.`);
|
||||
|
||||
const analytics = new AnalyticsService();
|
||||
const userProfile = await min.userProfile.get(step.context, {});
|
||||
analytics.createMessage(min.instance.instanceId, userProfile.conversation, null, text);
|
||||
|
|
|
@ -764,9 +764,20 @@ export class GBMinService {
|
|||
if (step.activeDialog !== undefined) {
|
||||
await step.continueDialog();
|
||||
} 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 (
|
||||
process.env.TRANSLATOR_DISABLED !== 'true' ||
|
||||
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,
|
||||
query
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -788,15 +799,15 @@ export class GBMinService {
|
|||
user.locale = locale;
|
||||
await user.save();
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
const notTranslatedQuery = query;
|
||||
query = await min.conversationalService.translate(
|
||||
const notTranslatedQuery = text;
|
||||
text = await min.conversationalService.translate(
|
||||
min,
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
query,
|
||||
text,
|
||||
'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.
|
||||
|
||||
|
@ -804,7 +815,7 @@ export class GBMinService {
|
|||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||
if (
|
||||
await e.onExchangeData(min, 'handleAnswer', {
|
||||
query: query,
|
||||
query: text,
|
||||
step: step,
|
||||
notTranslatedQuery: notTranslatedQuery,
|
||||
message: message ? message['dataValues'] : null,
|
||||
|
@ -817,7 +828,7 @@ export class GBMinService {
|
|||
|
||||
if (!handled) {
|
||||
await step.beginDialog('/answer', {
|
||||
query: query,
|
||||
query: text,
|
||||
user: user ? user['dataValues'] : null,
|
||||
message: message
|
||||
});
|
||||
|
|
|
@ -116,7 +116,7 @@ export class AskDialog extends IGBDialog {
|
|||
|
||||
let query = step.result;
|
||||
|
||||
let locale = 'pt';
|
||||
let locale = 'en';
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
if (process.env.TRANSLATOR_DISABLED !== 'true' && translatorEnabled()) {
|
||||
locale = await AzureText.getLocale(
|
||||
|
@ -142,7 +142,7 @@ export class AskDialog extends IGBDialog {
|
|||
query,
|
||||
'en'
|
||||
);
|
||||
GBLog.info(`Translated text: ${query}.`);
|
||||
GBLog.info(`Translated text (3): ${query}.`);
|
||||
|
||||
let handled = false;
|
||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||
|
@ -183,13 +183,29 @@ export class AskDialog extends IGBDialog {
|
|||
const member = step.context.activity.from;
|
||||
const userDb = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
||||
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(
|
||||
min,
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
userDb.locale ? userDb.locale : 'pt'
|
||||
);
|
||||
userDb.locale ? userDb.locale : 'en'
|
||||
);
|
||||
|
||||
GBLog.info(`Translated text (2): ${text}`);
|
||||
|
||||
if (!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) {
|
||||
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;
|
||||
// Searches KB for the first time.
|
||||
user.lastQuestion = text;
|
||||
await min.userProfile.set(step.context, user);
|
||||
|
||||
const resultsA = await service.ask(min.instance, text, searchScore, user.subjects);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// TODO: Put braces in this IF statment.
|
||||
|
||||
if (resultsB.answer)
|
||||
// Sends the answer to all outputs, including projector.
|
||||
|
||||
|
|
|
@ -204,6 +204,8 @@ export class KBService implements IGBKBService {
|
|||
|
||||
const values = results.result.value;
|
||||
|
||||
|
||||
|
||||
if (values && values.length > 0 && values[0]['@search.score'] >= searchScore) {
|
||||
const value = await this.getAnswerById(instance.instanceId, values[0].answerId);
|
||||
if (value !== null) {
|
||||
|
@ -213,6 +215,7 @@ export class KBService implements IGBKBService {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
const data = await this.getAnswerByText(instance.instanceId, query);
|
||||
if (data) {
|
||||
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}...`);
|
||||
return asyncPromise.eachSeries(rows, async line => {
|
||||
|
||||
// Skips the first line.
|
||||
|
||||
if (
|
||||
|
@ -308,6 +312,7 @@ export class KBService implements IGBKBService {
|
|||
line._cells[3] !== undefined &&
|
||||
line._cells[4] !== undefined
|
||||
) {
|
||||
|
||||
// Extracts values from columns in the current line.
|
||||
|
||||
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.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
answer.content,
|
||||
user.locale ? user.locale : 'pt'
|
||||
user.locale ? user.locale : 'en'
|
||||
);
|
||||
|
||||
// Converts from Markdown to HTML.
|
||||
|
|
Loading…
Add table
Reference in a new issue