Exemplo n.º 1
0
        public CustomConversationalTask(AnalyzeConversationOptions analysisInput, CustomConversationTaskParameters parameters)
        {
            if (analysisInput == null)
            {
                throw new ArgumentNullException(nameof(analysisInput));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            AnalysisInput = analysisInput;
            Parameters    = parameters;
            Kind          = AnalyzeConversationTaskKind.Conversation;
        }
Exemplo n.º 2
0
        /// <summary>Analyzes a conversational utterance.</summary>
        /// <param name="options">
        /// An <see cref="AnalyzeConversationOptions"/> containing the <see cref="AnalyzeConversationOptions.ProjectName"/>,
        /// <see cref="AnalyzeConversationOptions.DeploymentName"/>, <see cref="AnalyzeConversationOptions.Query"/>, and other options to analyze.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> to cancel the request.</param>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
        /// <exception cref="RequestFailedException">The service returned an error. The exception contains details of the service error.</exception>
        public virtual Response <AnalyzeConversationResult> AnalyzeConversation(AnalyzeConversationOptions options, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(options, nameof(options));

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(ConversationAnalysisClient)}.{nameof(AnalyzeConversation)}");
            scope.AddAttribute("projectName", options.ProjectName);
            scope.AddAttribute("deploymentName", options.DeploymentName);
            scope.Start();

            try
            {
                return(_analysisRestClient.AnalyzeConversation(options.ProjectName, options.DeploymentName, options, cancellationToken));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task <Response <AnalyzeConversationResult> > AnalyzeConversationAsync(string projectName, string deploymentName, AnalyzeConversationOptions conversationAnalysisOptions, CancellationToken cancellationToken = default)
        {
            if (projectName == null)
            {
                throw new ArgumentNullException(nameof(projectName));
            }
            if (deploymentName == null)
            {
                throw new ArgumentNullException(nameof(deploymentName));
            }
            if (conversationAnalysisOptions == null)
            {
                throw new ArgumentNullException(nameof(conversationAnalysisOptions));
            }

            using var message = CreateAnalyzeConversationRequest(projectName, deploymentName, conversationAnalysisOptions);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                AnalyzeConversationResult value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = AnalyzeConversationResult.DeserializeAnalyzeConversationResult(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
Exemplo n.º 4
0
        internal HttpMessage CreateAnalyzeConversationRequest(string projectName, string deploymentName, AnalyzeConversationOptions conversationAnalysisOptions)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Post;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendRaw("/language", false);
            uri.AppendPath("/:analyze-conversations", false);
            uri.AppendQuery("projectName", projectName, true);
            uri.AppendQuery("deploymentName", deploymentName, true);
            uri.AppendQuery("api-version", apiVersion, true);
            request.Uri = uri;
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(conversationAnalysisOptions);
            request.Content = content;
            return(message);
        }
Exemplo n.º 5
0
        /// <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="ArgumentNullException"><paramref name="project"/> or <paramref name="utterance"/> 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 <AnalyzeConversationResult> > AnalyzeConversationAsync(string utterance, ConversationsProject project, AnalyzeConversationOptions options = null, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(project, nameof(project));
            Argument.AssertNotNull(utterance, nameof(utterance));

            options           = options ?? new();
            options.Utterance = utterance;

            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(project.ProjectName, project.DeploymentName, options, 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));
                }
        /// <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;
            }
        }