public async Task ValidContentAssistantRequest_ShouldSucceedAsync()
        {
            //Arrange
            var minimumIntentScore = 0.5;
            var settings           = new ProcessContentAssistantSettings
            {
                Text           = "Test case",
                OutputVariable = "responseVariable",
                Score          = 55
            };

            Context.Flow.BuilderConfiguration.MinimumIntentScore = minimumIntentScore;

            var contentAssistantResource = new AnalysisRequest
            {
                Text  = settings.Text,
                Score = settings.Score.Value / 100
            };

            var contentResult = new ContentResult
            {
                Combinations = new ContentCombination[]
                {
                    new ContentCombination
                    {
                        Entities = new string[] { "teste" },
                        Intent   = "Teste"
                    },
                },
                Name   = "Name",
                Result = new Message
                {
                    Content = "Answer"
                }
            };

            var contentResultResponse = JsonConvert.SerializeObject(new ContentAssistantActionResponse
            {
                HasCombination = true,
                Entities       = contentResult.Combinations.First().Entities.ToList(),
                Intent         = contentResult.Combinations.First().Intent,
                Value          = contentResult.Result.Content.ToString()
            });


            //Act
            _artificialIntelligenceExtension.GetContentResultAsync(Arg.Is <AnalysisRequest>(
                                                                       ar =>
                                                                       ar.Score == contentAssistantResource.Score &&
                                                                       ar.Text == contentAssistantResource.Text),
                                                                   Arg.Any <CancellationToken>()).Returns(contentResult);

            await _processContentAssistantAction.ExecuteAsync(Context, JObject.FromObject(settings), CancellationToken);


            //Assert
            await Context.Received(1).SetVariableAsync(settings.OutputVariable, contentResultResponse, CancellationToken);
        }
Exemplo n.º 2
0
 private Lazy <Task <ContentResult> > CreateLazyGetContentResult() => new Lazy <Task <ContentResult> >(async() =>
 {
     var intentId = (await GetIntentAsync())?.Id;
     if (intentId == null)
     {
         return(null);
     }
     var entityValues = (await AnalyzedContent)?
                        .Entities?
                        .Select(entity => entity.Value)
                        .ToArray();
     try
     {
         return(await _artificialIntelligenceExtension.GetContentResultAsync(
                    new ContentCombination
         {
             Intent = intentId,
             Entities = entityValues
         },
                    _cancellationToken));
     }
     catch (LimeException)
     {
         return(null);
     }
 });
Exemplo n.º 3
0
        /// <summary>
        /// Get content result to a given input
        /// </summary>
        /// <param name="context">bot context</param>
        /// <param name="settings">ContentAssistant settings</param
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task ExecuteAsync(IContext context, ProcessContentAssistantSettings settings, CancellationToken cancellationToken)
        {
            var contentAssistantResource = new AnalysisRequest
            {
                Text  = settings.Text,
                Score = settings.Score.HasValue ? settings.Score.Value / Constants.PERCENTAGE_DENOMINATOR : context.Flow.BuilderConfiguration.MinimumIntentScore.Value
            } as Document;

            var contentResult = await _artificialIntelligenceExtension.GetContentResultAsync(
                contentAssistantResource,
                cancellationToken : cancellationToken);

            await SetContentResultAsync(context, settings.OutputVariable, contentResult, cancellationToken);
        }