From 4d3350de18a38c82caf163e16ac3d2543a8f3210 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Thu, 30 Aug 2018 21:59:36 -0500 Subject: [PATCH] Integrated with Articulate UI. --- BotSharp.Core/Engines/BotTrainer.cs | 2 +- BotSharp.RestApi/Rasa/ParseController.cs | 2 +- BotSharp.RestApi/Rasa/StatusController.cs | 1 + BotSharp.RestApi/Rasa/TrainController.cs | 31 +++++++++++++++++++++-- README.rst | 12 ++++++++- docs/installation.rst | 13 ++++++++-- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/BotSharp.Core/Engines/BotTrainer.cs b/BotSharp.Core/Engines/BotTrainer.cs index d3933a13..d5b35e5d 100644 --- a/BotSharp.Core/Engines/BotTrainer.cs +++ b/BotSharp.Core/Engines/BotTrainer.cs @@ -57,7 +57,7 @@ namespace BotSharp.Core.Engines var settings = new PipeSettings { - ProjectDir = Path.Combine(options.AgentDir), + ProjectDir = options.AgentDir, AlgorithmDir = Path.Combine(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms") }; diff --git a/BotSharp.RestApi/Rasa/ParseController.cs b/BotSharp.RestApi/Rasa/ParseController.cs index 35659bae..f6cdde8f 100644 --- a/BotSharp.RestApi/Rasa/ParseController.cs +++ b/BotSharp.RestApi/Rasa/ParseController.cs @@ -47,7 +47,7 @@ namespace BotSharp.RestApi.Rasa body = reader.ReadToEnd(); } - if(request ==null && !String.IsNullOrEmpty(body)) + if(request.Project ==null && !String.IsNullOrEmpty(body)) { request = JsonConvert.DeserializeObject(body); } diff --git a/BotSharp.RestApi/Rasa/StatusController.cs b/BotSharp.RestApi/Rasa/StatusController.cs index 67e5b034..ea49350c 100644 --- a/BotSharp.RestApi/Rasa/StatusController.cs +++ b/BotSharp.RestApi/Rasa/StatusController.cs @@ -36,6 +36,7 @@ namespace BotSharp.RestApi.Rasa { var status = new RasaStatusModel(); status.AvailableProjects = JObject.FromObject(new { }); + status.MaxTrainingProcesses = 1; // scan dir, get all models var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects"); diff --git a/BotSharp.RestApi/Rasa/TrainController.cs b/BotSharp.RestApi/Rasa/TrainController.cs index e7054375..058398c0 100644 --- a/BotSharp.RestApi/Rasa/TrainController.cs +++ b/BotSharp.RestApi/Rasa/TrainController.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace BotSharp.RestApi.Rasa @@ -48,8 +49,24 @@ namespace BotSharp.RestApi.Rasa body = reader.ReadToEnd(); } - var rasa_nlu_data = JsonConvert.DeserializeObject(body); + string lang = Regex.Match(body, @"language:.+")?.Value; + if (!String.IsNullOrEmpty(lang)) + { + lang = lang.Substring(11, 2); + } + string data = Regex.Match(body, @"data:([\s\S]*)")?.Value; + if (String.IsNullOrEmpty(data)) + { + data = body; + } + else + { + data = data.Substring(6); + } + + var rasa_nlu_data = JsonConvert.DeserializeObject(data); rasa_nlu_data.Model = model; + rasa_nlu_data.Project = project; var trainResult = await Train(rasa_nlu_data, project); return trainResult; @@ -73,6 +90,12 @@ namespace BotSharp.RestApi.Rasa } // 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 = "Rasa" + })); // in order to unify the process. var fileName = Path.Combine(modelPath, "corpus.json"); @@ -85,7 +108,11 @@ namespace BotSharp.RestApi.Rasa var agent = _platform.LoadAgentFromFile(modelPath); - var info = await trainer.Train(agent, new BotTrainOptions { Model = request.Model }); + var info = await trainer.Train(agent, new BotTrainOptions + { + AgentDir = projectPath, + Model = request.Model + }); return Ok(new { info = info.Model }); } diff --git a/README.rst b/README.rst index 748b0d03..d24283b5 100644 --- a/README.rst +++ b/README.rst @@ -22,12 +22,22 @@ Some Features * Support for multiple data request and response formats such as Rasa NLU and Dialogflow. * Integrate with popular social platforms like Facebook Messenger, Slack and Telegram. +Quick Started +------------- +You can use docker compose to run BotSharp quickly, make sure you've got `Docker`_ installed. +:: + + PS D:\BotSharp\> docker-compose -f docker-compose-articulateui.yml up + +Point your web browser at http://localhost:3000 and enjoy BotSharp with Articulate-UI. + + Documents --------- Read the docs: https://botsharp.readthedocs.io Github Wiki: https://github.com/Oceania2018/BotSharp/wiki - +.. _Docker: https://www.docker.com .. _Rasa UI: https://github.com/paschmann/rasa-ui .. _Articulate UI: https://spg.ai/projects/articulate diff --git a/docs/installation.rst b/docs/installation.rst index d9e309f0..f884604f 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -6,8 +6,17 @@ If you want to use the `RASA UI`_ as a front end, you can use the rasaui-specifi Docker Composer ^^^^^^^^^^^^^^^ -Integrate with `Rasa UI`_, you can use docker compose to run. -Make sure you've got `Docker`_ installed. +You can use docker compose to run, make sure you've got `Docker`_ installed. + +1. Integrate with `Articulate UI`_ + +:: + + PS D:\BotSharp\> docker-compose -f docker-compose-articulateui.yml up + +Point your web browser at http://localhost:3000 and enjoy Articulate-UI with BotSharp. + +2. Integrate with `Rasa UI`_, you can use docker compose to run. ::