コード例 #1
0
        public void UserAgentContainsProductVersion()
        {
            var application = new LuisApplication
            {
                EndpointKey   = "this-is-not-a-key",
                ApplicationId = Guid.Empty.ToString(),
                Endpoint      = "https://westus.api.cognitive.microsoft.com",
            };

            var clientHandler = new EmptyLuisResponseClientHandlerV3();

            var recognizer = new LuisRecognizer(new LuisRecognizerOptionsV3(application), clientHandler);

            var adapter  = new NullAdapter();
            var activity = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var recognizerResult = recognizer.RecognizeAsync(turnContext, CancellationToken.None).Result;

            Assert.IsNotNull(recognizerResult);

            var userAgent = clientHandler.UserAgent;

            // And that we added the bot.builder package details.
            Assert.IsTrue(userAgent.Contains("Microsoft.Bot.Builder.AI.Luis/4"));
        }
コード例 #2
0
        public async Task Telemetry_ConvertParms()
        {
            // Arrange
            // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
            // theses are GUIDs edited to look right to the parsing and validation code.
            var endpoint        = "https://westus.api.cognitive.microsoft.com/luis/v3.0-preview/apps/b31aeaf3-3511-495b-a07f-571fc873214b/slots/production/predict?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q=";
            var clientHandler   = new EmptyLuisResponseClientHandlerV3();
            var luisApp         = new LuisApplication(endpoint);
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var adapter         = new NullAdapter();
            var activity        = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var options = new LuisRecognizerOptionsV3(luisApp)
            {
                TelemetryClient        = telemetryClient.Object,
                LogPersonalInformation = false,
            };
            var recognizer = new LuisRecognizer(options, clientHandler);

            // Act
            var additionalProperties = new Dictionary <string, string>
            {
                { "test", "testvalue" },
                { "foo", "foovalue" },
            };
            var additionalMetrics = new Dictionary <string, double>
            {
                { "moo", 3.14159 },
                { "luis", 1.0001 },
            };

            var result = await recognizer.RecognizeAsync(turnContext, additionalProperties, additionalMetrics, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(telemetryClient.Invocations.Count, 1);
            Assert.AreEqual(telemetryClient.Invocations[0].Arguments[0].ToString(), "LuisResult");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("test"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["test"] == "testvalue");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("foo"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["foo"] == "foovalue");
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("applicationId"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intent"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("intentScore"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("fromId"));
            Assert.IsTrue(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("entities"));
            Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("moo"));
            Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["moo"], 3.14159);
            Assert.IsTrue(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2]).ContainsKey("luis"));
            Assert.AreEqual(((Dictionary <string, double>)telemetryClient.Invocations[0].Arguments[2])["luis"], 1.0001);
        }
コード例 #3
0
        public async Task Telemetry_OverrideOnDeriveAsync()
        {
            // Arrange
            // Note this is NOT a real LUIS application ID nor a real LUIS subscription-key
            // theses are GUIDs edited to look right to the parsing and validation code.
            var endpoint        = "https://westus.api.cognitive.microsoft.com/luis/prediction/v3.0/apps/b31aeaf3-3511-495b-a07f-571fc873214b/slots/production/predict?verbose=true&timezoneOffset=-360&subscription-key=048ec46dc58e495482b0c447cfdbd291&q=";
            var clientHandler   = new EmptyLuisResponseClientHandlerV3();
            var luisApp         = new LuisApplication(endpoint);
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var adapter         = new NullAdapter();
            var activity        = new Activity
            {
                Type         = ActivityTypes.Message,
                Text         = "please book from May 5 to June 6",
                Recipient    = new ChannelAccount(),        // to no where
                From         = new ChannelAccount(),        // from no one
                Conversation = new ConversationAccount(),   // on no conversation
            };

            var turnContext = new TurnContext(adapter, activity);

            var options = new LuisRecognizerOptionsV3(luisApp)
            {
                TelemetryClient        = telemetryClient.Object,
                LogPersonalInformation = false,
            };
            var recognizer = new TelemetryOverrideRecognizer(options, clientHandler);

            var additionalProperties = new Dictionary <string, string>
            {
                { "test", "testvalue" },
                { "foo", "foovalue" },
            };
            var result = await recognizer.RecognizeAsync(turnContext, additionalProperties).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, telemetryClient.Invocations.Count);
            Assert.Equal("LuisResult", telemetryClient.Invocations[0].Arguments[0].ToString());
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("MyImportantProperty"));
            Assert.Equal("myImportantValue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["MyImportantProperty"]);
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("test"));
            Assert.Equal("testvalue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["test"]);
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1]).ContainsKey("foo"));
            Assert.Equal("foovalue", ((Dictionary <string, string>)telemetryClient.Invocations[0].Arguments[1])["foo"]);
            Assert.Equal("MySecondEvent", telemetryClient.Invocations[1].Arguments[0].ToString());
            Assert.True(((Dictionary <string, string>)telemetryClient.Invocations[1].Arguments[1]).ContainsKey("MyImportantProperty2"));
            Assert.Equal("myImportantValue2", ((Dictionary <string, string>)telemetryClient.Invocations[1].Arguments[1])["MyImportantProperty2"]);
        }