abstract engine object.

This commit is contained in:
Oceania2018 2018-10-03 09:13:32 -05:00
parent 979fbcfd7d
commit b929aa272e
23 changed files with 41 additions and 153 deletions

View file

@ -1,5 +1,6 @@
using Bigtree.Algorithm.Extensions;
using BotSharp.Core.Engines;
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
@ -14,7 +15,7 @@ namespace BotSharp.Core.UnitTest.Performance
public class Spotify : TestEssential
{
//private List<Tuple<AIRequest, string>> Samples;
private IBotPlatform _platform;
private IBotEngine _platform;
[TestMethod]
public void IntentAccuracy()

View file

@ -89,8 +89,4 @@ If you feel that this project is helpful to you, please Star on the project, we
<ProjectReference Include="..\BotSharp.Platform.Models\BotSharp.Platform.Models.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Agents\" />
</ItemGroup>
</Project>

View file

@ -2,17 +2,17 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
namespace BotSharp.Core.Engines.BotSharp
{
public class BotSharpAi : BotEngineBase, IBotPlatform
public class BotSharpAi : BotEngineBase, IBotEngine
{
public override async Task Train(BotTrainOptions options)
{
/*agent.Corpus = GetIntentExpressions(agent);
var trainer = new BotTrainer(agent.Id, dc);
await trainer.Train(agent, options);*/
await trainer.Train(agent, options);
}
}
}

View file

@ -39,10 +39,10 @@ namespace BotSharp.Core.Engines
// Get NLP Provider
var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration");
var assemblies = (string[])AppDomain.CurrentDomain.GetData("Assemblies");
var platform = config.GetSection($"BotPlatform").Value;
string providerName = config.GetSection($"{platform}:Provider").Value;
var engine = config.GetSection($"BotEngine").Value;
string providerName = config.GetSection($"{engine}:Provider").Value;
var provider = TypeHelper.GetInstance(providerName, assemblies) as INlpProvider;
provider.Configuration = config.GetSection(platform);
provider.Configuration = config.GetSection(engine);
var pipeModel = new PipeModel
{
@ -73,7 +73,7 @@ namespace BotSharp.Core.Engines
var meta = new ModelMetaData
{
Platform = platform,
Platform = engine,
Language = agent.Language,
TrainingDate = DateTime.UtcNow,
Version = config.GetValue<String>($"Version"),

View file

@ -1,15 +1,17 @@
using BotSharp.Platform.Models;
using BotSharp.Platform.Models.AiRequest;
using BotSharp.Platform.Models.AiResponse;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Core.Engines
namespace BotSharp.Platform.Abstraction
{
public interface IBotPlatform
/// <summary>
/// BotEngine is the NLU of bot platform
/// </summary>
public interface IBotEngine
{
AiResponse TextRequest(AiRequest request);

View file

@ -74,10 +74,13 @@
<ItemGroup>
<Compile Remove="Authentication\**" />
<Compile Remove="Rasa\**" />
<Compile Remove="Voice\**" />
<EmbeddedResource Remove="Authentication\**" />
<EmbeddedResource Remove="Rasa\**" />
<EmbeddedResource Remove="Voice\**" />
<None Remove="Authentication\**" />
<None Remove="Rasa\**" />
<None Remove="Voice\**" />
</ItemGroup>
<ItemGroup>
@ -91,7 +94,6 @@
<ItemGroup>
<ProjectReference Include="..\..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj" />
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
<ProjectReference Include="..\BotSharp.Voice\BotSharp.Voice.csproj" />
</ItemGroup>
</Project>

View file

@ -14,11 +14,5 @@
PSID
</summary>
</member>
<member name="M:BotSharp.RestApi.Ontology.EntityController.#ctor(BotSharp.Core.Engines.IBotPlatform)">
<summary>
Initialize dialog controller and get a platform instance
</summary>
<param name="platform"></param>
</member>
</members>
</doc>

View file

@ -1,23 +0,0 @@
using BotSharp.Core.Engines;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.RestApi.Ontology
{
[Route("v1/[controller]/[action]")]
public class EntityController : ControllerBase
{
private readonly IBotPlatform _platform;
/// <summary>
/// Initialize dialog controller and get a platform instance
/// </summary>
/// <param name="platform"></param>
public EntityController(IBotPlatform platform)
{
_platform = platform;
}
}
}

View file

@ -14,8 +14,4 @@
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BotSharp.Voice\BotSharp.Voice.csproj" />
</ItemGroup>
</Project>

View file

@ -64,6 +64,7 @@
<ItemGroup>
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
<ProjectReference Include="..\BotSharp.Platform.Abstraction\BotSharp.Platform.Abstraction.csproj" />
<ProjectReference Include="..\BotSharp.RestApi\BotSharp.RestApi.csproj" />
</ItemGroup>

View file

@ -1,6 +1,6 @@
{
"Assemblies": "BotSharp.Core",
"BotPlatform": "BotSharpAi",
"BotEngine": "BotSharpAi",
"Version": "0.1.0",
"MachineLearning": {

View file

@ -1,4 +1,5 @@
using BotSharp.Core.Engines;
using BotSharp.Platform.Abstraction;
using DotNetToolkit;
using DotNetToolkit.JwtHelper;
using EntityFrameworkCore.BootKit;
@ -62,14 +63,14 @@ namespace BotSharp.WebHost
});
// register platform dependency
services.AddTransient<IBotPlatform>((provider) =>
services.AddTransient<IBotEngine>((provider) =>
{
var assemblies = (String[])AppDomain.CurrentDomain.GetData("Assemblies");
var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration");
var implements = TypeHelper.GetClassesWithInterface<IBotPlatform>(assemblies);
var implements = TypeHelper.GetClassesWithInterface<IBotEngine>(assemblies);
string platform = config.GetValue<String>("BotPlatform");
var implement = implements.FirstOrDefault(x => x.Name.Split('.').Last() == platform);
var instance = (IBotPlatform)Activator.CreateInstance(implement);
var instance = (IBotEngine)Activator.CreateInstance(implement);
return instance;
});
@ -92,14 +93,6 @@ namespace BotSharp.WebHost
{
var info = Configuration.GetSection("Swagger").Get<Info>();
#if DIALOGFLOW
info.Title += " (DIALOGFLOW)";
#elif RASA
info.Title += " (RASA)";
#elif ARTICULATE
info.Title += " (ARTICULATE)";
#endif
c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Post, SubmitMethod.Put, SubmitMethod.Patch, SubmitMethod.Delete);
c.ShowExtensions();
c.SwaggerEndpoint(Configuration.GetValue<String>("Swagger:Endpoint"), info.Title);

View file

@ -10,17 +10,12 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.WebHost", "BotSharp.WebHost\BotSharp.WebHost.csproj", "{03DCA427-327A-4FC9-9A2F-57D17F16708C}"
ProjectSection(ProjectDependencies) = postProject
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22} = {C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}
{184F8B93-68C2-4849-9625-4023C4360990} = {184F8B93-68C2-4849-9625-4023C4360990}
{62F08F9F-16C2-4754-90B0-B604DC18AE23} = {62F08F9F-16C2-4754-90B0-B604DC18AE23}
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72} = {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.NLP", "BotSharp.NLP\BotSharp.NLP.csproj", "{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Voice", "BotSharp.Voice\BotSharp.Voice.csproj", "{184F8B93-68C2-4849-9625-4023C4360990}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Voice.UnitTest", "BotSharp.Voice.UnitTest\BotSharp.Voice.UnitTest.csproj", "{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.NLP.UnitTest", "BotSharp.NLP.UnitTest\BotSharp.NLP.UnitTest.csproj", "{8A1F6277-FFCB-4CCD-B798-876D8BE525A9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Core.UnitTest", "BotSharp.Core.UnitTest\BotSharp.Core.UnitTest.csproj", "{30F80E7D-951A-4E8F-9C3C-2C866528EABD}"
@ -31,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models",
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}") = "Platform.Articulate", "Platform.Articulate\Platform.Articulate.csproj", "{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -71,22 +68,6 @@ Global
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Release|Any CPU.Build.0 = Release|Any CPU
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Release|x64.ActiveCfg = Release|x64
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Release|x64.Build.0 = Release|x64
{184F8B93-68C2-4849-9625-4023C4360990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Debug|x64.ActiveCfg = Debug|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Debug|x64.Build.0 = Debug|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Release|Any CPU.Build.0 = Release|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Release|x64.ActiveCfg = Release|Any CPU
{184F8B93-68C2-4849-9625-4023C4360990}.Release|x64.Build.0 = Release|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Debug|x64.ActiveCfg = Debug|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Debug|x64.Build.0 = Debug|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Release|Any CPU.Build.0 = Release|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Release|x64.ActiveCfg = Release|Any CPU
{3F0CAAD4-564B-43FF-90BF-26AC47C9D677}.Release|x64.Build.0 = Release|Any CPU
{8A1F6277-FFCB-4CCD-B798-876D8BE525A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A1F6277-FFCB-4CCD-B798-876D8BE525A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A1F6277-FFCB-4CCD-B798-876D8BE525A9}.Debug|x64.ActiveCfg = Debug|x64
@ -127,6 +108,14 @@ Global
{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
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Debug|x64.ActiveCfg = Debug|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Debug|x64.Build.0 = Debug|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Release|Any CPU.Build.0 = Release|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Release|x64.ActiveCfg = Release|Any CPU
{9B7D2034-55A0-4539-A7A5-FAA7117E16A6}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -136,62 +136,18 @@ namespace Platform.Articulate
public async Task<bool> Train(TAgent agent, TrainingCorpus corpus)
{
string agentDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id);
// save corpus to agent dir
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id);
var model = "model_" + DateTime.UtcNow.ToString("yyyyMMdd");
var modelPath = Path.Combine(projectPath, model);
var trainer = new BotTrainer();
var parsedAgent = agent.ToObject<AgentModel>();
var intents = new List<TrainingIntentExpression<TrainingIntentExpressionPart>>();
foreach (DomainModel domain in (agent as AgentModel).Domains)
{
foreach (IntentModel intent in domain.Intents)
{
foreach (IntentExampleModel example in intent.Examples)
{
var parsedIntent = new TrainingIntentExpression<TrainingIntentExpressionPart>
{
Intent = intent.IntentName,
Text = example.UserSays,
Entities = example.Entities.Select(x => new TrainingIntentExpressionPart
{
Entity = x.Entity,
Start = x.Start,
Value = x.Value
}).ToList()
};
intents.Add(parsedIntent);
}
}
}
parsedAgent.Corpus = new TrainingCorpus
{
Entities = (agent as AgentModel).Entities.Select(x => new TrainingEntity
{
Entity = x.EntityName,
Values = x.Examples.Select(y => new TrainingEntitySynonym
{
Value = y.Value,
Synonyms = y.Synonyms
}).ToList()
}).ToList(),
UserSays = intents
};
agent.Corpus = corpus;
var trainOptions = new BotTrainOptions
{
AgentDir = projectPath,
AgentDir = agentDir,
Model = model
};
var info = await trainer.Train(parsedAgent, trainOptions);
var info = await trainer.Train(agent, trainOptions);
return true;
}

View file

@ -16,19 +16,17 @@ using System.Text.RegularExpressions;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class AgentController : ControllerBase
{
private readonly IConfiguration configuration;
private readonly IBotPlatform _platform;
private readonly IBotEngine _platform;
private ArticulateAi<AgentModel> builder;
/// <summary>
/// Initialize agent controller and get a platform instance
/// </summary>
/// <param name="platform"></param>
public AgentController(IBotPlatform platform, IConfiguration configuration)
public AgentController(IBotEngine platform, IConfiguration configuration)
{
_platform = platform;
builder = new ArticulateAi<AgentModel>();
@ -79,5 +77,4 @@ namespace Platform.Articulate.Controllers
return agent;
}
}
#endif
}

View file

@ -15,7 +15,6 @@ using System.Text.RegularExpressions;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class DomainController : ControllerBase
{
@ -68,5 +67,4 @@ namespace Platform.Articulate.Controllers
return new DomainPageViewModel { Domains = agent.Domains, Total = agent.Domains.Count };
}
}
#endif
}

View file

@ -13,7 +13,6 @@ using System.Text;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class EntityController : ControllerBase
{
@ -67,5 +66,4 @@ namespace Platform.Articulate.Controllers
return entity;
}
}
#endif
}

View file

@ -14,7 +14,6 @@ using System.Text;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class IntentController : ControllerBase
{
@ -127,5 +126,4 @@ namespace Platform.Articulate.Controllers
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
}
}
#endif
}

View file

@ -14,7 +14,6 @@ using Console = Colorful.Console;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class ParseControllercs : ControllerBase
{
@ -45,5 +44,4 @@ namespace Platform.Articulate.Controllers
return Ok(response);
}
}
#endif
}

View file

@ -12,7 +12,6 @@ using System.Text;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class ScenarioController : ControllerBase
{
@ -63,5 +62,4 @@ namespace Platform.Articulate.Controllers
return scenario;
}
}
#endif
}

View file

@ -9,12 +9,9 @@ using System.Text;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class SettingsController : ControllerBase
{
private readonly IConfiguration configuration;
[HttpGet]
public SettingsModel GetSettings()
{
@ -51,5 +48,4 @@ namespace Platform.Articulate.Controllers
return settings;
}
}
#endif
}

View file

@ -9,7 +9,6 @@ using System.Threading.Tasks;
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class TrainController : ControllerBase
{
@ -38,5 +37,4 @@ namespace Platform.Articulate.Controllers
return agent;
}
}
#endif
}

View file

@ -6,7 +6,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;DEBUG;RASA</DefineConstants>
<DefineConstants>TRACE</DefineConstants>
<Optimize>false</Optimize>
</PropertyGroup>
@ -16,8 +16,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>bin\DIALOGFLOW</OutputPath>
<DefineConstants>TRACE;DEBUG;DIALOGFLOW</DefineConstants>
<OutputPath></OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">