Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class BaseTest
{
private const HttpRecorderMode mode = HttpRecorderMode.Playback;

protected const string appId = "86226c53-b7a6-416f-876b-226b2b5ab07b";
protected const string appId = "0894d430-8f00-4bcd-8153-45e06a1feca1";
protected const string subscriptionKey = "00000000000000000000000000000000";

private string ClassName => GetType().FullName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,238 @@
namespace LUIS.Runtime.Tests
{
using System.Collections.Generic;
using System;
using System.Linq;
using Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime;
using Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.Models;
using Microsoft.Rest;
using Newtonsoft.Json.Linq;
using Xunit;

public class PredictionTests : BaseTest
{
[Fact]
public void Prediction_Post()
public void Prediction_Slot()
{
UseClientFor(async client =>
{
var utterance = "this is a test with post";
var result = await client.Prediction.ResolveAsync(System.Guid.Parse(appId), utterance);
var utterance = "today this is a test with post";
var slotName = "production";

Assert.Equal("None", result.TopScoringIntent.Intent);
var requestOptions = new PredictionRequestOptions
{
DatetimeReference = DateTime.Parse("2019-01-01"),
OverridePredictions = true
};

var externalResolution = JObject.FromObject(new { text = "post", external = true });
var externalEntities = new[]
{
new ExternalEntity
{
EntityName = "simple",
StartIndex = 26,
EntityLength = 4,
Resolution = externalResolution
}
};

var dynamicLists = new[]
{
new DynamicList
{
ListEntityName = "list",
RequestLists = new[]
{
new RequestList
{
Name = "test",
CanonicalForm = "testing",
Synonyms = new[] { "this" }
}
}
}
};

var predictionRequest = new PredictionRequest
{
Query = utterance,
Options = requestOptions,
ExternalEntities = externalEntities,
DynamicLists = dynamicLists
};

var result = await client.Prediction.GetSlotPredictionAsync(
Guid.Parse(appId),
slotName,
predictionRequest,
verbose: true,
showAllIntents: true);

var prediction = result.Prediction;
Assert.Equal(utterance, result.Query);
Assert.Equal(utterance, prediction.NormalizedQuery);
Assert.Equal("intent", prediction.TopIntent);
Assert.Equal(2, prediction.Intents.Count);
Assert.Equal(4, prediction.Entities.Count);
Assert.Contains("datetimeV2", prediction.Entities.Keys);
Assert.Contains("simple", prediction.Entities.Keys);
Assert.Contains("list", prediction.Entities.Keys);
Assert.Contains("$instance", prediction.Entities.Keys);

// Test external resolution
var actualResolution = (prediction.Entities["simple"] as JArray).Single();
Assert.True(JToken.DeepEquals(externalResolution, actualResolution));

var topIntent = prediction.Intents[prediction.TopIntent];
Assert.True(topIntent.Score > 0.5);

Assert.Equal("positive", prediction.Sentiment.Label);
Assert.True(prediction.Sentiment.Score > 0.5);

// dispatch
var child = topIntent.ChildApp;
Assert.Equal(utterance, child.NormalizedQuery);
Assert.Equal("None", child.TopIntent);
Assert.Equal(1, child.Intents.Count);
Assert.Equal(2, child.Entities.Count);
Assert.Contains("datetimeV2", child.Entities.Keys);
Assert.Contains("$instance", child.Entities.Keys);

var dispatchTopIntent = child.Intents[child.TopIntent];
Assert.True(dispatchTopIntent.Score > 0.5);

Assert.Equal("positive", child.Sentiment.Label);
Assert.True(child.Sentiment.Score > 0.5);
});
}

[Fact]
public void Prediction_WithSpellCheck()
public void Prediction_Version()
{
UseClientFor(async client =>
{
var utterance = "helo, what dai is todey?";
var result = await client.Prediction.ResolveAsync(System.Guid.Parse(appId), utterance, spellCheck: true, bingSpellCheckSubscriptionKey: "00000000000000000000000000000000");
var utterance = "today this is a test with post";
var versionId = "0.1";

Assert.True(!string.IsNullOrWhiteSpace(result.AlteredQuery));
Assert.Equal("hello, what day is today?", result.AlteredQuery);
var requestOptions = new PredictionRequestOptions
{
DatetimeReference = DateTime.Parse("2019-01-01"),
OverridePredictions = true
};

var externalResolution = JObject.FromObject(new { text = "post", external = true });
var externalEntities = new[]
{
new ExternalEntity
{
EntityName = "simple",
StartIndex = 26,
EntityLength = 4,
Resolution = externalResolution
}
};

var dynamicLists = new[]
{
new DynamicList
{
ListEntityName = "list",
RequestLists = new[]
{
new RequestList
{
Name = "test",
CanonicalForm = "testing",
Synonyms = new[] { "this" }
}
}
}
};

var predictionRequest = new PredictionRequest
{
Query = utterance,
Options = requestOptions,
ExternalEntities = externalEntities,
DynamicLists = dynamicLists
};

var result = await client.Prediction.GetVersionPredictionAsync(
Guid.Parse(appId),
versionId,
predictionRequest,
verbose: true,
showAllIntents: true);

var prediction = result.Prediction;
Assert.Equal(utterance, result.Query);
Assert.Equal(utterance, prediction.NormalizedQuery);
Assert.Equal("intent", prediction.TopIntent);
Assert.Equal(2, prediction.Intents.Count);
Assert.Equal(4, prediction.Entities.Count);
Assert.Contains("datetimeV2", prediction.Entities.Keys);
Assert.Contains("simple", prediction.Entities.Keys);
Assert.Contains("list", prediction.Entities.Keys);
Assert.Contains("$instance", prediction.Entities.Keys);

// Test external resolution
var actualResolution = (prediction.Entities["simple"] as JArray).Single();
Assert.True(JToken.DeepEquals(externalResolution, actualResolution));

var topIntent = prediction.Intents[prediction.TopIntent];
Assert.True(topIntent.Score > 0.5);

Assert.Equal("positive", prediction.Sentiment.Label);
Assert.True(prediction.Sentiment.Score > 0.5);

// dispatch
var child = topIntent.ChildApp;
Assert.Equal(utterance, child.NormalizedQuery);
Assert.Equal("None", child.TopIntent);
Assert.Equal(1, child.Intents.Count);
Assert.Equal(2, child.Entities.Count);
Assert.Contains("datetimeV2", child.Entities.Keys);
Assert.Contains("$instance", child.Entities.Keys);

var dispatchTopIntent = child.Intents[child.TopIntent];
Assert.True(dispatchTopIntent.Score > 0.5);

Assert.Equal("positive", child.Sentiment.Label);
Assert.True(child.Sentiment.Score > 0.5);
});
}

[Fact]
public void Prediction_InvalidKey_ThrowsAPIErrorException()
public void Prediction_AppNotFound_ThrowsAPIErrorException()
{
var headers = new Dictionary<string, List<string>> { ["Ocp-Apim-Subscription-Key"] = new List<string> { "invalid-key" } };

UseClientFor(async client =>
{
var ex = await Assert.ThrowsAsync<APIErrorException>(async () =>
var ex = await Assert.ThrowsAsync<ErrorException>(async () =>
{
await client.Prediction.ResolveWithHttpMessagesAsync(System.Guid.Parse(appId), "this is a test with post", customHeaders: headers);
await client.Prediction.GetSlotPredictionAsync(
Guid.Parse("7555b7c1-e69c-4580-9d95-1abd6dfa8291"),
"production",
new PredictionRequest
{
Query = "this is a test with post"
});
});

Assert.Equal("401", ex.Body.StatusCode);
Assert.Equal("NotFound", ex.Body.ErrorProperty.Code);
});
}

[Fact]
public void Prediction_QueryTooLong_ThrowsValidationException()
public void Prediction_NullQuery_ThrowsValidationException()
{
UseClientFor(async client =>
{
var query = string.Empty.PadLeft(501, 'x');
var ex = await Assert.ThrowsAsync<ValidationException>(async () =>
{
await client.Prediction.ResolveWithHttpMessagesAsync(System.Guid.Parse(appId), query);
await client.Prediction.GetSlotPredictionAsync(Guid.Parse(appId), "production", new PredictionRequest());
});

Assert.Equal("query", ex.Target);
Assert.Equal("Query", ex.Target);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"Entries": [
{
"RequestUri": "/luis/v3.0-preview/apps/7555b7c1-e69c-4580-9d95-1abd6dfa8291/slots/production/predict",
"EncodedRequestUri": "L2x1aXMvdjMuMC1wcmV2aWV3L2FwcHMvNzU1NWI3YzEtZTY5Yy00NTgwLTlkOTUtMWFiZDZkZmE4MjkxL3Nsb3RzL3Byb2R1Y3Rpb24vcHJlZGljdA==",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"query\": \"this is a test with post\"\r\n}",
"RequestHeaders": {
"Ocp-Apim-Subscription-Key": [
"00000000000000000000000000000000"
],
"User-Agent": [
"FxVersion/4.6.27414.06",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.17763.",
"Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.LUISRuntimeClient/2.1.0.0"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"43"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-store, proxy-revalidate, no-cache, max-age=0, private"
],
"Pragma": [
"no-cache"
],
"Apim-Request-Id": [
"f55e861b-c0b8-474a-a32a-f65a510de7bd"
],
"Request-Id": [
"f55e861b-c0b8-474a-a32a-f65a510de7bd"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains; preload"
],
"Request-Context": [
"appId=cid-v1:26a3540d-a02a-4998-a060-715488fd769b"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Frame-Options": [
"SAMEORIGIN"
],
"Date": [
"Mon, 29 Apr 2019 18:53:23 GMT"
],
"Content-Length": [
"154"
],
"Content-Type": [
"application/json; charset=utf-8"
]
},
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"NotFound\",\r\n \"message\": \"The application 7555b7c1-e69c-4580-9d95-1abd6dfa8291 is not published or doesn't exist.\"\r\n }\r\n}",
"StatusCode": 404
}
],
"Names": {},
"Variables": {}
}

This file was deleted.

Loading