Skip to content

Commit

Permalink
Merge branch 'master' into stgum/filenamify
Browse files Browse the repository at this point in the history
  • Loading branch information
cleemullins authored Jun 19, 2019
2 parents c6490e3 + d714487 commit ae38ae0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
17 changes: 13 additions & 4 deletions libraries/botbuilder-ai/src/luisRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
* @param context Context for the current turn of conversation with the use.
* @param telemetryProperties Additional properties to be logged to telemetry with the LuisResult event.
* @param telemetryMetrics Additional metrics to be logged to telemetry with the LuisResult event.
* @param options (Optional) options object used to control predictions. Should conform to the [LuisPrectionOptions](#luispredictionoptions) definition.
*/
public recognize(context: TurnContext, telemetryProperties?: { [key: string]: string }, telemetryMetrics?: { [key: string]: number }): Promise<RecognizerResult> {
public recognize(context: TurnContext, telemetryProperties?: { [key: string]: string }, telemetryMetrics?: { [key: string]: number }, options?: LuisPredictionOptions): Promise<RecognizerResult> {
const cached: any = context.turnState.get(this.cacheKey);
const luisPredictionOptions = options ? this.setLuisPredictionOptions(this.options, options) : this.options;
if (!cached) {
const utterance: string = context.activity.text || '';
let recognizerPromise: Promise<RecognizerResult>;
Expand All @@ -288,12 +290,12 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
recognizerPromise = this.luisClient.prediction.resolve(
this.application.applicationId, utterance,
{
verbose: this.options.includeAllIntents,
verbose: luisPredictionOptions.includeAllIntents,
customHeaders: {
'Ocp-Apim-Subscription-Key': this.application.endpointKey,
'User-Agent': this.getUserAgent()
},
...this.options
...luisPredictionOptions
})
// Map results
.then((luisResult: LuisModels.LuisResult) => ({
Expand All @@ -303,7 +305,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
entities: this.getEntitiesAndMetadata(
luisResult.entities,
luisResult.compositeEntities,
this.options.includeInstanceData === undefined || this.options.includeInstanceData
luisPredictionOptions.includeInstanceData === undefined || luisPredictionOptions.includeInstanceData
),
sentiment: this.getSentiment(luisResult),
luisResult: (this.includeApiResults ? luisResult : null)
Expand Down Expand Up @@ -709,6 +711,13 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
return result;
}

/**
* Merges the default options set by the Recognizer contructor with the 'user' options passed into the 'recognize' method
*/
private setLuisPredictionOptions(defaultOptions: LuisPredictionOptions, userOptions: LuisPredictionOptions): any {
return Object.assign(defaultOptions, userOptions);
}

/**
* Performs a series of valdiations on `LuisRecognizer.application`.
*
Expand Down
29 changes: 29 additions & 0 deletions libraries/botbuilder-ai/tests/luisRecognizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,35 @@ describe('LuisRecognizer', function () {
});
});

it('should accept LuisPredictionOptions passed into recognizer "recognize" method', done => {
const luisPredictionDefaultOptions = {
includeAllIntents: true,
includeInstanceData: true
};
const luisPredictionUserOptions = {
includeAllIntents: false,
includeInstanceData: false
};
const recognizer = new LuisRecognizer({ applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, true);
const mergedOptions = luisPredictionUserOptions ? recognizer.setLuisPredictionOptions(recognizer.options, luisPredictionUserOptions) : recognizer.options;
assert(mergedOptions.includeAllIntents === false);
assert(mergedOptions.includeInstanceData === false);
throttle(done);
});

it('should use default Luis prediction options if no user options passed in', done => {
const luisPredictionDefaultOptions = {
includeAllIntents: true,
includeInstanceData: true
};
const luisPredictionUserOptions = null;
const recognizer = new LuisRecognizer({ applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, true);
const mergedOptions = luisPredictionUserOptions ? recognizer.setLuisPredictionOptions(recognizer.options, luisPredictionUserOptions) : recognizer.options;
assert(mergedOptions.includeAllIntents === true);
assert(mergedOptions.includeInstanceData === true);
throttle(done);
});

});

class telemetryOverrideRecognizer extends LuisRecognizer {
Expand Down
27 changes: 14 additions & 13 deletions libraries/botframework-config/src/botConfigurationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IAppInsightsService, IBlobStorageService, IBotConfiguration, IBotServic

/**
* This is class which allows you to manipulate in memory representations of bot configuration with
* no nodejs depedencies.
* no nodejs dependencies.
*/
export class BotConfigurationBase implements Partial<IBotConfiguration> {

Expand All @@ -25,7 +25,7 @@ export class BotConfigurationBase implements Partial<IBotConfiguration> {
public version: string = '2.0';

/**
* Creates a new BotConfigutationBase instance.
* Creates a new BotConfigurationBase instance.
*/
constructor() {
// noop
Expand Down Expand Up @@ -107,18 +107,19 @@ export class BotConfigurationBase implements Partial<IBotConfiguration> {
public connectService(newService: IConnectedService): string {
const service: ConnectedService = BotConfigurationBase.serviceFromJSON(newService);

// assign a unique id
let found = false;
do {
found = false;
service.id = Math.floor((Math.random() * 255)).toString();
for (const existingService of this.services) {
if (existingService.id === service.id) {
found = true;
break;
if (!service.id) {
let maxValue = 0;
this.services.forEach((s) => {
if (parseInt(s.id) > maxValue) {
maxValue = parseInt(s.id);
}
}
} while (found);
});

service.id = (++maxValue).toString();
}
else if (this.services.filter(s => s.type === service.type && s.id === service.id).length) {
throw new Error(`Service with ${ service.id } is already connected`);
}

this.services.push(service);

Expand Down
2 changes: 1 addition & 1 deletion libraries/botframework-config/tests/connect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("ServiceManipulation", () => {
var config = await bf.BotConfiguration.load(testBotPath);
var config2 = new bf.BotConfiguration();
for(let service of config.services) {
service.id = "1";
service.id = undefined;
config2.connectService(service);
}

Expand Down

0 comments on commit ae38ae0

Please sign in to comment.