Exemplo n.º 1
0
        public AIResponse TextRequest(AIRequest request)
        {
            var preditor   = new BotPredictor();
            var doc        = preditor.Predict(agent, request).Result;
            var parameters = new Dictionary <String, Object>();

            doc.Sentences[0].Entities.ForEach(x => parameters.Add(x.Entity, x.Value));

            return(new AIResponse
            {
                Lang = request.Language,
                Timestamp = DateTime.UtcNow,
                SessionId = request.SessionId,
                Status = new AIResponseStatus(),
                Result = new AIResponseResult
                {
                    Score = doc.Sentences[0].Intent == null ? 0 : doc.Sentences[0].Intent.Confidence,
                    ResolvedQuery = doc.Sentences[0].Text,
                    Fulfillment = new AIResponseFulfillment {
                    },
                    Parameters = parameters,
                    Metadata = new AIResponseMetadata
                    {
                        IntentName = doc.Sentences[0].Intent?.Label
                    }
                }
            });
        }
Exemplo n.º 2
0
        public async Task <AiResponse> TextRequest(AiRequest request)
        {
            var preditor = new BotPredictor();
            var doc      = preditor.PredictOther(Agent, new AiRequest
            {
                AgentDir  = request.AgentDir,
                Model     = request.Model,
                SessionId = request.SessionId,
                Text      = request.Text
            }).Result;


            var parameters = new Dictionary <String, Object>();

            if (doc.Sentences[0].Entities == null)
            {
                doc.Sentences[0].Entities = new List <NlpEntity>();
            }
            doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value);

            return(new AiResponse
            {
                /*Lang = request.Language,
                 * Timestamp = DateTime.UtcNow,
                 * SessionId = request.SessionId,
                 * Status = new AIResponseStatus(),
                 * Result = new AIResponseResult
                 * {
                 *  Score = doc.Sentences[0].Intent == null ? 0 : doc.Sentences[0].Intent.Confidence,
                 *  ResolvedQuery = doc.Sentences[0].Text,
                 *  Fulfillment = new AIResponseFulfillment
                 *  {
                 *      Speech = agent.Intents.FirstOrDefault(tnt => tnt.Name == doc.Sentences[0].Intent?.Label)?.Responses?.Random()?.Messages?.Random()?.Speech
                 *  },
                 *  Parameters = parameters,
                 *  Entities = doc.Sentences[0].Entities,
                 *  Metadata = new AIResponseMetadata
                 *  {
                 *      IntentName = doc.Sentences[0].Intent?.Label
                 *  }
                 * }*/
            });
        }
Exemplo n.º 3
0
        public AIResponse TextRequest(AIRequest request)
        {
            var preditor = new BotPredictor();
            var doc      = preditor.Predict(agent, request).Result;

            var parameters = new Dictionary <String, Object>();

            if (doc.Sentences[0].Entities == null)
            {
                doc.Sentences[0].Entities = new List <NlpEntity>();
            }
            doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value);

            return(new AIResponse
            {
                Lang = request.Language,
                Timestamp = DateTime.UtcNow,
                SessionId = request.SessionId,
                Status = new AIResponseStatus(),
                Result = new AIResponseResult
                {
                    Score = doc.Sentences[0].Intent == null ? 0 : doc.Sentences[0].Intent.Confidence,
                    ResolvedQuery = doc.Sentences[0].Text,
                    Fulfillment = new AIResponseFulfillment
                    {
                        Speech = agent.Intents.FirstOrDefault(tnt => tnt.Name == doc.Sentences[0].Intent?.Label)?.Responses?.Random()?.Messages?.Random()?.Speech
                    },
                    Parameters = parameters,
                    Entities = doc.Sentences[0].Entities,
                    Metadata = new AIResponseMetadata
                    {
                        IntentName = doc.Sentences[0].Intent?.Label
                    }
                }
            });
        }