Added RASA and DIALOGFLOW compile condition.
This commit is contained in:
parent
fd1738e264
commit
4037160abd
|
|
@ -4,6 +4,10 @@
|
|||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
<IsPackable>false</IsPackable>
|
||||
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ namespace BotSharp.Core.Engines
|
|||
{
|
||||
public interface IBotPlatform
|
||||
{
|
||||
AIConfiguration AiConfig { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Load agent profile
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
@ -31,10 +32,26 @@
|
|||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|x64'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|x64'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DefineConstants>TRACE;MODEL_PER_CONTEXTS</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace BotSharp.Core.Engines
|
|||
{
|
||||
public String Id { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Platform { get; set; }
|
||||
public PlatformType Platform { get; set; }
|
||||
public String ClientAccessToken { get; set; }
|
||||
public String DeveloperAccessToken { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -115,16 +115,16 @@ namespace BotSharp.Core.Engines
|
|||
|
||||
switch (meta.Platform)
|
||||
{
|
||||
case "Dialogflow":
|
||||
case PlatformType.Dialogflow:
|
||||
importer = new AgentImporterInDialogflow();
|
||||
break;
|
||||
case "Rasa":
|
||||
case PlatformType.Rasa:
|
||||
importer = new AgentImporterInRasa();
|
||||
break;
|
||||
case "Sebis":
|
||||
case PlatformType.Sebis:
|
||||
importer = new AgentImporterInSebis();
|
||||
break;
|
||||
case "QuickQA":
|
||||
case PlatformType.QuickQA:
|
||||
importer = new AgentImporterInQuickQA();
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -291,6 +291,31 @@ namespace BotSharp.Core.Engines
|
|||
|
||||
public void AssembleTrainData(Agent agent)
|
||||
{
|
||||
// convert agent to training corpus
|
||||
agent.Corpus = new TrainingCorpus
|
||||
{
|
||||
Entities = new List<TrainingEntity>(),
|
||||
UserSays = new List<TrainingIntentExpression<TrainingIntentExpressionPart>>()
|
||||
};
|
||||
|
||||
agent.Intents.ForEach(intent =>
|
||||
{
|
||||
intent.UserSays.ForEach(say => {
|
||||
agent.Corpus.UserSays.Add(new TrainingIntentExpression<TrainingIntentExpressionPart>
|
||||
{
|
||||
Intent = intent.Name,
|
||||
Text = String.Join("", say.Data.Select(x => x.Text)),
|
||||
Entities = say.Data.Where(x => !String.IsNullOrEmpty(x.Meta))
|
||||
.Select(x => new TrainingIntentExpressionPart
|
||||
{
|
||||
Value = x.Text,
|
||||
Entity = x.Meta,
|
||||
Start = x.Start
|
||||
})
|
||||
.ToList()
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
BotSharp.Core/Engines/PlatformType.cs
Normal file
14
BotSharp.Core/Engines/PlatformType.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Core.Engines
|
||||
{
|
||||
public enum PlatformType
|
||||
{
|
||||
Dialogflow = 1,
|
||||
Rasa = 2,
|
||||
Sebis = 3,
|
||||
QuickQA = 4
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
<IsPackable>false</IsPackable>
|
||||
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -24,12 +24,21 @@ Naive Bayes Classifier</Description>
|
|||
Mark milestone 0.2.3. Tokenizer, POS Tagger, NER and Text Classifier modules can be used in production environments.</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/Oceania2018/BotSharp/master/BotSharp.WebHost/wwwroot/images/BotSharp.png</PackageIconUrl>
|
||||
<PackageTags>BotSharp, NLP, NLU, POS, NER, LSTM, CRF, SVM, Tagger, NaiveBayes</PackageTags>
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|AnyCPU'">
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BotSharp.Algorithm\BotSharp.Algorithm.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -16,11 +16,22 @@
|
|||
<PackageTags>NLU, Chatbot, Bot, AI Bot</PackageTags>
|
||||
<PackageReleaseNotes>Restful API for BotSharp.Core</PackageReleaseNotes>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
|
||||
<DocumentationFile>BotSharp.RestApi.xml</DocumentationFile>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netcoreapp2.1\BotSharp.RestApi.xml</DocumentationFile>
|
||||
<DefineConstants>TRACE;DEBUG;RASA_UI</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
|
@ -28,6 +39,16 @@
|
|||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|x64'">
|
||||
<DocumentationFile>bin\Debug\netcoreapp2.1\BotSharp.RestApi.xml</DocumentationFile>
|
||||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|x64'">
|
||||
<DocumentationFile>bin\Debug\netcoreapp2.1\BotSharp.RestApi.xml</DocumentationFile>
|
||||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DefineConstants>TRACE;MODE_DIALOGFLOW;RELEASE;NETCOREAPP;NETCOREAPP2_1;RELEASE;NETCOREAPP;NETCOREAPP2_1</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
|
@ -36,6 +57,12 @@
|
|||
<DefineConstants>TRACE;MODE_DIALOGFLOW;RELEASE;NETCOREAPP;NETCOREAPP2_1;RELEASE;NETCOREAPP;NETCOREAPP2_1</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DIALOGFLOW|AnyCPU'">
|
||||
<WarningLevel>1</WarningLevel>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<DocumentationFile>BotSharp.RestApi.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Authentication\**" />
|
||||
<EmbeddedResource Remove="Authentication\**" />
|
||||
|
|
|
|||
143
BotSharp.RestApi/BotSharp.RestApi.xml
Normal file
143
BotSharp.RestApi/BotSharp.RestApi.xml
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>BotSharp.RestApi</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:BotSharp.RestApi.AgentController">
|
||||
<summary>
|
||||
Agent
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.AgentController.#ctor(BotSharp.Core.Engines.IBotPlatform)">
|
||||
<summary>
|
||||
Initialize dialog controller and get a platform instance
|
||||
</summary>
|
||||
<param name="platform"></param>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.AgentController.Restore(Microsoft.AspNetCore.Http.IFormFile)">
|
||||
<summary>
|
||||
Restore a agent from a uploaded zip file
|
||||
</summary>
|
||||
<param name="file"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.AgentController.Train(System.String)">
|
||||
<summary>
|
||||
Train agent
|
||||
</summary>
|
||||
<param name="agentId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.AgentController.Dump(System.String)">
|
||||
<summary>
|
||||
Dump agent
|
||||
</summary>
|
||||
<param name="agentId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.Contexts">
|
||||
<summary>
|
||||
Array of additional context objects. Should be sent via a POST /query request.
|
||||
Contexts sent in a query are activated before the query.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.Event">
|
||||
<summary>
|
||||
Object containing event name and additional data.
|
||||
The "data" parameter can be submitted only in POST requests.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.Lang">
|
||||
<summary>
|
||||
Language tag, e.g., en, es etc.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.Query">
|
||||
<summary>
|
||||
Natural language text to be processed. Query length should not exceed 256 characters.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.SessionId">
|
||||
<summary>
|
||||
A string token up to 36 symbols long, used to identify the client and to manage session parameters (including contexts) per client.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Dialogflow.QueryModel.Timezone">
|
||||
<summary>
|
||||
Time zone from IANA Time Zone Database Examples: America/New_York, Europe/Paris
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:BotSharp.RestApi.Rasa.ParseController">
|
||||
<summary>
|
||||
send a text request
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.ParseController.#ctor(BotSharp.Core.Engines.IBotPlatform)">
|
||||
<summary>
|
||||
Initialize dialog controller and get a platform instance
|
||||
</summary>
|
||||
<param name="platform"></param>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.ParseController.Parse(BotSharp.RestApi.Rasa.RasaRequestModel)">
|
||||
<summary>
|
||||
parse request
|
||||
</summary>
|
||||
<param name="request"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:BotSharp.RestApi.Rasa.StatusController">
|
||||
<summary>
|
||||
This returns all the currently available projects.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.StatusController.#ctor(BotSharp.Core.Engines.IBotPlatform)">
|
||||
<summary>
|
||||
Initialize status controller and get a platform instance
|
||||
</summary>
|
||||
<param name="platform"></param>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.StatusController.Get">
|
||||
<summary>
|
||||
Returns a list of available projects the server can use to fulfill /parse requests.
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:BotSharp.RestApi.Rasa.TrainController">
|
||||
<summary>
|
||||
You can post your training data to this endpoint to train a new model for a project.
|
||||
This request will wait for the server answer: either the model was trained successfully or the training exited with an error.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.TrainController.#ctor(BotSharp.Core.Engines.IBotPlatform)">
|
||||
<summary>
|
||||
Initialize dialog controller and get a platform instance
|
||||
</summary>
|
||||
<param name="platform"></param>
|
||||
</member>
|
||||
<member name="M:BotSharp.RestApi.Rasa.TrainController.Train(System.String,System.String)">
|
||||
<summary>
|
||||
Using the HTTP server, you must specify the project you want to train a new model for to be able to use it during parse requests later on : /train?project=my_project.
|
||||
</summary>
|
||||
<param name="model">Model name</param>
|
||||
<param name="project"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Integrations.FacebookMessenger.WebhookMessageRecipient.Id">
|
||||
<summary>
|
||||
PAGE_ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:BotSharp.RestApi.Integrations.FacebookMessenger.WebhookMessageSender.Id">
|
||||
<summary>
|
||||
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>
|
||||
|
|
@ -1,18 +1,23 @@
|
|||
using BotSharp.Core.Engines;
|
||||
using BotSharp.Core.Models;
|
||||
using BotSharp.NLP;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Dialogflow
|
||||
{
|
||||
#if MODE_DIALOGFLOW
|
||||
#if DIALOGFLOW
|
||||
/// <summary>
|
||||
/// Dialogflow mode query controller
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("v1/[controller]")]
|
||||
public class QueryController : ControllerBase
|
||||
{
|
||||
|
|
@ -37,18 +42,51 @@ namespace BotSharp.RestApi.Dialogflow
|
|||
[HttpGet, HttpPost]
|
||||
public ActionResult<AIResponse> Query(QueryModel request)
|
||||
{
|
||||
String clientAccessToken = Request.Headers["ClientAccessToken"];
|
||||
var config = new AIConfiguration(clientAccessToken, SupportedLanguage.English);
|
||||
config.SessionId = request.SessionId;
|
||||
String clientAccessToken = (User.Identity as ClaimsIdentity).Claims.FirstOrDefault(x => x.Type == "UserId")?.Value;
|
||||
_platform.AiConfig = new AIConfiguration(clientAccessToken, SupportedLanguage.English);
|
||||
_platform.AiConfig.SessionId = request.SessionId;
|
||||
|
||||
_platform.LoadAgent(clientAccessToken);
|
||||
// find a model according to clientAccessToken
|
||||
string projectPath = String.Empty;
|
||||
string projectsPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects");
|
||||
|
||||
string[] d1 = Directory.GetDirectories(projectsPath);
|
||||
for (int i = 0; i < d1.Length; i++)
|
||||
{
|
||||
string[] d2 = Directory.GetDirectories(d1[i]);
|
||||
for (int j = 0; j < d2.Length; j++)
|
||||
{
|
||||
string metaJson = System.IO.File.ReadAllText(Path.Combine(d2[j], "meta.json"));
|
||||
|
||||
var meta = JsonConvert.DeserializeObject<AgentImportHeader>(metaJson);
|
||||
|
||||
if (meta.ClientAccessToken == clientAccessToken)
|
||||
{
|
||||
projectPath = d1[i];
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
if (!String.IsNullOrEmpty(projectPath))
|
||||
{
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// Load agent
|
||||
string model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
|
||||
string dataDir = Path.Combine(projectPath, model);
|
||||
|
||||
_platform.LoadAgentFromFile(dataDir);
|
||||
|
||||
var aIResponse = _platform.TextRequest(new AIRequest
|
||||
{
|
||||
Timezone = request.Timezone,
|
||||
Contexts = request?.Contexts?.Select(x => new AIContext { Name = x })?.ToList(),
|
||||
Language = request.Lang,
|
||||
Query = new String[] { request.Query }
|
||||
Query = new String[] { request.Query },
|
||||
AgentDir = projectPath,
|
||||
Model = model
|
||||
});
|
||||
|
||||
return aIResponse;
|
||||
|
|
|
|||
59
BotSharp.RestApi/Dialogflow/TrainController.cs
Normal file
59
BotSharp.RestApi/Dialogflow/TrainController.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using BotSharp.Core.Agents;
|
||||
using BotSharp.Core.Engines;
|
||||
using BotSharp.Core.Engines.Rasa;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
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
|
||||
{
|
||||
#if DIALOGFLOW
|
||||
/// <summary>
|
||||
/// You can post your training data to this endpoint to train a new model for a project.
|
||||
/// This request will wait for the server answer: either the model was trained successfully or the training exited with an error.
|
||||
/// </summary>
|
||||
[Route("v1/[controller]")]
|
||||
public class TrainController : ControllerBase
|
||||
{
|
||||
private readonly IBotPlatform _platform;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize dialog controller and get a platform instance
|
||||
/// </summary>
|
||||
/// <param name="platform"></param>
|
||||
public TrainController(IBotPlatform platform)
|
||||
{
|
||||
_platform = platform;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<String>> Train([FromQuery] string agentId)
|
||||
{
|
||||
var trainer = new BotTrainer();
|
||||
|
||||
// save corpus to agent dir
|
||||
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agentId);
|
||||
var model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
|
||||
string dataDir = Path.Combine(projectPath, model);
|
||||
|
||||
var agent = _platform.LoadAgentFromFile(dataDir);
|
||||
|
||||
var info = await trainer.Train(agent, new BotTrainOptions
|
||||
{
|
||||
AgentDir = projectPath,
|
||||
Model = model
|
||||
});
|
||||
|
||||
return Ok(new { info = info });
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
{
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
[Route("[controller]")]
|
||||
public class ConfigController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ using Console = Colorful.Console;
|
|||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
{
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
/// <summary>
|
||||
/// send a text request
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Text;
|
|||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
{
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
/// <summary>
|
||||
/// This returns all the currently available projects.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
{
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
/// <summary>
|
||||
/// You can post your training data to this endpoint to train a new model for a project.
|
||||
/// This request will wait for the server answer: either the model was trained successfully or the training exited with an error.
|
||||
|
|
@ -94,7 +94,7 @@ namespace BotSharp.RestApi.Rasa
|
|||
System.IO.File.WriteAllText(metaFileName, JsonConvert.SerializeObject(new AgentImportHeader
|
||||
{
|
||||
Name = project,
|
||||
Platform = "Rasa"
|
||||
Platform = PlatformType.Rasa
|
||||
}));
|
||||
// in order to unify the process.
|
||||
var fileName = Path.Combine(modelPath, "corpus.json");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
{
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
[Route("[controller]")]
|
||||
public class VersionController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -4,16 +4,33 @@
|
|||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<RuntimeIdentifiers>Portable;win10-x64;centos.7-x64</RuntimeIdentifiers>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Configurations>Debug;Release;RASA NLU;DIALOGFLOW;RASA</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG;RASA_UI</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|AnyCPU'">
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA|x64'">
|
||||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RASA NLU|x64'">
|
||||
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="App_Data\AgentArchive\**" />
|
||||
<Compile Remove="App_Data\Corpus\**" />
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace BotSharp.WebHost
|
|||
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
|
||||
});
|
||||
})
|
||||
#if RASA_UI
|
||||
#if RASA
|
||||
.UseUrls("http://0.0.0.0:5000")
|
||||
#else
|
||||
.UseUrls("http://0.0.0.0:3112")
|
||||
|
|
|
|||
|
|
@ -107,9 +107,9 @@ namespace BotSharp.WebHost
|
|||
if (!string.IsNullOrWhiteSpace(token) && (token = token.Split(' ').Last()).Length == 32)
|
||||
{
|
||||
var config = (IConfiguration)AppDomain.CurrentDomain.GetData("Configuration");
|
||||
context.Request.Headers["ClientAccessToken"] = token;
|
||||
context.Request.Headers["Authorization"] = token;
|
||||
|
||||
// context.Request.Headers["Authorization"] = "Bearer " + JwtToken.GenerateToken(config, userId);
|
||||
context.Request.Headers["Authorization"] = "Bearer " + JwtToken.GenerateToken(config, token);
|
||||
}
|
||||
|
||||
await next.Invoke();
|
||||
|
|
|
|||
68
BotSharp.sln
68
BotSharp.sln
|
|
@ -22,75 +22,75 @@ EndProject
|
|||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
DIALOGFLOW|Any CPU = DIALOGFLOW|Any CPU
|
||||
RASA|Any CPU = RASA|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Debug|x64.Build.0 = Debug|x64
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Release|x64.ActiveCfg = Release|x64
|
||||
{95780673-2A1A-4953-962F-C46CBFDD07FF}.Release|x64.Build.0 = Release|x64
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Debug|x64.Build.0 = Debug|x64
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Release|x64.ActiveCfg = Release|x64
|
||||
{80DDAA05-69BC-49DD-96A4-37345E7A2E20}.Release|x64.Build.0 = Release|x64
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Debug|x64.Build.0 = Debug|x64
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Release|x64.ActiveCfg = Release|x64
|
||||
{03DCA427-327A-4FC9-9A2F-57D17F16708C}.Release|x64.Build.0 = Release|x64
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Debug|x64.Build.0 = Debug|x64
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Release|x64.ActiveCfg = Release|x64
|
||||
{A31A6853-DFB8-477D-8F09-8E6E3D166102}.Release|x64.Build.0 = Release|x64
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{BE1A033F-AC14-4654-95C3-4B33AF8F6BBF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{4C4EE7A8-99CA-41FE-9517-C66799720784}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Debug|x64.Build.0 = Debug|x64
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{C2FDC855-BD88-4041-B0FF-3AA8A1C11A22}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{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
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Debug|x64.Build.0 = Debug|x64
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.RASA|Any CPU.ActiveCfg = RASA|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.RASA|Any CPU.Build.0 = RASA|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Release|x64.ActiveCfg = Release|x64
|
||||
{4AAA7A40-0389-41AC-B55E-CFAF7C8600B1}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
Loading…
Reference in a new issue