private async Task <ActionResult <String> > Train([FromBody] RasaTrainRequestModel request, [FromQuery] string project) { var trainer = new BotTrainer(); if (String.IsNullOrEmpty(request.Project)) { request.Project = project; } // save corpus to agent dir var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", project); var modelPath = Path.Combine(projectPath, request.Model); if (!Directory.Exists(modelPath)) { Directory.CreateDirectory(modelPath); } // Save raw data to file, then parse it to Agent instance. var metaFileName = Path.Combine(modelPath, "meta.json"); System.IO.File.WriteAllText(metaFileName, JsonConvert.SerializeObject(new AgentImportHeader { Name = project, Platform = PlatformType.Rasa })); // in order to unify the process. var fileName = Path.Combine(modelPath, "corpus.json"); System.IO.File.WriteAllText(fileName, JsonConvert.SerializeObject(request, new JsonSerializerSettings { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() })); var agent = _platform.LoadAgentFromFile(modelPath); var info = await trainer.Train(agent, new BotTrainOptions { AgentDir = projectPath, Model = request.Model }); return(Ok(new { info = info.Model })); }
public async Task <ActionResult <String> > Train([FromBody] RasaTrainRequestModel request, [FromQuery] string project) { var trainer = new BotTrainer(); if (String.IsNullOrEmpty(request.Project)) { request.Project = project; } // save corpus to agent dir var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects"); var dataPath = Path.Combine(projectPath, project); var agentPath = Path.Combine(dataPath, "Temp"); if (!Directory.Exists(agentPath)) { Directory.CreateDirectory(agentPath); } var fileName = Path.Combine(agentPath, "corpus.json"); System.IO.File.WriteAllText(fileName, JsonConvert.SerializeObject(request.Corpus, new JsonSerializerSettings { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() })); var bot = new RasaAi(); var agent = bot.LoadAgentFromFile <AgentImporterInRasa>(agentPath, new AgentImportHeader { Id = request.Project, Name = project }); var info = await trainer.Train(agent); return(Ok(new { info = info.Model })); }