add multiple language config

This commit is contained in:
Oceania2018 2018-10-25 17:17:51 -05:00
parent 09282234e4
commit c5abe02f77
13 changed files with 164 additions and 16 deletions

View file

@ -75,7 +75,7 @@ If you feel that this project is helpful to you, please Star on the project, we
<ItemGroup>
<PackageReference Include="Colorful.Console" Version="1.2.9" />
<PackageReference Include="CSRedisCore" Version="3.0.5" />
<PackageReference Include="CSRedisCore" Version="3.0.13" />
<PackageReference Include="DotNetToolkit" Version="1.6.0" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.9.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.1.1" />

View file

@ -58,7 +58,7 @@ namespace BotSharp.Core.Engines
// pipe process
var pipelines = config.GetValue<String>($"{meta.BotEngine}:pipe")
var pipelines = config.GetValue<String>($"{meta.BotEngine}_{agent.Language}:pipe")
.Split(',')
.Select(x => x.Trim())
.ToList();
@ -66,7 +66,7 @@ namespace BotSharp.Core.Engines
for(int pipeIdx = 0; pipeIdx < pipelines.Count; pipeIdx++)
{
var pipe = TypeHelper.GetInstance(pipelines[pipeIdx], assemblies) as INlpPredict;
pipe.Configuration = config.GetSection(meta.BotEngine).GetSection(pipelines[pipeIdx]);
pipe.Configuration = config.GetSection($"{meta.BotEngine}_{agent.Language}").GetSection(pipelines[pipeIdx]);
pipe.Settings = settings;
var pipeModel = meta.Pipeline.FirstOrDefault(x => x.Name == pipelines[pipeIdx]);
await pipe.Predict(agent, data, pipeModel);

View file

@ -45,9 +45,9 @@ namespace BotSharp.Core.Engines
var assemblies = (string[])AppDomain.CurrentDomain.GetData("Assemblies");
var platform = config.GetSection($"platformModuleName").Value;
var engine = this.settings.BotEngine;
string providerName = config.GetSection($"{engine}:Provider").Value;
string providerName = config.GetSection($"{engine}_{agent.Language}:Provider").Value;
var provider = TypeHelper.GetInstance(providerName, assemblies) as INlpProvider;
provider.Configuration = config.GetSection(engine);
provider.Configuration = config.GetSection($"{engine}_{agent.Language}");
var pipeModel = new PipeModel
{

View file

@ -34,7 +34,14 @@ namespace BotSharp.Core.Modules
if (options.Modules.Count == 0)
{
options.Modules.Add(new ModuleOptions
{
Name = "DialogflowAi",
Type = "BotSharp.Platform.Dialogflow"
});
Console.WriteLine($"Platform emulator not found.", Color.Red);
Console.WriteLine($"Using default emulator: DialogflowAi, BotSharp.Platform.Dialogflow.");
}
this._modules = options.Modules

View file

@ -4,13 +4,16 @@ using BotSharp.Platform.Models;
using BotSharp.Platform.Models.AiRequest;
using BotSharp.Platform.Models.AiResponse;
using BotSharp.Platform.Models.Entities;
using BotSharp.Platform.Models.Intents;
using BotSharp.Platform.Models.MachineLearning;
using DotNetToolkit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@ -151,13 +154,53 @@ namespace BotSharp.Core
var preditor = new BotPredictor();
var doc = await preditor.Predict(Agent, request);
if (doc.Sentences[0].Entities == null)
{
doc.Sentences[0].Entities = new List<NlpEntity>();
}
var predictedIntent = doc.Sentences[0].Intent;
if (predictedIntent.Confidence < Agent.MlConfig.MinConfidence)
{
var data = new
{
token = "openbot",
info = request.Text
};
using (var client = new HttpClient())
{
var response = await client.PostAsync(
"https://api.ownthink.com/bot",
new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json"));
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<JObject>(content);
predictedIntent = new TextClassificationResult
{
Confidence = Agent.MlConfig.MinConfidence,
Classifier = "ownthink",
Label = "fallback"
};
Agent.Intents.Add(new Intent
{
Name = predictedIntent.Label,
Responses = new List<IntentResponse>
{
new IntentResponse
{
IntentName = predictedIntent.Label,
Messages = new List<IntentResponseMessage>
{
new IntentResponseMessage
{
Speech = "[\"" + result["text"] + "\"]",
Type = AIResponseMessageType.Text
}
}
}
}
});
}
}
var aiResponse = new AiResponse
{
ResolvedQuery = request.Text,

View file

@ -1,4 +1,6 @@
using System;
using BotSharp.Platform.Models.Intents;
using BotSharp.Platform.Models.MachineLearning;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
@ -10,6 +12,7 @@ namespace BotSharp.Platform.Models
public AgentBase()
{
CreatedDate = DateTime.UtcNow;
Intents = new List<Intent>();
}
/// <summary>
@ -42,5 +45,33 @@ namespace BotSharp.Platform.Models
public DateTime CreatedDate { get; set; }
public TrainingCorpus Corpus { get; set; }
public AgentMlConfig MlConfig { get; set; }
public List<AgentIntegration> Integrations { get; set; }
public Boolean Published { get; set; }
/// <summary>
/// Only access text/ audio rquest
/// </summary>
[StringLength(32)]
public String ClientAccessToken { get; set; }
/// <summary>
/// Developer can access more APIs
/// </summary>
[StringLength(32)]
public String DeveloperAccessToken { get; set; }
public List<Intent> Intents { get; set; }
public String Birthday
{
get
{
return CreatedDate.ToShortDateString();
}
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using BotSharp.Platform.Models.MachineLearning;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -39,5 +40,9 @@ namespace BotSharp.Platform.Models.Intents
[ForeignKey("IntentId")]
public List<IntentResponse> Responses { get; set; }
public AgentMlConfig MlConfig { get; set; }
public List<AgentIntegration> Integrations { get; set; }
}
}

View file

@ -8,6 +8,13 @@ namespace BotSharp.Platform.Models.Intents
{
public class IntentResponse
{
public IntentResponse()
{
Parameters = new List<IntentResponseParameter>();
Contexts = new List<IntentResponseContext>();
Messages = new List<IntentResponseMessage>();
}
/// <summary>
/// Guid
/// </summary>

View file

@ -84,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj" />
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
@ -91,6 +92,9 @@
<Content Update="Settings\app.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Settings\BotSharpNLU_zh-cn.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Settings\channels.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -100,7 +104,7 @@
<Content Update="Settings\auth.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Settings\BotSharpNLU.json">
<Content Update="Settings\BotSharpNLU_en.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Settings\db.json">

View file

@ -1,7 +1,5 @@
{
"botSharpNLU": {
"lang": "en",
"botSharpNLU_en": {
"provider": "BotSharpProvider",
"botSharpProvider": {

View file

@ -0,0 +1,27 @@
{
"botSharpNLU_zh-cn": {
"provider": "BotSharpProvider",
"botSharpProvider": {
},
"pipe": "BotSharpTokenizer, BotSharpTagger, BotSharpNER, BotSharpIntentClassifier",
"botSharpTokenizer": {
"tokenizer": "JiebaTokenizer"
},
"botSharpIntentClassifier": {
"classifer": "NaiveBayesClassifier",
"wordvecModel": "|App_Data|wordvec_enu.bin"
},
"botSharpTagger": {
"tagger": "JiebaTagger"
},
"botSharpNER": {
"template": "|App_Data|CRFLite/template.en"
}
}
}

View file

@ -22,6 +22,8 @@ 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", "{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
ARTICULATE|Any CPU = ARTICULATE|Any CPU
@ -206,6 +208,30 @@ Global
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Test|Any CPU.Build.0 = Release|Any CPU
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Test|x64.ActiveCfg = Release|Any CPU
{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Test|x64.Build.0 = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.ARTICULATE|Any CPU.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.ARTICULATE|Any CPU.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.ARTICULATE|x64.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.ARTICULATE|x64.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Debug|x64.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.RASA|Any CPU.ActiveCfg = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.RASA|Any CPU.Build.0 = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.RASA|x64.ActiveCfg = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.RASA|x64.Build.0 = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Release|Any CPU.Build.0 = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Release|x64.ActiveCfg = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Release|x64.Build.0 = Release|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Test|Any CPU.Build.0 = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Test|x64.ActiveCfg = Debug|Any CPU
{6A7E5DC1-3AE3-42C1-8F67-3131783646EB}.Test|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE