public void AnalyzeConversationWithLanguage() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguage #if SNIPPET AnalyzeConversationOptions options = new AnalyzeConversationOptions( "Menu", "production", "Tendremos 2 platos de nigiri de salmón braseado.") { Language = "es" }; Response <AnalyzeConversationResult> response = client.AnalyzeConversation(options); #else AnalyzeConversationOptions options = new AnalyzeConversationOptions( TestEnvironment.ProjectName, TestEnvironment.DeploymentName, "Tendremos 2 platos de nigiri de salmón braseado.") { Language = "es" }; Response <AnalyzeConversationResult> response = client.AnalyzeConversation(options); #endif Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}"); #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order")); }
public void AnalyzeConversationWithOptions() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptions #if SNIPPET AnalyzeConversationOptions options = new AnalyzeConversationOptions( "Menu", "production", "We'll have 2 plates of seared salmon nigiri."); Response <AnalyzeConversationResult> response = client.AnalyzeConversation(options); #else AnalyzeConversationOptions options = new AnalyzeConversationOptions( TestEnvironment.ProjectName, TestEnvironment.DeploymentName, "We'll have 2 plates of seared salmon nigiri."); Response <AnalyzeConversationResult> response = client.AnalyzeConversation(options); #endif Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}"); #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order")); }
public void AnalyzeConversation() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversation #if SNIPPET ConversationsProject conversationsProject = new ConversationsProject("Menu", "production"); Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "Send an email to Carol about the tomorrow's demo.", conversationsProject); #else Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "Send an email to Carol about the tomorrow's demo.", TestEnvironment.Project); #endif CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction; Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}"); Console.WriteLine("Intents:"); foreach (ConversationIntent intent in conversationPrediction.Intents) { Console.WriteLine($"Category: {intent.Category}"); Console.WriteLine($"Confidence: {intent.Confidence}"); Console.WriteLine(); } Console.WriteLine("Entities:"); foreach (ConversationEntity entity in conversationPrediction.Entities) { Console.WriteLine($"Category: {entity.Category}"); Console.WriteLine($"Text: {entity.Text}"); Console.WriteLine($"Offset: {entity.Offset}"); Console.WriteLine($"Length: {entity.Length}"); Console.WriteLine($"Confidence: {entity.Confidence}"); Console.WriteLine(); foreach (BaseResolution resolution in entity.Resolutions) { if (resolution is DateTimeResolution dateTimeResolution) { Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}"); Console.WriteLine($"Timex: {dateTimeResolution.Timex}"); Console.WriteLine($"Value: {dateTimeResolution.Value}"); Console.WriteLine(); } } } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Read")); }
public void AnalyzeConversationOrchestrationPredictionLuis() { ConversationAnalysisClient client = Client; Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "Reserve a table for 2 at the Italian restaurant.", TestEnvironment.OrchestrationProject); CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionLuis string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.Luis) { LuisTargetIntentResult luisTargetIntentResult = targetIntentResult as LuisTargetIntentResult; BinaryData luisResponse = luisTargetIntentResult.Result; Console.WriteLine($"LUIS Response: {luisResponse.ToString()}"); } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Luis)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("RestaurantIntent")); }
public void AnalyzeConversationOrchestrationPredictionLuis() { ConversationAnalysisClient client = Client; Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "Book me flight from London to Paris", TestEnvironment.OrchestrationProject); OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionLuis string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.Luis) { LuisTargetIntentResult luisTargetIntentResult = targetIntentResult as LuisTargetIntentResult; BinaryData luisResponse = luisTargetIntentResult.Result; Console.WriteLine($"LUIS Response: {luisResponse.ToString()}"); } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Luis)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("FlightBooking")); }
public void AnalyzeConversationOrchestrationPredictionQuestionAnswering() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPrediction #if SNIPPET ConversationsProject orchestrationProject = new ConversationsProject("DomainOrchestrator", "production"); Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "How are you?", orchestrationProject); #else Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "How are you?", TestEnvironment.OrchestrationProject); #endif CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction; #endregion #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering) { Console.WriteLine($"Top intent: {respondingProjectName}"); QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult; KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result; Console.WriteLine("Answers: \n"); foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers) { Console.WriteLine($"Answer: {answer.Answer}"); Console.WriteLine($"Confidence: {answer.Confidence}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("ChitChat-QnA")); }
public void AnalyzeConversationOrchestrationPredictionConversation() { ConversationAnalysisClient client = Client; Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "Send an email to Carol about the tomorrow's demo", TestEnvironment.OrchestrationProject); CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; var orchestratorPrediction = customConversationalTaskResult.Results.Prediction as OrchestratorPrediction; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionConversation string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.Conversation) { ConversationTargetIntentResult cluTargetIntentResult = targetIntentResult as ConversationTargetIntentResult; ConversationResult conversationResult = cluTargetIntentResult.Result; ConversationPrediction conversationPrediction = conversationResult.Prediction; Console.WriteLine($"Top Intent: {conversationResult.Prediction.TopIntent}"); Console.WriteLine($"Intents:"); foreach (ConversationIntent intent in conversationPrediction.Intents) { Console.WriteLine($"Intent Category: {intent.Category}"); Console.WriteLine($"Confidence: {intent.Confidence}"); Console.WriteLine(); } Console.WriteLine($"Entities:"); foreach (ConversationEntity entity in conversationPrediction.Entities) { Console.WriteLine($"Entity Text: {entity.Text}"); Console.WriteLine($"Entity Category: {entity.Category}"); Console.WriteLine($"Confidence: {entity.Confidence}"); Console.WriteLine($"Starting Position: {entity.Offset}"); Console.WriteLine($"Length: {entity.Length}"); Console.WriteLine(); foreach (BaseResolution resolution in entity.Resolutions) { if (resolution is DateTimeResolution dateTimeResolution) { Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}"); Console.WriteLine($"Timex: {dateTimeResolution.Timex}"); Console.WriteLine($"Value: {dateTimeResolution.Value}"); Console.WriteLine(); } } } } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Conversation)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("EmailIntent")); }
public void AnalyzeConversationDeepstack() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationDeepstack #if SNIPPET Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "Menu", "production", "We'll have 2 plates of seared salmon nigiri."); #else Response <AnalyzeConversationResult> response = client.AnalyzeConversation( TestEnvironment.ProjectName, TestEnvironment.DeploymentName, "We'll have 2 plates of seared salmon nigiri."); #endif DeepstackPrediction deepstackPrediction = response.Value.Prediction as DeepstackPrediction; Console.WriteLine("Intents:"); foreach (DeepstackIntent intent in deepstackPrediction.Intents) { Console.WriteLine($"Category:{intent.Category}"); Console.WriteLine($"Confidence Score:{intent.ConfidenceScore}"); Console.WriteLine(); } Console.WriteLine("Entities:"); foreach (DeepstackEntity entity in deepstackPrediction.Entities) { Console.WriteLine($"Category: {entity.Category}"); Console.WriteLine($"Text: {entity.Text}"); Console.WriteLine($"Offset: {entity.Offset}"); Console.WriteLine($"Length: {entity.Length}"); Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(deepstackPrediction.TopIntent, Is.EqualTo("Order")); }
public void AnalyzeConversationWithConversationPredictionResult() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithConversationPrediction #if SNIPPET ConversationsProject conversationsProject = new ConversationsProject("Menu", "production"); Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "We'll have 2 plates of seared salmon nigiri.", conversationsProject); #else Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "We'll have 2 plates of seared salmon nigiri.", TestEnvironment.Project); #endif ConversationPrediction conversationPrediction = response.Value.Prediction as ConversationPrediction; Console.WriteLine("Intents:"); foreach (ConversationIntent intent in conversationPrediction.Intents) { Console.WriteLine($"Category:{intent.Category}"); Console.WriteLine($"Confidence Score:{intent.ConfidenceScore}"); Console.WriteLine(); } Console.WriteLine("Entities:"); foreach (ConversationEntity entity in conversationPrediction.Entities) { Console.WriteLine($"Category: {entity.Category}"); Console.WriteLine($"Text: {entity.Text}"); Console.WriteLine($"Offset: {entity.Offset}"); Console.WriteLine($"Length: {entity.Length}"); Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}"); Console.WriteLine(); } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Order")); }
public void AnalyzeConversationOrchestrationPredictionQuestionAnswering() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPrediction #if SNIPPET ConversationsProject orchestrationProject = new ConversationsProject("DomainOrchestrator", "production"); Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "Where are the calories per recipe?", orchestrationProject); #else Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "Where are the calories per recipe?", TestEnvironment.OrchestrationProject); #endif OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction; #endregion #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.QuestionAnswering) { QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult; KnowledgeBaseAnswers qnaAnswers = qnaTargetIntentResult.Result; Console.WriteLine("Answers: \n"); foreach (KnowledgeBaseAnswer answer in qnaAnswers.Answers) { Console.WriteLine($"Answer: {answer.Answer}"); Console.WriteLine($"Confidence Score: {answer.ConfidenceScore}"); Console.WriteLine($"Source: {answer.Source}"); Console.WriteLine(); } } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.QuestionAnswering)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("SushiMaking")); }
public void AnalyzeConversationWithOptions() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithOptions #if SNIPPET ConversationsProject conversationsProject = new ConversationsProject("Menu", "production"); AnalyzeConversationOptions options = new AnalyzeConversationOptions() { IsLoggingEnabled = true, Verbose = true, }; Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "We'll have 2 plates of seared salmon nigiri.", conversationsProject, options); #else AnalyzeConversationOptions options = new AnalyzeConversationOptions() { IsLoggingEnabled = true, Verbose = true, }; Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "We'll have 2 plates of seared salmon nigiri.", TestEnvironment.Project, options); #endif Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}"); #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(response.Value.Prediction.TopIntent, Is.EqualTo("Order")); }
public void AnalyzeConversationOrchestrationPredictionConversation() { ConversationAnalysisClient client = Client; Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "We'll have 2 plates of seared salmon nigiri.", TestEnvironment.OrchestrationProject); OrchestratorPrediction orchestratorPrediction = response.Value.Prediction as OrchestratorPrediction; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionConversation string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetKind == TargetKind.Conversation) { ConversationTargetIntentResult cluTargetIntentResult = targetIntentResult as ConversationTargetIntentResult; ConversationResult conversationResult = cluTargetIntentResult.Result; ConversationPrediction conversationPrediction = conversationResult.Prediction; if (!String.IsNullOrEmpty(conversationResult.DetectedLanguage)) { Console.WriteLine($"Detected Language: {conversationResult.DetectedLanguage}"); } Console.WriteLine($"Top Intent: {conversationResult.Prediction.TopIntent}"); Console.WriteLine($"Intents:"); foreach (ConversationIntent intent in conversationPrediction.Intents) { Console.WriteLine($"Intent Category: {intent.Category}"); Console.WriteLine($"Confidence Score: {intent.ConfidenceScore}"); Console.WriteLine(); } Console.WriteLine($"Entities:"); foreach (ConversationEntity entitiy in conversationPrediction.Entities) { Console.WriteLine($"Entity Text: {entitiy.Text}"); Console.WriteLine($"Entity Category: {entitiy.Category}"); Console.WriteLine($"Confidence Score: {entitiy.ConfidenceScore}"); Console.WriteLine($"Starting Position: {entitiy.Offset}"); Console.WriteLine($"Length: {entitiy.Length}"); Console.WriteLine(); } } #endregion Assert.That(targetIntentResult.TargetKind, Is.EqualTo(TargetKind.Conversation)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("SushiOrder")); }
public void AnalyzeConversationOrchestrationPredictionQuestionAnswering() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPrediction #if SNIPPET ConversationsProject orchestrationProject = new ConversationsProject("DomainOrchestrator", "production"); Response <AnalyzeConversationResult> response = client.AnalyzeConversation( "How are you?", orchestrationProject); #else Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "How are you?", TestEnvironment.OrchestrationProject); #endif CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; var orchestratorPrediction = customConversationalTaskResult.Result.Prediction as OrchestratorPrediction; #endregion #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA string respondingProjectName = orchestratorPrediction.TopIntent; TargetIntentResult targetIntentResult = orchestratorPrediction.Intents[respondingProjectName]; if (targetIntentResult.TargetProjectKind == TargetProjectKind.QuestionAnswering) { Console.WriteLine($"Top intent: {respondingProjectName}"); QuestionAnsweringTargetIntentResult qnaTargetIntentResult = targetIntentResult as QuestionAnsweringTargetIntentResult; BinaryData questionAnsweringResponse = qnaTargetIntentResult.Result; Console.WriteLine($"Qustion Answering Response: {questionAnsweringResponse.ToString()}"); } #endregion Assert.That(targetIntentResult.TargetProjectKind, Is.EqualTo(TargetProjectKind.QuestionAnswering)); Assert.That(orchestratorPrediction.TopIntent, Is.EqualTo("ChitChat-QnA")); }
public void AnalyzeConversationOrchestrationPredictionLuis() { ConversationAnalysisClient client = Client; var data = new { analysisInput = new { conversationItem = new { text = "Reserve a table for 2 at the Italian restaurant.", id = "1", participantId = "1", } }, parameters = new { projectName = TestEnvironment.OrchestrationProjectName, deploymentName = TestEnvironment.OrchestrationDeploymentName, // Use Utf16CodeUnit for strings in .NET. stringIndexType = "Utf16CodeUnit", }, kind = "Conversation", }; Response response = client.AnalyzeConversation(RequestContent.Create(data)); using JsonDocument result = JsonDocument.Parse(response.ContentStream); JsonElement conversationalTaskResult = result.RootElement; JsonElement orchestrationPrediction = conversationalTaskResult.GetProperty("result").GetProperty("prediction"); #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionLuis string respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString(); JsonElement targetIntentResult = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName); if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "Luis") { JsonElement luisResponse = targetIntentResult.GetProperty("result"); Console.WriteLine($"LUIS Response: {luisResponse.GetRawText()}"); } #endregion Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("Luis")); Assert.That(orchestrationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("RestaurantIntent")); }
public void AnalyzeConversationOrchestrationPredictionConversation() { ConversationAnalysisClient client = Client; var data = new { analysisInput = new { conversationItem = new { text = "Send an email to Carol about tomorrow's demo", id = "1", participantId = "1", } }, parameters = new { projectName = TestEnvironment.OrchestrationProjectName, deploymentName = TestEnvironment.OrchestrationDeploymentName, // Use Utf16CodeUnit for strings in .NET. stringIndexType = "Utf16CodeUnit", }, kind = "Conversation", }; Response response = client.AnalyzeConversation(RequestContent.Create(data)); using JsonDocument result = JsonDocument.Parse(response.ContentStream); JsonElement conversationalTaskResult = result.RootElement; JsonElement orchestrationPrediction = conversationalTaskResult.GetProperty("result").GetProperty("prediction"); #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionConversation string respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString(); JsonElement targetIntentResult = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName); if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "Conversation") { JsonElement conversationResult = targetIntentResult.GetProperty("result"); JsonElement conversationPrediction = conversationResult.GetProperty("prediction"); Console.WriteLine($"Top Intent: {conversationPrediction.GetProperty("topIntent").GetString()}"); Console.WriteLine($"Intents:"); foreach (JsonElement intent in conversationPrediction.GetProperty("intents").EnumerateArray()) { Console.WriteLine($"Intent Category: {intent.GetProperty("category").GetString()}"); Console.WriteLine($"Confidence: {intent.GetProperty("confidenceScore").GetSingle()}"); Console.WriteLine(); } Console.WriteLine($"Entities:"); foreach (JsonElement entity in conversationPrediction.GetProperty("entities").EnumerateArray()) { Console.WriteLine($"Entity Text: {entity.GetProperty("text").GetString()}"); Console.WriteLine($"Entity Category: {entity.GetProperty("category").GetString()}"); Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}"); Console.WriteLine($"Starting Position: {entity.GetProperty("offset").GetInt32()}"); Console.WriteLine($"Length: {entity.GetProperty("length").GetInt32()}"); Console.WriteLine(); if (!entity.TryGetProperty("resolutions", out JsonElement resolutions)) { continue; } foreach (JsonElement resolution in resolutions.EnumerateArray()) { if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution") { Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}"); Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}"); Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}"); Console.WriteLine(); } } } } #endregion Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("Conversation")); Assert.That(orchestrationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("EmailIntent")); }
public void AnalyzeConversationOrchestrationPredictionQuestionAnswering() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPrediction string projectName = "DomainOrchestrator"; string deploymentName = "production"; #if !SNIPPET projectName = TestEnvironment.OrchestrationProjectName; deploymentName = TestEnvironment.OrchestrationDeploymentName; #endif var data = new { analysisInput = new { conversationItem = new { text = "How are you?", id = "1", participantId = "1", } }, parameters = new { projectName, deploymentName, // Use Utf16CodeUnit for strings in .NET. stringIndexType = "Utf16CodeUnit", }, kind = "Conversation", }; Response response = client.AnalyzeConversation(RequestContent.Create(data)); using JsonDocument result = JsonDocument.Parse(response.ContentStream); JsonElement conversationalTaskResult = result.RootElement; JsonElement orchestrationPrediction = conversationalTaskResult.GetProperty("result").GetProperty("prediction"); #endregion #region Snippet:ConversationAnalysis_AnalyzeConversationOrchestrationPredictionQnA string respondingProjectName = orchestrationPrediction.GetProperty("topIntent").GetString(); JsonElement targetIntentResult = orchestrationPrediction.GetProperty("intents").GetProperty(respondingProjectName); if (targetIntentResult.GetProperty("targetProjectKind").GetString() == "QuestionAnswering") { Console.WriteLine($"Top intent: {respondingProjectName}"); JsonElement questionAnsweringResponse = targetIntentResult.GetProperty("result"); Console.WriteLine($"Question Answering Response:"); foreach (JsonElement answer in questionAnsweringResponse.GetProperty("answers").EnumerateArray()) { Console.WriteLine(answer.GetProperty("answer").GetString()); } } #endregion Assert.That(targetIntentResult.GetProperty("targetProjectKind").GetString(), Is.EqualTo("QuestionAnswering")); Assert.That(respondingProjectName, Is.EqualTo("ChitChat-QnA")); }
public void AnalyzeConversationWithLanguage() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguage TextConversationItem input = new TextConversationItem( participantId: "1", id: "1", text: "Tendremos 2 platos de nigiri de salmón braseado.") { Language = "es" }; AnalyzeConversationOptions options = new AnalyzeConversationOptions(input); #if SNIPPET ConversationsProject conversationsProject = new ConversationsProject("Menu", "production"); Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( textConversationItem, conversationsProject, options); #else Response <AnalyzeConversationTaskResult> response = client.AnalyzeConversation( "Tendremos 2 platos de nigiri de salmón braseado.", TestEnvironment.Project, options); #endif CustomConversationalTaskResult customConversationalTaskResult = response.Value as CustomConversationalTaskResult; ConversationPrediction conversationPrediction = customConversationalTaskResult.Result.Prediction as ConversationPrediction; Console.WriteLine($"Project Kind: {customConversationalTaskResult.Result.Prediction.ProjectKind}"); Console.WriteLine($"Top intent: {conversationPrediction.TopIntent}"); Console.WriteLine("Intents:"); foreach (ConversationIntent intent in conversationPrediction.Intents) { Console.WriteLine($"Category: {intent.Category}"); Console.WriteLine($"Confidence: {intent.Confidence}"); Console.WriteLine(); } Console.WriteLine("Entities:"); foreach (ConversationEntity entity in conversationPrediction.Entities) { Console.WriteLine($"Category: {entity.Category}"); Console.WriteLine($"Text: {entity.Text}"); Console.WriteLine($"Offset: {entity.Offset}"); Console.WriteLine($"Length: {entity.Length}"); Console.WriteLine($"Confidence: {entity.Confidence}"); Console.WriteLine(); foreach (BaseResolution resolution in entity.Resolutions) { if (resolution is DateTimeResolution dateTimeResolution) { Console.WriteLine($"Datetime Sub Kind: {dateTimeResolution.DateTimeSubKind}"); Console.WriteLine($"Timex: {dateTimeResolution.Timex}"); Console.WriteLine($"Value: {dateTimeResolution.Value}"); Console.WriteLine(); } } } #endregion Assert.That(response.GetRawResponse().Status, Is.EqualTo(200)); Assert.That(conversationPrediction.TopIntent, Is.EqualTo("Read")); }
public void AnalyzeConversationWithLanguage() { ConversationAnalysisClient client = Client; #region Snippet:ConversationAnalysis_AnalyzeConversationWithLanguage string projectName = "Menu"; string deploymentName = "production"; #if !SNIPPET projectName = TestEnvironment.ProjectName; deploymentName = TestEnvironment.DeploymentName; #endif var data = new { analysisInput = new { conversationItem = new { text = "Enviar un email a Carol acerca de la presentación de mañana", language = "es", id = "1", participantId = "1", } }, parameters = new { projectName, deploymentName, verbose = true, // Use Utf16CodeUnit for strings in .NET. stringIndexType = "Utf16CodeUnit", }, kind = "Conversation", }; Response response = client.AnalyzeConversation(RequestContent.Create(data)); #endregion using JsonDocument result = JsonDocument.Parse(response.ContentStream); JsonElement conversationalTaskResult = result.RootElement; JsonElement conversationPrediction = conversationalTaskResult.GetProperty("result").GetProperty("prediction"); Console.WriteLine($"Project Kind: {conversationPrediction.GetProperty("projectKind").GetString()}"); Console.WriteLine($"Top intent: {conversationPrediction.GetProperty("topIntent").GetString()}"); Console.WriteLine("Intents:"); foreach (JsonElement intent in conversationPrediction.GetProperty("intents").EnumerateArray()) { Console.WriteLine($"Category: {intent.GetProperty("category").GetString()}"); Console.WriteLine($"Confidence: {intent.GetProperty("confidenceScore").GetSingle()}"); Console.WriteLine(); } Console.WriteLine("Entities:"); foreach (JsonElement entity in conversationPrediction.GetProperty("entities").EnumerateArray()) { Console.WriteLine($"Category: {entity.GetProperty("category").GetString()}"); Console.WriteLine($"Text: {entity.GetProperty("text").GetString()}"); Console.WriteLine($"Offset: {entity.GetProperty("offset").GetInt32()}"); Console.WriteLine($"Length: {entity.GetProperty("length").GetInt32()}"); Console.WriteLine($"Confidence: {entity.GetProperty("confidenceScore").GetSingle()}"); Console.WriteLine(); if (!entity.TryGetProperty("resolutions", out JsonElement resolutions)) { continue; } foreach (JsonElement resolution in resolutions.EnumerateArray()) { if (resolution.GetProperty("resolutionKind").GetString() == "DateTimeResolution") { Console.WriteLine($"Datetime Sub Kind: {resolution.GetProperty("dateTimeSubKind").GetString()}"); Console.WriteLine($"Timex: {resolution.GetProperty("timex").GetString()}"); Console.WriteLine($"Value: {resolution.GetProperty("value").GetString()}"); Console.WriteLine(); } } } Assert.That(response.Status, Is.EqualTo(200)); Assert.That(conversationPrediction.GetProperty("topIntent").GetString(), Is.EqualTo("Send")); }