Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle textless messages differently, bringing Node into parity with .NET #856

Merged
merged 4 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions libraries/botbuilder-ai/src/luisRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,28 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
const cached: any = context.turnState.get(this.cacheKey);
if (!cached) {
const utterance: string = context.activity.text || '';

return this.luisClient.prediction.resolve(
this.application.applicationId, utterance,
{
verbose: this.options.includeAllIntents,
customHeaders: {
'Ocp-Apim-Subscription-Key': this.application.endpointKey,
'User-Agent': this.getUserAgent()
},
...this.options
}
)
.then((luisResult: LuisModels.LuisResult) => {
let recognizerPromise: Promise<RecognizerResult>;

if (!utterance.trim()) {
// Bypass LUIS if the activity's text is null or whitespace
recognizerPromise = Promise.resolve({
text: utterance,
intents: { '': { score: 1 } },
entities: {},
});
} else {
recognizerPromise = this.luisClient.prediction.resolve(
this.application.applicationId, utterance,
{
verbose: this.options.includeAllIntents,
customHeaders: {
'Ocp-Apim-Subscription-Key': this.application.endpointKey,
'User-Agent': this.getUserAgent()
},
...this.options
})
// Map results
const recognizerResult: RecognizerResult = {
.then((luisResult: LuisModels.LuisResult) => ({
text: luisResult.query,
alteredText: luisResult.alteredQuery,
intents: this.getIntents(luisResult),
Expand All @@ -296,16 +303,19 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
this.options.includeInstanceData === undefined || this.options.includeInstanceData
),
sentiment: this.getSentiment(luisResult),
luisResult: this.includeApiResults ? luisResult : null
};
luisResult: (this.includeApiResults ? luisResult : null)
}));
}

return recognizerPromise
.then((recognizerResult: RecognizerResult) => {
// Write to cache
context.turnState.set(this.cacheKey, recognizerResult);

// Log telemetry
this.onRecognizerResults(recognizerResult, context, telemetryProperties, telemetryMetrics);

return this.emitTraceInfo(context, luisResult, recognizerResult).then(() => {
return this.emitTraceInfo(context, recognizerResult.luisResult || null, recognizerResult).then(() => {
return recognizerResult;
});
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"intents": {},
"entities": {
"$instance": {}
},
"luisResult": {
"intents": [],
"entities": []
}
"text": "",
"intents": { "": { "score": 1 }},
"entities": {}
}
6 changes: 4 additions & 2 deletions libraries/botbuilder-ai/tests/luisRecognizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ describe('LuisRecognizer', function () {
}, true, false);
});

it('should only return "None" intent for undefined text', done => {
it('should only return empty intent for empty text', done => {
TestJson("EmptyText.json", res => {
const top = LuisRecognizer.topIntent(res);
assert(top === 'None');
assert(top === 'None'); // topIntent() converts '' to 'None'
assert(Object.keys(res.intents).length == 1)
assert('' in res.intents);
done();
});
});
Expand Down