From 32f65ae07a46527b389866709c53864345f852d8 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Thu, 4 Oct 2018 16:18:46 -0500 Subject: [PATCH] finish training for rasa nlu. --- BotSharp.Core/PlatformBuilderBase.cs | 22 +++++++++++++++++++ .../IPlatformBuilder.cs | 2 +- BotSharp.WebHost/BotSharp.WebHost.csproj | 4 ---- BotSharp.WebHost/Startup.cs | 2 +- BotSharp.sln | 20 ----------------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/BotSharp.Core/PlatformBuilderBase.cs b/BotSharp.Core/PlatformBuilderBase.cs index 56618ee8..802d8820 100644 --- a/BotSharp.Core/PlatformBuilderBase.cs +++ b/BotSharp.Core/PlatformBuilderBase.cs @@ -1,6 +1,7 @@ using BotSharp.Core.Engines; using BotSharp.Platform.Abstraction; using BotSharp.Platform.Models; +using BotSharp.Platform.Models.MachineLearning; using DotNetToolkit; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; @@ -9,6 +10,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace BotSharp.Core { @@ -70,6 +72,26 @@ namespace BotSharp.Core return Storage.FetchByName(agentName); } + public virtual async Task Train(TAgent agent, TrainingCorpus corpus, BotTrainOptions options) + { + if (String.IsNullOrEmpty(options.AgentDir)) + { + options.AgentDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id); + } + + if (String.IsNullOrEmpty(options.Model)) + { + options.Model = "model_" + DateTime.UtcNow.ToString("yyyyMMdd"); + } + + var trainer = new BotTrainer(); + agent.Corpus = corpus; + + var info = await trainer.Train(agent, options); + + return info; + } + public virtual bool SaveAgent(TAgent agent) { GetStorage(); diff --git a/BotSharp.Platform.Abstraction/IPlatformBuilder.cs b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs index c04b98be..4e3a470b 100644 --- a/BotSharp.Platform.Abstraction/IPlatformBuilder.cs +++ b/BotSharp.Platform.Abstraction/IPlatformBuilder.cs @@ -48,7 +48,7 @@ namespace BotSharp.Platform.Abstraction /// bool SaveAgent(TAgent agent); - Task Train(TAgent agent, TrainingCorpus corpus); + Task Train(TAgent agent, TrainingCorpus corpus, BotTrainOptions options); AiResponse TextRequest(AiRequest request); } diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index 96920fdc..68c7fd5b 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -74,10 +74,6 @@ - - - - PreserveNewest diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index 85fc4940..77541628 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -142,7 +142,7 @@ namespace BotSharp.WebHost }; Console.WriteLine(); - Console.WriteLineFormatted("Platform Emulator: {0} powered by {1} engine.", Color.White, settings); + Console.WriteLineFormatted("{0} platform emulator powered by {1} engine.", Color.White, settings); Console.WriteLine(); } } diff --git a/BotSharp.sln b/BotSharp.sln index d51a8768..ed4e217b 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -22,10 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Abstracti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models", "BotSharp.Platform.Models\BotSharp.Platform.Models.csproj", "{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Dialogflow", "..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj", "{B865F070-9693-47C6-B901-40121F659C6F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "..\botsharp-rasa\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj", "{87C265EF-3A8A-4290-8AD2-33504168F653}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -90,22 +86,6 @@ Global {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.Build.0 = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.ActiveCfg = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.Build.0 = Release|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Debug|x64.ActiveCfg = Debug|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Debug|x64.Build.0 = Debug|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Release|Any CPU.Build.0 = Release|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Release|x64.ActiveCfg = Release|Any CPU - {B865F070-9693-47C6-B901-40121F659C6F}.Release|x64.Build.0 = Release|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Debug|Any CPU.Build.0 = Debug|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Debug|x64.ActiveCfg = Debug|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Debug|x64.Build.0 = Debug|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Release|Any CPU.ActiveCfg = Release|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Release|Any CPU.Build.0 = Release|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Release|x64.ActiveCfg = Release|Any CPU - {87C265EF-3A8A-4290-8AD2-33504168F653}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE