Пример #1
0
        public ActionResult <RasaResponse> Parse(RasaRequestModel request)
        {
            String clientAccessToken = Request.Headers["ClientAccessToken"];
            var    config            = new AIConfiguration(clientAccessToken, SupportedLanguage.English);

            config.SessionId = "rasa nlu";

            _platform.LoadAgent(clientAccessToken);

            var aIResponse = _platform.TextRequest(new AIRequest
            {
                Query = new String[] { request.Text }
            });

            return(new RasaResponse
            {
                Intent = new RasaResponseIntent
                {
                    Name = aIResponse.Result.Metadata.IntentName,
                    Confidence = aIResponse.Result.Score
                },
                Entities = new List <RasaResponseEntity>
                {
                },
                Text = request.Text
            });
        }
Пример #2
0
        public ActionResult <RasaResponse> Parse(RasaRequestModel request)
        {
            var config = new AIConfiguration("", SupportedLanguage.English);

            config.SessionId = "rasa nlu";

            string body = "";

            using (var reader = new StreamReader(Request.Body))
            {
                body = reader.ReadToEnd();
            }

            Console.WriteLine($"Got message from {Request.Host}: {body}", Color.Green);
            if (request.Project == null && !String.IsNullOrEmpty(body))
            {
                request = JsonConvert.DeserializeObject <RasaRequestModel>(body);
            }

            // Load agent
            var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", request.Project);

            if (String.IsNullOrEmpty(request.Model))
            {
                request.Model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
            }

            var modelPath = Path.Combine(projectPath, request.Model);

            var agent = _platform.LoadAgentFromFile(modelPath);

            var aIResponse = _platform.TextRequest(new AIRequest
            {
                AgentDir = projectPath,
                Model    = request.Model,
                Query    = new String[] { request.Text }
            });

            var rasaResponse = new RasaResponse
            {
                Intent = new RasaResponseIntent
                {
                    Name       = aIResponse.Result.Metadata.IntentName,
                    Confidence = aIResponse.Result.Score
                },
                Entities = aIResponse.Result.Entities.Select(x => new RasaResponseEntity
                {
                    Extractor = x.Extrator,
                    Start     = x.Start,
                    Entity    = x.Entity,
                    Value     = x.Value
                }).ToList(),
                Text          = request.Text,
                Model         = request.Model,
                Project       = agent.Name,
                IntentRanking = new List <RasaResponseIntent>
                {
                    new RasaResponseIntent
                    {
                        Name       = aIResponse.Result.Metadata.IntentName,
                        Confidence = aIResponse.Result.Score
                    }
                },
                Fullfillment = aIResponse.Result.Fulfillment
            };

            return(rasaResponse);
        }