/// <summary>Analyzes a conversational utterance.</summary> /// <param name="utterance">The conversation utterance to be analyzed.</param> /// <param name="project">The <see cref="ConversationsProject"/> used for conversation analysis.</param> /// <param name="options">Optional <see cref="AnalyzeConversationOptions"/> with additional query options.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> to cancel the request.</param> /// <exception cref="ArgumentException"><paramref name="utterance"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="utterance"/> or <paramref name="project"/> or is null.</exception> /// <exception cref="RequestFailedException">The service returned an error. The exception contains details of the service error.</exception> public virtual async Task <Response <AnalyzeConversationTaskResult> > AnalyzeConversationAsync(string utterance, ConversationsProject project, AnalyzeConversationOptions options = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(utterance, nameof(utterance)); Argument.AssertNotNull(project, nameof(project)); CustomConversationTaskParameters customConversationTaskParameters = new CustomConversationTaskParameters(project.ProjectName, project.DeploymentName) { Verbose = options?.Verbose, }; TextConversationItem textConversationItem = new TextConversationItem("1", "1", utterance); options ??= new AnalyzeConversationOptions(textConversationItem); CustomConversationalTask customConversationalTask = new CustomConversationalTask(options, customConversationTaskParameters); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(ConversationAnalysisClient)}.{nameof(AnalyzeConversation)}"); scope.AddAttribute("projectName", project.ProjectName); scope.AddAttribute("deploymentName", project.DeploymentName); scope.Start(); try { return(await _analysisRestClient.AnalyzeConversationAsync(customConversationalTask, cancellationToken).ConfigureAwait(false)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary>Analyzes a conversational utterance.</summary> /// <param name="utterance">The conversation utterance to be analyzed.</param> /// <param name="project">The <see cref="ConversationsProject"/> used for conversation analysis.</param> /// <param name="options">Optional <see cref="AnalyzeConversationOptions"/> with additional query options.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> to cancel the request.</param> /// <exception cref="ArgumentException"><paramref name="utterance"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="utterance"/> or <paramref name="project"/> or is null.</exception> /// <exception cref="RequestFailedException">The service returned an error. The exception contains details of the service error.</exception> public virtual async Task <Response <AnalyzeConversationTaskResult> > AnalyzeConversationAsync(string utterance, ConversationsProject project, AnalyzeConversationOptions options = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(utterance, nameof(utterance)); Argument.AssertNotNull(project, nameof(project)); CustomConversationTaskParameters customConversationTaskParameters = new CustomConversationTaskParameters(project.ProjectName, project.DeploymentName) { Verbose = options?.Verbose, }; TextConversationItem textConversationItem = new TextConversationItem("1", "1", utterance); options ??= new AnalyzeConversationOptions(textConversationItem); CustomConversationalTask customConversationalTask = new CustomConversationalTask(options, customConversationTaskParameters); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(ConversationAnalysisClient)}.{nameof(AnalyzeConversation)}External"); scope.AddAttribute("projectName", project.ProjectName); scope.AddAttribute("deploymentName", project.DeploymentName); scope.Start(); try { Utf8JsonRequestContent content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(customConversationalTask); Response response = await AnalyzeConversationAsync(content, new RequestContext() { CancellationToken = cancellationToken }).ConfigureAwait(false); switch (response.Status) { case 200: { AnalyzeConversationTaskResult value = default; using JsonDocument document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = AnalyzeConversationTaskResult.DeserializeAnalyzeConversationTaskResult(document.RootElement); return(Response.FromValue(value, response)); }