fix(core.gbapp): Start dialog done and log improvements.
This commit is contained in:
parent
d04a4804a8
commit
1ff24290f0
6 changed files with 94 additions and 24 deletions
|
@ -481,7 +481,7 @@ export class GBConversationalService {
|
|||
try {
|
||||
const saved = step.context.activity.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;
|
||||
} catch (error) {
|
||||
// tslint:disable:no-unsafe-any
|
||||
|
@ -498,12 +498,15 @@ export class GBConversationalService {
|
|||
// tslint:enable:no-unsafe-any
|
||||
}
|
||||
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
let nlpActive = false;
|
||||
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 => {
|
||||
score = nlp.intents[name].score;
|
||||
if (score > min.instance.nlpScore) {
|
||||
if (score > instanceScore) {
|
||||
nlpActive = true;
|
||||
}
|
||||
});
|
||||
|
@ -518,7 +521,7 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
@ -548,7 +551,7 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
GBLog.info(
|
||||
`NLP NOT called: score: ${score} > required (nlpScore): ${min.instance.nlpScore}`
|
||||
`NLP NOT called: score: ${score} > required (nlpScore): ${instanceScore}`
|
||||
);
|
||||
|
||||
return false;
|
||||
|
|
|
@ -587,7 +587,7 @@ STORAGE_SYNC=true
|
|||
return value ? value : defaultValue;
|
||||
}
|
||||
if (typeof defaultValue === 'number') {
|
||||
return new Number(value ? defaultValue : defaultValue ? defaultValue : 0);
|
||||
return new Number(value ? value : defaultValue ? defaultValue : 0);
|
||||
}
|
||||
|
||||
if (instance['dataValues'] && !value) {
|
||||
|
|
|
@ -614,6 +614,7 @@ export class GBMinService {
|
|||
// Get loaded user state
|
||||
const step = await min.dialogs.createContext(context);
|
||||
step.context.activity.locale = 'pt-BR';
|
||||
let firstTime = false;
|
||||
|
||||
try {
|
||||
const user = await min.userProfile.get(context, {});
|
||||
|
@ -622,6 +623,7 @@ export class GBMinService {
|
|||
|
||||
const sec = new SecService();
|
||||
if (!user.loaded) {
|
||||
firstTime = true;
|
||||
await min.conversationalService.sendEvent(min, step, 'loadInstance', {
|
||||
instanceId: instance.instanceId,
|
||||
botId: instance.botId,
|
||||
|
@ -668,7 +670,19 @@ export class GBMinService {
|
|||
await CollectionUtil.asyncForEach(appPackages, async e => {
|
||||
await e.onNewSession(min, step);
|
||||
});
|
||||
await step.beginDialog('/');
|
||||
|
||||
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('/');
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
GBLog.info(`Member added to conversation: ${member.name}`);
|
||||
}
|
||||
|
|
|
@ -423,7 +423,7 @@ export class GBVMService extends GBService {
|
|||
const isIntentYes = (locale, utterance) => {
|
||||
return utterance.toLowerCase().match(Messages[locale].affirmative_sentences);
|
||||
}
|
||||
|
||||
|
||||
let result = step.result;
|
||||
if (step.activeDialog.state.options['boolean']) {
|
||||
|
||||
|
@ -436,7 +436,7 @@ export class GBVMService extends GBService {
|
|||
|
||||
}
|
||||
else if (step.activeDialog.state.options['email']) {
|
||||
// e@e.com
|
||||
// e@e.com
|
||||
}
|
||||
else if (step.activeDialog.state.options['number']) {
|
||||
// MAX and MIN.
|
||||
|
@ -456,7 +456,7 @@ export class GBVMService extends GBService {
|
|||
else if (step.activeDialog.state.options['zipcode']) {
|
||||
// 12333-222
|
||||
}
|
||||
else if (step.activeDialog.state.options['menu']){
|
||||
else if (step.activeDialog.state.options['menu']) {
|
||||
// ['drums', 'guitar', 'bass']; kpmSearch
|
||||
}
|
||||
|
||||
|
@ -487,6 +487,15 @@ export class GBVMService extends GBService {
|
|||
|
||||
const mainMethod = text.toLowerCase();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,9 @@ export class AskDialog extends IGBDialog {
|
|||
|
||||
// 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;
|
||||
await min.userProfile.set(step.context, user);
|
||||
|
||||
|
@ -192,15 +194,14 @@ export class AskDialog extends IGBDialog {
|
|||
answer = resultsA.answer;
|
||||
|
||||
// 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.
|
||||
|
||||
const resultsB = await service.ask(min.instance, text, searchScore, undefined);
|
||||
|
||||
// If there is some result, answer immediately.
|
||||
|
||||
if (resultsB !== undefined && resultsB.answer !== undefined)
|
||||
{
|
||||
if (resultsB !== undefined && resultsB.answer !== undefined) {
|
||||
// Saves some context info.
|
||||
|
||||
const user2 = await min.userProfile.get(step.context, {});
|
||||
|
|
|
@ -177,6 +177,8 @@ export class KBService implements IGBKBService {
|
|||
): Promise<KBServiceSearchResults> {
|
||||
// Builds search query.
|
||||
|
||||
|
||||
|
||||
query = query.toLowerCase();
|
||||
query = query.replace('?', ' ');
|
||||
query = query.replace('!', ' ');
|
||||
|
@ -192,6 +194,8 @@ export class KBService implements IGBKBService {
|
|||
}
|
||||
}
|
||||
|
||||
let notSearched = true;
|
||||
|
||||
// tslint:disable:no-unsafe-any
|
||||
if (instance.searchKey !== null && GBConfigService.get('STORAGE_DIALECT') === 'mssql') {
|
||||
const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey);
|
||||
|
@ -205,22 +209,61 @@ 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) {
|
||||
return { answer: value, questionId: values[0].questionId };
|
||||
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);
|
||||
if (value !== null) {
|
||||
GBLog.info(
|
||||
`SEARCH WILL BE USED with score: ${returnedScore} > required (searchScore): ${searchScore}`
|
||||
);
|
||||
notSearched = false;
|
||||
return { answer: value, questionId: values[0].questionId };
|
||||
} 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 {
|
||||
const data = await this.getAnswerByText(instance.instanceId, query);
|
||||
if (data) {
|
||||
return { answer: data.answer, questionId: data.question.questionId };
|
||||
} else {
|
||||
GBLog.info(
|
||||
`SEARCH called but NO answer could be found (zero results).`
|
||||
);
|
||||
return { answer: undefined, questionId: 0 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DISABLED: Searches via Database "WHERE" command.
|
||||
|
||||
// if (notSearched) {
|
||||
// const data = await this.getAnswerByText(instance.instanceId, query);
|
||||
// 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[]> {
|
||||
|
|
Loading…
Add table
Reference in a new issue