add agentDir.
This commit is contained in:
parent
8a12e2e825
commit
0f6a101de2
|
|
@ -51,7 +51,7 @@ namespace BotSharp.Core.UnitTest
|
||||||
|
|
||||||
agents.ForEach(agentHeader => {
|
agents.ForEach(agentHeader => {
|
||||||
var bot = new BotSharpAi();
|
var bot = new BotSharpAi();
|
||||||
bot.RestoreAgent<AgentImporterInDialogflow>();
|
bot.RestoreAgent<AgentImporterInDialogflow>(dataPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,9 @@ namespace BotSharp.Core.Engines
|
||||||
|
|
||||||
protected Agent agent { get; set; }
|
protected Agent agent { get; set; }
|
||||||
|
|
||||||
public String DbInitializerPath { get; private set; }
|
|
||||||
|
|
||||||
public BotEngineBase()
|
public BotEngineBase()
|
||||||
{
|
{
|
||||||
dc = new DefaultDataContextLoader().GetDefaultDc();
|
dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||||
string dataPath = AppDomain.CurrentDomain.GetData("DataPath").ToString();
|
|
||||||
DbInitializerPath = Path.Combine(dataPath, $"DbInitializer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AIResponse TextRequest(AIRequest request)
|
public AIResponse TextRequest(AIRequest request)
|
||||||
|
|
@ -89,10 +85,8 @@ namespace BotSharp.Core.Engines
|
||||||
/// <param name="importer"></param>
|
/// <param name="importer"></param>
|
||||||
/// <param name="dataDir"></param>
|
/// <param name="dataDir"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool RestoreAgent<TAgentImporter>() where TAgentImporter : IAgentImporter, new()
|
public bool RestoreAgent<TAgentImporter>(string dataDir) where TAgentImporter : IAgentImporter, new()
|
||||||
{
|
{
|
||||||
string dataDir = Path.Combine(DbInitializerPath, "Agents");
|
|
||||||
|
|
||||||
int row = dc.DbTran(() => {
|
int row = dc.DbTran(() => {
|
||||||
LoadAgentFromFile(dataDir);
|
LoadAgentFromFile(dataDir);
|
||||||
SaveAgent();
|
SaveAgent();
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ namespace BotSharp.Core.Engines
|
||||||
public async Task<NlpDoc> Predict(Agent agent, AIRequest request)
|
public async Task<NlpDoc> Predict(Agent agent, AIRequest request)
|
||||||
{
|
{
|
||||||
// load model
|
// load model
|
||||||
var dir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id, request.Model);
|
var dir = Path.Combine(request.AgentDir, request.Model);
|
||||||
Console.WriteLine($"Load model from {dir}");
|
Console.WriteLine($"Load model from {dir}");
|
||||||
var metaJson = File.ReadAllText(Path.Combine(dir, "metadata.json"));
|
var metaJson = File.ReadAllText(Path.Combine(dir, "model-meta.json"));
|
||||||
var meta = JsonConvert.DeserializeObject<ModelMetaData>(metaJson);
|
var meta = JsonConvert.DeserializeObject<ModelMetaData>(metaJson);
|
||||||
|
|
||||||
// Get NLP Provider
|
// Get NLP Provider
|
||||||
|
|
@ -50,7 +50,7 @@ namespace BotSharp.Core.Engines
|
||||||
var settings = new PipeSettings
|
var settings = new PipeSettings
|
||||||
{
|
{
|
||||||
ModelDir = dir,
|
ModelDir = dir,
|
||||||
ProjectDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id),
|
ProjectDir = request.AgentDir,
|
||||||
AlgorithmDir = Path.Combine(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms")
|
AlgorithmDir = Path.Combine(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,11 @@ namespace BotSharp.Core.Engines
|
||||||
|
|
||||||
var settings = new PipeSettings
|
var settings = new PipeSettings
|
||||||
{
|
{
|
||||||
ProjectDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id),
|
ProjectDir = Path.Combine(options.AgentDir),
|
||||||
AlgorithmDir = Path.Combine(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms")
|
AlgorithmDir = Path.Combine(AppDomain.CurrentDomain.GetData("ContentRootPath").ToString(), "Algorithms")
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.ModelDir = Path.Combine(settings.ProjectDir, String.IsNullOrEmpty(options.Model) ? "model" + DateTime.UtcNow.ToString("MMddyyyyHHmm") : options.Model);
|
settings.ModelDir = Path.Combine(options.AgentDir, options.Model);
|
||||||
|
|
||||||
if (!Directory.Exists(settings.ProjectDir))
|
if (!Directory.Exists(settings.ProjectDir))
|
||||||
{
|
{
|
||||||
|
|
@ -117,7 +117,7 @@ namespace BotSharp.Core.Engines
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||||
});
|
});
|
||||||
File.WriteAllText(Path.Combine(settings.ModelDir, "metadata.json"), metaJson);
|
File.WriteAllText(Path.Combine(settings.ModelDir, "model-meta.json"), metaJson);
|
||||||
|
|
||||||
Console.WriteLine(metaJson);
|
Console.WriteLine(metaJson);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ namespace BotSharp.Core.Engines.Classifiers
|
||||||
|
|
||||||
doc.Sentences[0].Intent = new TextClassificationResult
|
doc.Sentences[0].Intent = new TextClassificationResult
|
||||||
{
|
{
|
||||||
|
Classifier = "FasttextClassifier",
|
||||||
Label = output.Split(' ')[0].Split(new string[] { "__label__" }, StringSplitOptions.None)[1],
|
Label = output.Split(' ')[0].Split(new string[] { "__label__" }, StringSplitOptions.None)[1],
|
||||||
Confidence = decimal.Parse(output.Split(' ')[1])
|
Confidence = decimal.Parse(output.Split(' ')[1])
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ namespace BotSharp.Core.Models
|
||||||
|
|
||||||
public OriginalRequest OriginalRequest { get; set; }
|
public OriginalRequest OriginalRequest { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Agent directory
|
||||||
|
/// </summary>
|
||||||
|
public string AgentDir { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// What model is used to predict.
|
/// What model is used to predict.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace BotSharp.Core.Engines
|
||||||
{
|
{
|
||||||
public class TextClassificationResult
|
public class TextClassificationResult
|
||||||
{
|
{
|
||||||
|
public String Classifier { get; set; }
|
||||||
|
|
||||||
public String Label { get; set; }
|
public String Label { get; set; }
|
||||||
|
|
||||||
public Decimal Confidence { get; set; }
|
public Decimal Confidence { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ namespace BotSharp.RestApi
|
||||||
public string Train([FromRoute] String agentId)
|
public string Train([FromRoute] String agentId)
|
||||||
{
|
{
|
||||||
string agentDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agentId);
|
string agentDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agentId);
|
||||||
string dest = Directory.GetDirectories(agentDir).Last();
|
string dest = Directory.GetDirectories(agentDir).Where(x => x.Contains("model_")).Last();
|
||||||
var agent = _platform.LoadAgentFromFile(dest);
|
var agent = _platform.LoadAgentFromFile(dest);
|
||||||
_platform.Train(new BotTrainOptions { AgentDir = agentDir, Model = dest.Split(Path.DirectorySeparatorChar).Last() });
|
_platform.Train(new BotTrainOptions { AgentDir = agentDir, Model = dest.Split(Path.DirectorySeparatorChar).Last() });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace BotSharp.RestApi.Rasa
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost, HttpGet]
|
[HttpPost, HttpGet]
|
||||||
public ActionResult<RasaResponse> Parse()
|
public ActionResult<RasaResponse> Parse(RasaRequestModel request)
|
||||||
{
|
{
|
||||||
var config = new AIConfiguration("", SupportedLanguage.English);
|
var config = new AIConfiguration("", SupportedLanguage.English);
|
||||||
config.SessionId = "rasa nlu";
|
config.SessionId = "rasa nlu";
|
||||||
|
|
@ -46,16 +46,21 @@ namespace BotSharp.RestApi.Rasa
|
||||||
{
|
{
|
||||||
body = reader.ReadToEnd();
|
body = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
var request = JsonConvert.DeserializeObject<RasaRequestModel>(body);
|
|
||||||
|
if(request ==null && !String.IsNullOrEmpty(body))
|
||||||
|
{
|
||||||
|
request = JsonConvert.DeserializeObject<RasaRequestModel>(body);
|
||||||
|
}
|
||||||
|
|
||||||
// Load agent
|
// Load agent
|
||||||
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", request.Project);
|
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", request.Project);
|
||||||
var modelPath = Path.Combine(projectPath, request.Model);
|
var modelPath = Path.Combine(projectPath, request.Model);
|
||||||
|
|
||||||
_platform.LoadAgentFromFile(modelPath);
|
var agent = _platform.LoadAgentFromFile(modelPath);
|
||||||
|
|
||||||
var aIResponse = _platform.TextRequest(new AIRequest
|
var aIResponse = _platform.TextRequest(new AIRequest
|
||||||
{
|
{
|
||||||
|
AgentDir = projectPath,
|
||||||
Model = request.Model,
|
Model = request.Model,
|
||||||
Query = new String[] { request.Text }
|
Query = new String[] { request.Text }
|
||||||
});
|
});
|
||||||
|
|
@ -76,7 +81,7 @@ namespace BotSharp.RestApi.Rasa
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
Text = request.Text,
|
Text = request.Text,
|
||||||
Model = request.Model,
|
Model = request.Model,
|
||||||
Project = request.Project,
|
Project = agent.Name,
|
||||||
IntentRanking = new List<RasaResponseIntent> { }
|
IntentRanking = new List<RasaResponseIntent> { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
3294
BotSharp.UI/package-lock.json
generated
3294
BotSharp.UI/package-lock.json
generated
File diff suppressed because it is too large
Load diff
35
BotSharp.WebHost/Program.cs
Normal file
35
BotSharp.WebHost/Program.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace BotSharp.WebHost
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
BuildWebHost(args).Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
|
Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||||
|
{
|
||||||
|
var env = hostingContext.HostingEnvironment;
|
||||||
|
var settings = Directory.GetFiles(Path.Combine(env.ContentRootPath, "Settings"), "*.json");
|
||||||
|
settings.ToList().ForEach(setting =>
|
||||||
|
{
|
||||||
|
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
#if RASA_UI
|
||||||
|
.UseUrls("http://0.0.0.0:5000")
|
||||||
|
#else
|
||||||
|
.UseUrls("http://0.0.0.0:3112")
|
||||||
|
#endif
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,15 +15,6 @@ Make sure you've got `Docker`_ installed.
|
||||||
|
|
||||||
Point your web browser at http://localhost:5001 and enjoy Rasa-UI with BotSharp.
|
Point your web browser at http://localhost:5001 and enjoy Rasa-UI with BotSharp.
|
||||||
|
|
||||||
Integrate with `Articulate UI`_, you can use docker compose to run.
|
|
||||||
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 Rasa-UI with BotSharp.
|
|
||||||
|
|
||||||
Building BotSharp
|
Building BotSharp
|
||||||
^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^
|
||||||
Make sure the `Microsoft .NET Core`_ build environment is installed.
|
Make sure the `Microsoft .NET Core`_ build environment is installed.
|
||||||
|
|
@ -77,4 +68,4 @@ Use BotSharp.NLP as a natural language processing toolkit alone.
|
||||||
.. _Rasa UI: https://github.com/paschmann/rasa-ui
|
.. _Rasa UI: https://github.com/paschmann/rasa-ui
|
||||||
.. _Articulate UI: https://spg.ai/projects/articulate
|
.. _Articulate UI: https://spg.ai/projects/articulate
|
||||||
.. _Microsoft .NET Core: https://www.microsoft.com/net/download
|
.. _Microsoft .NET Core: https://www.microsoft.com/net/download
|
||||||
.. _Docker: https://www.docker.com
|
.. _Docker: https://www.docker.com
|
||||||
Loading…
Reference in a new issue