diff --git a/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj b/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj
deleted file mode 100644
index a43c3086..00000000
--- a/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- netcoreapp2.0
- true
-
-
-
- bin\Debug\netcoreapp2.0\Bot.Rasa.RestApi.xml
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Bot.Rasa/Models/UserSay.cs b/Bot.Rasa/Models/UserSay.cs
deleted file mode 100644
index 8fdc6ed5..00000000
--- a/Bot.Rasa/Models/UserSay.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Bot.Rasa.Expressions;
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Bot.Rasa.Models
-{
- public class UserSay
- {
- public UserSay()
- {
- Entities = new List();
- }
-
- public String Text { get; set; }
- public String Intent { get; set; }
- public List Entities { get; set; }
- }
-}
diff --git a/Bot.UnitTest/AgentTest.cs b/Bot.UnitTest/AgentTest.cs
deleted file mode 100644
index b48e90d2..00000000
--- a/Bot.UnitTest/AgentTest.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using Bot.Rasa;
-using Bot.Rasa.Agents;
-using Bot.Rasa.Consoles;
-using Bot.Rasa.Models;
-using EntityFrameworkCore.BootKit;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Bot.UnitTest
-{
- [TestClass]
- public class AgentTest : TestEssential
- {
- public static String BOT_ID = "2b6a288e-d891-40c6-96ce-6a0cf324545c";
- public static String BOT_NAME = "VirtualAssistant";
-
- [TestMethod]
- public void CreateAgent()
- {
- var rasa = new RasaAi(dc);
- var importer = new AgentImporterInDialogflow();
- var agent = rasa.RestoreAgent(importer, BOT_NAME);
- agent.Id = BOT_ID;
-
- int row = dc.DbTran(() => rasa.SaveAgent(agent));
-
- var loadedAgent = rasa.LoadAgent(agent.Id);
- Assert.IsTrue(loadedAgent.Intents.Count == agent.Intents.Count);
- }
-
- [TestMethod]
- public void TextRequest()
- {
- var rasa = new RasaAi(dc);
- rasa.agent = rasa.LoadAgent(BOT_ID);
-
- var response = rasa.TextRequest(dc, new AIRequest { Query = new String[] { "Create a work order for PetSmart" } });
- Assert.IsTrue(response.Result.Metadata.IntentName == "Create Work Order");
-
- response = rasa.TextRequest(dc, new AIRequest { Query = new String[] { "1010" } });
- Assert.IsTrue(response.Result.Metadata.IntentName == "Telling Store Number");
- }
-
- [TestMethod]
- public void Train()
- {
- var rasa = new RasaAi(dc);
- }
- }
-}
diff --git a/Bot.WebStarter/Bot.WebStarter.csproj b/Bot.WebStarter/Bot.WebStarter.csproj
index cb56ae3a..a7506ff4 100644
--- a/Bot.WebStarter/Bot.WebStarter.csproj
+++ b/Bot.WebStarter/Bot.WebStarter.csproj
@@ -24,7 +24,7 @@
-
+
diff --git a/Bot.WebStarter/Startup.cs b/Bot.WebStarter/Startup.cs
index bacfce11..a052058c 100644
--- a/Bot.WebStarter/Startup.cs
+++ b/Bot.WebStarter/Startup.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
-using Bot.Rasa.Consoles;
+using BotSharp.Core.Engines;
using DotNetToolkit.JwtHelper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -52,7 +52,7 @@ namespace Bot.WebStarter
var info = Configuration.GetSection("Swagger").Get();
c.SwaggerDoc(info.Version, info);
- var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "Bot.Rasa.RestApi.xml");
+ var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "BotSharp.RestApi.xml");
c.IncludeXmlComments(filePath);
});
}
@@ -81,7 +81,7 @@ namespace Bot.WebStarter
app.UseAuthentication();
app.UseMvc();
- app.UseEntityDbContext(Configuration, env.ContentRootPath, new String[] { "Bot.Rasa" });
+ app.UseEntityDbContext(Configuration, env.ContentRootPath, new String[] { "BotSharp.Core." });
app.UseInitLoader();
}
}
diff --git a/Bot.WebStarter/settings.db.json b/Bot.WebStarter/settings.db.json
index 06db2785..23309cfc 100644
--- a/Bot.WebStarter/settings.db.json
+++ b/Bot.WebStarter/settings.db.json
@@ -3,7 +3,7 @@
"Default": "SqlServer",
"ConnectionStrings": {
"InMemory": "DataSource=:memory:",
- "Sqlite": "Data Source=|DataDirectory|\\RasaBot.db;",
+ "Sqlite": "Data Source=|DataDirectory|RasaBot.db;",
"SqlServer": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=RasaBot;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
}
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowAgent.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowAgent.cs
similarity index 88%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowAgent.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowAgent.cs
index 9e5f441f..74c6596c 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowAgent.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowAgent.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowAgent
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowEntity.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowEntity.cs
similarity index 95%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowEntity.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowEntity.cs
index 93d335a4..4bef17e2 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowEntity.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowEntity.cs
@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
[JsonObject]
public class DialogflowEntity
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowEntityEntry.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowEntityEntry.cs
similarity index 93%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowEntityEntry.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowEntityEntry.cs
index bb7b86cb..8a601906 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowEntityEntry.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowEntityEntry.cs
@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
[JsonObject]
public class DialogflowEntityEntry
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntent.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntent.cs
similarity index 90%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntent.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntent.cs
index 2a6e2174..a65d809e 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntent.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntent.cs
@@ -1,9 +1,9 @@
-using Bot.Rasa.Intents;
+using BotSharp.Core.Intents;
using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntent
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentEvent.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentEvent.cs
similarity index 79%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentEvent.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentEvent.cs
index 9d01da1a..50993e4d 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentEvent.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentEvent.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentEvent
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpression.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpression.cs
similarity index 86%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpression.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpression.cs
index 7d240d56..65d7436e 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpression.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpression.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentExpression
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs
similarity index 87%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs
index af2106dd..5b1968b9 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentExpressionPart
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponse.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponse.cs
similarity index 84%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponse.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponse.cs
index 9a30b51a..c539f2b9 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponse.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponse.cs
@@ -1,10 +1,10 @@
-using Bot.Rasa.Intents;
-using Bot.Rasa.Models;
+using BotSharp.Core.Intents;
+using BotSharp.Core.Models;
using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentResponse
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs
similarity index 79%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs
index 0c3918c3..c5439b65 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs
@@ -1,9 +1,9 @@
-using Bot.Rasa.Models;
+using BotSharp.Core.Models;
using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentResponseMessage : AIResponseMessageBase
{
diff --git a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs
similarity index 89%
rename from Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs
rename to BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs
index a047f184..153c8650 100644
--- a/Bot.Rasa/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs
+++ b/BotSharp.Core/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Adapters.Dialogflow
+namespace BotSharp.Core.Adapters.Dialogflow
{
public class DialogflowIntentResponseParameter
{
diff --git a/Bot.Rasa/Agents/Agent.cs b/BotSharp.Core/Agents/Agent.cs
similarity index 65%
rename from Bot.Rasa/Agents/Agent.cs
rename to BotSharp.Core/Agents/Agent.cs
index 3affadbd..fe699be8 100644
--- a/Bot.Rasa/Agents/Agent.cs
+++ b/BotSharp.Core/Agents/Agent.cs
@@ -1,5 +1,5 @@
-using Bot.Rasa.Entities;
-using Bot.Rasa.Intents;
+using BotSharp.Core.Entities;
+using BotSharp.Core.Intents;
using EntityFrameworkCore.BootKit;
using Newtonsoft.Json;
using System;
@@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Agents
+namespace BotSharp.Core.Agents
{
[Table("Bot_Agent")]
public class Agent : DbRecord, IDbRecord
@@ -22,6 +22,16 @@ namespace Bot.Rasa.Agents
public String Language { get; set; }
+ ///
+ /// Only access text/ audio rquest
+ ///
+ public String ClientAccessToken { get; set; }
+
+ ///
+ /// Developer can access more APIs
+ ///
+ public String DeveloperAccessToken { get; set; }
+
[ForeignKey("AgentId")]
public List Intents { get; set; }
diff --git a/Bot.Rasa/Agents/AgentExtension.cs b/BotSharp.Core/Agents/AgentExtension.cs
similarity index 62%
rename from Bot.Rasa/Agents/AgentExtension.cs
rename to BotSharp.Core/Agents/AgentExtension.cs
index 7a659b0e..1fa7ad59 100644
--- a/Bot.Rasa/Agents/AgentExtension.cs
+++ b/BotSharp.Core/Agents/AgentExtension.cs
@@ -1,6 +1,6 @@
-using Bot.Rasa.Entities;
-using Bot.Rasa.Intents;
-using Bot.Rasa.Models;
+using BotSharp.Core.Entities;
+using BotSharp.Core.Intents;
+using BotSharp.Core.Models;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;
using System;
@@ -8,7 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Agents
+namespace BotSharp.Core.Agents
{
public static class AgentExtension
{
@@ -32,12 +32,14 @@ namespace Bot.Rasa.Agents
{
var trainingData = new RasaTrainingData
{
- UserSays = new List()
+ UserSays = new List()
};
var intents = dc.Table()
.Include(x => x.Contexts)
- .Include(x => x.UserSays).ThenInclude(say => say.Data).ToList();
+ .Include(x => x.UserSays).ThenInclude(say => say.Data)
+ .Where(x => x.UserSays.Count > 0)
+ .ToList();
var contexts = ctx.OrderBy(x => x.Name).Select(x => x.Name.ToLower()).ToList();
@@ -56,12 +58,34 @@ namespace Bot.Rasa.Agents
intents.ForEach(intent =>
{
- trainingData.UserSays.AddRange(intent.UserSays
- .Select(exp => new UserSay
+ intent.UserSays.ForEach(exp =>
+ {
+ var say = new RasaIntentExpression
{
Intent = intent.Name,
- Text = String.Join("", exp.Data.OrderBy(x => x.UpdatedTime).Select(x => x.Text))
- }));
+ Text = String.Join("", exp.Data.OrderBy(x => x.UpdatedTime).Select(x => x.Text)),
+ };
+
+ // convert entity format
+ exp.Data.Where(x => !String.IsNullOrEmpty(x.Meta))
+ .ToList()
+ .ForEach(x =>
+ {
+ int start = say.Text.IndexOf(x.Text);
+
+ var part = new RasaIntentExpressionPart
+ {
+ Value = x.Text,
+ Entity = x.Alias,
+ Start = start,
+ End = start + x.Text.Length
+ };
+
+ say.Entities.Add(part);
+ });
+
+ trainingData.UserSays.Add(say);
+ });
});
return trainingData;
diff --git a/Bot.Rasa/Bot.Rasa.csproj b/BotSharp.Core/BotSharp.Core.csproj
similarity index 77%
rename from Bot.Rasa/Bot.Rasa.csproj
rename to BotSharp.Core/BotSharp.Core.csproj
index 6f6487ac..9ef96022 100644
--- a/Bot.Rasa/Bot.Rasa.csproj
+++ b/BotSharp.Core/BotSharp.Core.csproj
@@ -2,19 +2,18 @@
netcoreapp2.0
- true
-
-
-
-
+
+
-
-
+
+
+
+
diff --git a/Bot.Rasa/Consoles/AgentImporterInDialogflow.cs b/BotSharp.Core/Engines/AgentImporterInDialogflow.cs
similarity index 96%
rename from Bot.Rasa/Consoles/AgentImporterInDialogflow.cs
rename to BotSharp.Core/Engines/AgentImporterInDialogflow.cs
index 4a3e9b1b..0cb352c9 100644
--- a/Bot.Rasa/Consoles/AgentImporterInDialogflow.cs
+++ b/BotSharp.Core/Engines/AgentImporterInDialogflow.cs
@@ -3,16 +3,16 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
-using Bot.Rasa.Adapters.Dialogflow;
-using Bot.Rasa.Agents;
-using Bot.Rasa.Entities;
-using Bot.Rasa.Intents;
-using Bot.Rasa.Models;
+using BotSharp.Core.Adapters.Dialogflow;
+using BotSharp.Core.Agents;
+using BotSharp.Core.Entities;
+using BotSharp.Core.Intents;
+using BotSharp.Core.Models;
using DotNetToolkit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-namespace Bot.Rasa.Consoles
+namespace BotSharp.Core.Engines
{
public class AgentImporterInDialogflow : IAgentImporter
{
diff --git a/Bot.Rasa/Consoles/IAgentImporter.cs b/BotSharp.Core/Engines/IAgentImporter.cs
similarity index 88%
rename from Bot.Rasa/Consoles/IAgentImporter.cs
rename to BotSharp.Core/Engines/IAgentImporter.cs
index 947654c8..4a1299bf 100644
--- a/Bot.Rasa/Consoles/IAgentImporter.cs
+++ b/BotSharp.Core/Engines/IAgentImporter.cs
@@ -1,9 +1,9 @@
-using Bot.Rasa.Agents;
+using BotSharp.Core.Agents;
using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Consoles
+namespace BotSharp.Core.Engines
{
public interface IAgentImporter
{
diff --git a/Bot.Rasa/Consoles/RasaAi.cs b/BotSharp.Core/Engines/RasaAi.cs
similarity index 72%
rename from Bot.Rasa/Consoles/RasaAi.cs
rename to BotSharp.Core/Engines/RasaAi.cs
index 2fb1e00f..d55361f1 100644
--- a/Bot.Rasa/Consoles/RasaAi.cs
+++ b/BotSharp.Core/Engines/RasaAi.cs
@@ -1,5 +1,6 @@
-using Bot.Rasa.Agents;
-using Bot.Rasa.Entities;
+using BotSharp.Core.Agents;
+using BotSharp.Core.Entities;
+using BotSharp.Core.Models;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -11,22 +12,28 @@ using System.IO;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Consoles
+namespace BotSharp.Core.Engines
{
public class RasaAi
{
- private Database dc { get; set; }
- public static RasaOptions Options { get; set; }
+ public Database dc { get; set; }
+ public AIConfiguration AiConfig { get; set; }
public static IConfiguration Configuration { get; set; }
public Agent agent { get; set; }
- public String SessionId { get; set; }
-
public RasaAi(Database dc)
{
this.dc = dc;
- SessionId = Guid.NewGuid().ToString();
+ }
+
+ public RasaAi(Database dc, AIConfiguration aiConfig)
+ {
+ this.dc = dc;
+
+ AiConfig = aiConfig;
+ agent = LoadAgent();
+ aiConfig.DevMode = agent.DeveloperAccessToken == aiConfig.ClientAccessToken;
}
///
@@ -37,7 +44,7 @@ namespace Bot.Rasa.Consoles
///
public Agent RestoreAgent(IAgentImporter importer, String agentId)
{
- string dataDir = $"{Options.ContentRootPath}\\App_Data\\DbInitializer\\Agents\\";
+ string dataDir = $"{Database.ContentRootPath}\\App_Data\\DbInitializer\\Agents\\";
// Load agent summary
agent = importer.LoadAgent(agentId, dataDir);
@@ -61,11 +68,11 @@ namespace Bot.Rasa.Consoles
return true;
}
- public Agent LoadAgent(String agentId)
+ public Agent LoadAgent()
{
return dc.Table()
.Include(x => x.Intents).ThenInclude(x => x.Contexts)
- .FirstOrDefault(x => x.Id == agentId);
+ .FirstOrDefault(x => x.ClientAccessToken == AiConfig.ClientAccessToken || x.DeveloperAccessToken == AiConfig.ClientAccessToken);
}
public String SaveAgent(Agent agent)
diff --git a/Bot.Rasa/Consoles/RasaOptions.cs b/BotSharp.Core/Engines/RasaOptions.cs
similarity index 91%
rename from Bot.Rasa/Consoles/RasaOptions.cs
rename to BotSharp.Core/Engines/RasaOptions.cs
index 75b9e1bc..3c6f30e5 100644
--- a/Bot.Rasa/Consoles/RasaOptions.cs
+++ b/BotSharp.Core/Engines/RasaOptions.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Consoles
+namespace BotSharp.Core.Engines
{
public class RasaOptions
{
diff --git a/Bot.Rasa/Consoles/RequestExtension.cs b/BotSharp.Core/Engines/RequestExtension.cs
similarity index 60%
rename from Bot.Rasa/Consoles/RequestExtension.cs
rename to BotSharp.Core/Engines/RequestExtension.cs
index c0b4317a..2e58105b 100644
--- a/Bot.Rasa/Consoles/RequestExtension.cs
+++ b/BotSharp.Core/Engines/RequestExtension.cs
@@ -1,7 +1,7 @@
-using Bot.Rasa.Agents;
-using Bot.Rasa.Intents;
-using Bot.Rasa.Models;
-using Bot.Rasa.Sessions;
+using BotSharp.Core.Agents;
+using BotSharp.Core.Intents;
+using BotSharp.Core.Models;
+using BotSharp.Core.Sessions;
using DotNetToolkit;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;
@@ -15,18 +15,24 @@ using System.IO;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Consoles
+namespace BotSharp.Core.Engines
{
public static class RequestExtension
{
- public static AIResponse TextRequest(this RasaAi rasa, Database dc, AIRequest request)
+ public static AIResponse TextRequest(this RasaAi rasa, string text, RequestExtras requestExtras)
+ {
+ return rasa.TextRequest(new AIRequest(text, requestExtras));
+ }
+
+ public static AIResponse TextRequest(this RasaAi rasa, AIRequest request)
{
AIResponse aiResponse = new AIResponse();
RasaResponse response = null;
+ Database dc = rasa.dc;
// Merge input contexts
var contexts = dc.Table()
- .Where(x => x.SessionId == rasa.SessionId && x.Lifespan > 0)
+ .Where(x => x.SessionId == rasa.AiConfig.SessionId && x.Lifespan > 0)
.ToList()
.Select(x => new AIContext { Name = x.Context.ToLower(), Lifespan = x.Lifespan })
.ToList();
@@ -48,43 +54,61 @@ namespace Bot.Rasa.Consoles
}
}).OrderByDescending(x => x.Contexts.Count).ToList();
- // Max contexts match
- foreach(var it in intents)
+ // training per request contexts
{
- request.Contexts = it.Contexts.Select(x => new AIContext { Name = x.Name.ToLower() })
- .OrderBy(x => x.Name)
- .ToList();
- string contextId = $"{String.Join(',', request.Contexts.Select(x => x.Name))}".GetMd5Hash();
-
+ string contextId = $"{String.Join(',', contexts.Select(x => x.Name))}".GetMd5Hash();
string modelName = dc.Table().FirstOrDefault(x => x.ContextId == contextId)?.ModelName;
-
// need training
if (String.IsNullOrEmpty(modelName))
{
+ request.Contexts = contexts.Select(x => new AIContext { Name = x.Name.ToLower() })
+ .OrderBy(x => x.Name)
+ .ToList();
+
dc.DbTran(() =>
{
modelName = TrainWithContexts(rasa, dc, request, contextId);
});
}
- var client = new RestClient($"{RasaAi.Options.HostUrl}");
+ var result = CallRasa(rasa.agent.Id, request.Query.First(), modelName);
- var rest = new RestRequest("parse", Method.POST);
- string json = JsonConvert.SerializeObject(new { Project = rasa.agent.Id, Q = request.Query.First(), Model = modelName },
- new JsonSerializerSettings
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- });
- rest.AddParameter("application/json", json, ParameterType.RequestBody);
-
- var result = client.Execute(rest);
-
- if(result.Data.Intent != null)
+ if (result.Data.Intent != null)
{
response = result.Data;
- break;
}
- };
+ }
+
+ // Max contexts match
+ if (response == null)
+ {
+ foreach (var it in intents)
+ {
+ request.Contexts = it.Contexts.Select(x => new AIContext { Name = x.Name.ToLower() })
+ .OrderBy(x => x.Name)
+ .ToList();
+ string contextId = $"{String.Join(',', request.Contexts.Select(x => x.Name))}".GetMd5Hash();
+
+ string modelName = dc.Table().FirstOrDefault(x => x.ContextId == contextId)?.ModelName;
+
+ // need training
+ if (String.IsNullOrEmpty(modelName))
+ {
+ dc.DbTran(() =>
+ {
+ modelName = TrainWithContexts(rasa, dc, request, contextId);
+ });
+ }
+
+ var result = CallRasa(rasa.agent.Id, request.Query.First(), modelName);
+
+ if (result.Data.Intent != null)
+ {
+ response = result.Data;
+ break;
+ }
+ };
+ }
var intent = (dc.Table().Where(x => x.Name == response.Intent.Name)
.Include(x => x.Responses).ThenInclude(x => x.Contexts)
@@ -95,13 +119,22 @@ namespace Bot.Rasa.Consoles
aiResponse.Id = Guid.NewGuid().ToString();
aiResponse.Lang = rasa.agent.Language;
aiResponse.Status = new AIResponseStatus { };
- aiResponse.SessionId = rasa.SessionId;
+ aiResponse.SessionId = rasa.AiConfig.SessionId;
aiResponse.Timestamp = DateTime.UtcNow;
- intentResponse.Messages.Where(x => x.Type == AIResponseMessageType.Text)
- .ToList()
+ intentResponse.Messages = intentResponse.Messages.OrderBy(x => x.UpdatedTime).ToList();
+ intentResponse.Messages.ToList()
.ForEach(msg =>
{
- msg.Speech = ArrayHelper.GetRandom(msg.Speech.Substring(2, msg.Speech.Length - 4).Split("\",\"").ToList());
+ if (msg.Type == AIResponseMessageType.Custom)
+ {
+
+ }
+ else
+ {
+ msg.Speech = msg.Speech.StartsWith("[") ?
+ ArrayHelper.GetRandom(msg.Speech.Substring(2, msg.Speech.Length - 4).Split("\",\"").ToList()) :
+ msg.Speech;
+ }
});
aiResponse.Result = new AIResponseResult
@@ -114,7 +147,21 @@ namespace Bot.Rasa.Consoles
Metadata = new AIResponseMetadata { IntentId = intent.Id, IntentName = intent.Name },
Fulfillment = new AIResponseFulfillment
{
- Messages = intentResponse.Messages.Select(x => (object)x).ToList()
+ Messages = intentResponse.Messages.Select(x => {
+ if (x.Type == AIResponseMessageType.Custom)
+ {
+ return (new
+ {
+ x.Type,
+ Payload = JObject.Parse(x.Payload)
+ }) as Object;
+ }
+ else
+ {
+ return (new { x.Type, x.Speech }) as Object;
+ }
+
+ }).ToList()
}
};
@@ -122,7 +169,7 @@ namespace Bot.Rasa.Consoles
// override if exists, otherwise add, delete if lifespan is zero
dc.DbTran(() =>
{
- var sessionContexts = dc.Table().Where(x => x.SessionId == rasa.SessionId).ToList();
+ var sessionContexts = dc.Table().Where(x => x.SessionId == rasa.AiConfig.SessionId).ToList();
// minus 1 round
sessionContexts.Where(x => !intentResponse.Contexts.Select(ctx => ctx.Name).Contains(x.Context))
@@ -148,7 +195,7 @@ namespace Bot.Rasa.Consoles
{
dc.Table().Add(new SessionContext
{
- SessionId = rasa.SessionId,
+ SessionId = rasa.AiConfig.SessionId,
Context = ctx.Name,
Lifespan = ctx.Lifespan
});
@@ -157,13 +204,27 @@ namespace Bot.Rasa.Consoles
});
aiResponse.Result.Contexts = dc.Table()
- .Where(x => x.SessionId == rasa.SessionId)
- .Select(x => new AIContext { Name = x.Context, Lifespan = x.Lifespan })
+ .Where(x => x.SessionId == rasa.AiConfig.SessionId)
+ .Select(x => new AIContext { Name = x.Context.ToLower(), Lifespan = x.Lifespan })
.ToArray();
return aiResponse;
}
+ private static IRestResponse CallRasa(string projectId, string text, string model)
+ {
+ var client = new RestClient($"{Database.Configuration.GetSection("Rasa:Host").Value}");
+
+ var rest = new RestRequest("parse", Method.POST);
+ string json = JsonConvert.SerializeObject(new { Project = projectId, Q = text, Model = model },
+ new JsonSerializerSettings
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver()
+ });
+ rest.AddParameter("application/json", json, ParameterType.RequestBody);
+
+ return client.Execute(rest);
+ }
///
/// Need two categories at least
///
@@ -176,19 +237,19 @@ namespace Bot.Rasa.Consoles
{
var corpus = console.agent.GrabCorpus(dc, request.Contexts);
- corpus.UserSays.Add(new UserSay
+ corpus.UserSays.Add(new RasaIntentExpression
{
Intent = "Welcome",
Text = "Hi"
});
- corpus.UserSays.Add(new UserSay
+ corpus.UserSays.Add(new RasaIntentExpression
{
Intent = "Welcome",
Text = "Hey"
});
- corpus.UserSays.Add(new UserSay
+ corpus.UserSays.Add(new RasaIntentExpression
{
Intent = "Welcome",
Text = "Hello"
@@ -200,7 +261,7 @@ namespace Bot.Rasa.Consoles
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
- var client = new RestClient($"{RasaAi.Options.HostUrl}");
+ var client = new RestClient($"{Database.Configuration.GetSection("Rasa:Host").Value}");
var rest = new RestRequest("train", Method.POST);
rest.AddQueryParameter("project", console.agent.Id);
rest.AddParameter("application/json", json, ParameterType.RequestBody);
diff --git a/Bot.Rasa/Entities/Entity.cs b/BotSharp.Core/Entities/Entity.cs
similarity index 94%
rename from Bot.Rasa/Entities/Entity.cs
rename to BotSharp.Core/Entities/Entity.cs
index 873561fc..80ecb7e2 100644
--- a/Bot.Rasa/Entities/Entity.cs
+++ b/BotSharp.Core/Entities/Entity.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Entities
+namespace BotSharp.Core.Entities
{
[Table("Bot_Entity")]
public class Entity : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Entities/EntityEntry.cs b/BotSharp.Core/Entities/EntityEntry.cs
similarity index 94%
rename from Bot.Rasa/Entities/EntityEntry.cs
rename to BotSharp.Core/Entities/EntityEntry.cs
index cab85188..69d392f6 100644
--- a/Bot.Rasa/Entities/EntityEntry.cs
+++ b/BotSharp.Core/Entities/EntityEntry.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Entities
+namespace BotSharp.Core.Entities
{
[Table("Bot_EntityEntry")]
public class EntityEntry : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Entities/EntityTypeExtension.cs b/BotSharp.Core/Entities/EntityTypeExtension.cs
similarity index 92%
rename from Bot.Rasa/Entities/EntityTypeExtension.cs
rename to BotSharp.Core/Entities/EntityTypeExtension.cs
index d05a26c6..12d6fde7 100644
--- a/Bot.Rasa/Entities/EntityTypeExtension.cs
+++ b/BotSharp.Core/Entities/EntityTypeExtension.cs
@@ -1,11 +1,11 @@
-using Bot.Rasa.Agents;
+using BotSharp.Core.Agents;
using EntityFrameworkCore.BootKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Entities
+namespace BotSharp.Core.Entities
{
public static class EntityTypeExtension
{
diff --git a/Bot.Rasa/Expressions/IntentExpressionPart.cs b/BotSharp.Core/Expressions/IntentExpressionPart.cs
similarity index 94%
rename from Bot.Rasa/Expressions/IntentExpressionPart.cs
rename to BotSharp.Core/Expressions/IntentExpressionPart.cs
index cdb01845..3d4d93c5 100644
--- a/Bot.Rasa/Expressions/IntentExpressionPart.cs
+++ b/BotSharp.Core/Expressions/IntentExpressionPart.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Expressions
+namespace BotSharp.Core.Expressions
{
[Table("Bot_IntentExpressionPart")]
public class IntentExpressionPart : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/ContextModelMapping.cs b/BotSharp.Core/Intents/ContextModelMapping.cs
similarity index 94%
rename from Bot.Rasa/Intents/ContextModelMapping.cs
rename to BotSharp.Core/Intents/ContextModelMapping.cs
index 331436e5..0d7cb37e 100644
--- a/Bot.Rasa/Intents/ContextModelMapping.cs
+++ b/BotSharp.Core/Intents/ContextModelMapping.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_ContextModelMapping")]
public class ContextModelMapping : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/Intent.cs b/BotSharp.Core/Intents/Intent.cs
similarity index 96%
rename from Bot.Rasa/Intents/Intent.cs
rename to BotSharp.Core/Intents/Intent.cs
index 7b7df918..75a218dc 100644
--- a/Bot.Rasa/Intents/Intent.cs
+++ b/BotSharp.Core/Intents/Intent.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
///
/// Intent Table
diff --git a/Bot.Rasa/Intents/IntentExpression.cs b/BotSharp.Core/Intents/IntentExpression.cs
similarity index 92%
rename from Bot.Rasa/Intents/IntentExpression.cs
rename to BotSharp.Core/Intents/IntentExpression.cs
index 0099a514..538d86b6 100644
--- a/Bot.Rasa/Intents/IntentExpression.cs
+++ b/BotSharp.Core/Intents/IntentExpression.cs
@@ -1,4 +1,4 @@
-using Bot.Rasa.Expressions;
+using BotSharp.Core.Expressions;
using EntityFrameworkCore.BootKit;
using Newtonsoft.Json;
using System;
@@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentExpression")]
public class IntentExpression : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/IntentExtension.cs b/BotSharp.Core/Intents/IntentExtension.cs
similarity index 87%
rename from Bot.Rasa/Intents/IntentExtension.cs
rename to BotSharp.Core/Intents/IntentExtension.cs
index 002990f6..de2fd96c 100644
--- a/Bot.Rasa/Intents/IntentExtension.cs
+++ b/BotSharp.Core/Intents/IntentExtension.cs
@@ -1,11 +1,11 @@
-using Bot.Rasa.Agents;
+using BotSharp.Core.Agents;
using EntityFrameworkCore.BootKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
public static class IntentExtension
{
diff --git a/Bot.Rasa/Intents/IntentInputContext.cs b/BotSharp.Core/Intents/IntentInputContext.cs
similarity index 93%
rename from Bot.Rasa/Intents/IntentInputContext.cs
rename to BotSharp.Core/Intents/IntentInputContext.cs
index 41fb966f..d00e86e2 100644
--- a/Bot.Rasa/Intents/IntentInputContext.cs
+++ b/BotSharp.Core/Intents/IntentInputContext.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentInputContext")]
public class IntentInputContext : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/IntentResponse.cs b/BotSharp.Core/Intents/IntentResponse.cs
similarity index 96%
rename from Bot.Rasa/Intents/IntentResponse.cs
rename to BotSharp.Core/Intents/IntentResponse.cs
index 2e26fb8f..0b373a1a 100644
--- a/Bot.Rasa/Intents/IntentResponse.cs
+++ b/BotSharp.Core/Intents/IntentResponse.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentResponse")]
public class IntentResponse : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/IntentResponseContext.cs b/BotSharp.Core/Intents/IntentResponseContext.cs
similarity index 94%
rename from Bot.Rasa/Intents/IntentResponseContext.cs
rename to BotSharp.Core/Intents/IntentResponseContext.cs
index 949d150e..21367b42 100644
--- a/Bot.Rasa/Intents/IntentResponseContext.cs
+++ b/BotSharp.Core/Intents/IntentResponseContext.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentResponseContext")]
public class IntentResponseContext : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/IntentResponseMessage.cs b/BotSharp.Core/Intents/IntentResponseMessage.cs
similarity index 93%
rename from Bot.Rasa/Intents/IntentResponseMessage.cs
rename to BotSharp.Core/Intents/IntentResponseMessage.cs
index 5186d244..06b97dbf 100644
--- a/Bot.Rasa/Intents/IntentResponseMessage.cs
+++ b/BotSharp.Core/Intents/IntentResponseMessage.cs
@@ -1,4 +1,4 @@
-using Bot.Rasa.Models;
+using BotSharp.Core.Models;
using EntityFrameworkCore.BootKit;
using System;
using System.Collections.Generic;
@@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentResponseMessage")]
public class IntentResponseMessage : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Intents/IntentResponseParameter.cs b/BotSharp.Core/Intents/IntentResponseParameter.cs
similarity index 95%
rename from Bot.Rasa/Intents/IntentResponseParameter.cs
rename to BotSharp.Core/Intents/IntentResponseParameter.cs
index 34284f09..e9a4153d 100644
--- a/Bot.Rasa/Intents/IntentResponseParameter.cs
+++ b/BotSharp.Core/Intents/IntentResponseParameter.cs
@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
-namespace Bot.Rasa.Intents
+namespace BotSharp.Core.Intents
{
[Table("Bot_IntentResponseParameter")]
public class IntentResponseParameter : DbRecord, IDbRecord
diff --git a/Bot.Rasa/Loader/DbInitializer.cs b/BotSharp.Core/Loader/DbInitializer.cs
similarity index 97%
rename from Bot.Rasa/Loader/DbInitializer.cs
rename to BotSharp.Core/Loader/DbInitializer.cs
index 9b311eff..642cf06f 100644
--- a/Bot.Rasa/Loader/DbInitializer.cs
+++ b/BotSharp.Core/Loader/DbInitializer.cs
@@ -4,7 +4,7 @@ using System.Linq;
using EntityFrameworkCore.BootKit;
using DotNetToolkit;
-namespace Bot.Rasa.Loader
+namespace BotSharp.Core.Loader
{
public class DbInitializer : IInitializationLoader
{
diff --git a/Bot.Rasa/Loader/IHookDbInitializer.cs b/BotSharp.Core/Loader/IHookDbInitializer.cs
similarity index 95%
rename from Bot.Rasa/Loader/IHookDbInitializer.cs
rename to BotSharp.Core/Loader/IHookDbInitializer.cs
index 420df8ea..30b854cd 100644
--- a/Bot.Rasa/Loader/IHookDbInitializer.cs
+++ b/BotSharp.Core/Loader/IHookDbInitializer.cs
@@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Loader
+namespace BotSharp.Core.Loader
{
///
/// Initialize data for modules
diff --git a/Bot.Rasa/Loader/IInitializationLoader.cs b/BotSharp.Core/Loader/IInitializationLoader.cs
similarity index 87%
rename from Bot.Rasa/Loader/IInitializationLoader.cs
rename to BotSharp.Core/Loader/IInitializationLoader.cs
index 746c2c92..9128bc87 100644
--- a/Bot.Rasa/Loader/IInitializationLoader.cs
+++ b/BotSharp.Core/Loader/IInitializationLoader.cs
@@ -1,6 +1,6 @@
using System.Text;
-namespace Bot.Rasa.Loader
+namespace BotSharp.Core.Loader
{
///
/// Implement a customzied loader
diff --git a/Bot.Rasa/Loader/InitializationLoader.cs b/BotSharp.Core/Loader/InitializationLoader.cs
similarity index 97%
rename from Bot.Rasa/Loader/InitializationLoader.cs
rename to BotSharp.Core/Loader/InitializationLoader.cs
index 153f4a64..393ede7d 100644
--- a/Bot.Rasa/Loader/InitializationLoader.cs
+++ b/BotSharp.Core/Loader/InitializationLoader.cs
@@ -5,7 +5,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Loader
+namespace BotSharp.Core.Loader
{
public class InitializationLoader
{
diff --git a/BotSharp.Core/Models/AIConfiguration.cs b/BotSharp.Core/Models/AIConfiguration.cs
new file mode 100644
index 00000000..80e48a80
--- /dev/null
+++ b/BotSharp.Core/Models/AIConfiguration.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace BotSharp.Core.Models
+{
+ public class AIConfiguration
+ {
+ private const string SERVICE_PROD_URL = "";
+ private const string SERVICE_DEV_URL = "";
+
+ private const string CURRENT_PROTOCOL_VERSION = "20190322";
+
+ public string ClientAccessToken { get; private set; }
+
+ public SupportedLanguage Language { get; set; }
+
+ public bool VoiceActivityDetectionEnabled { get; set; }
+
+ public string SessionId { get; set; }
+
+ ///
+ /// If true, will be used Testing API.AI server instead of Production server. This option for TESTING PURPOSES ONLY.
+ ///
+ public bool DevMode { get; set; }
+
+ ///
+ /// If true, all request and response content will be printed to the console. Use this option only FOR DEVELOPMENT.
+ ///
+ public bool DebugLog { get; set; }
+
+ string protocolVersion;
+ public string ProtocolVersion
+ {
+ get
+ {
+ return protocolVersion;
+ }
+ set
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ throw new ArgumentNullException("value");
+ }
+ protocolVersion = value;
+ }
+ }
+
+ public AIConfiguration(string clientAccessToken, SupportedLanguage language)
+ {
+ this.ClientAccessToken = clientAccessToken;
+ this.Language = language;
+
+ DevMode = false;
+ DebugLog = false;
+ VoiceActivityDetectionEnabled = true;
+
+ ProtocolVersion = CURRENT_PROTOCOL_VERSION;
+ }
+
+ public string RequestUrl
+ {
+ get
+ {
+ var baseUrl = DevMode ? SERVICE_DEV_URL : SERVICE_PROD_URL;
+ return string.Format("{0}{1}?v={2}", baseUrl, "query", ProtocolVersion);
+ }
+ }
+ }
+}
diff --git a/Bot.Rasa/Models/AIContext.cs b/BotSharp.Core/Models/AIContext.cs
similarity index 94%
rename from Bot.Rasa/Models/AIContext.cs
rename to BotSharp.Core/Models/AIContext.cs
index 997eed1e..f89ecfc8 100644
--- a/Bot.Rasa/Models/AIContext.cs
+++ b/BotSharp.Core/Models/AIContext.cs
@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Models
+namespace BotSharp.Core.Models
{
[JsonObject]
public class AIContext
diff --git a/Bot.Rasa/Models/AIRequest.cs b/BotSharp.Core/Models/AIRequest.cs
similarity index 79%
rename from Bot.Rasa/Models/AIRequest.cs
rename to BotSharp.Core/Models/AIRequest.cs
index 064697f1..b4bca325 100644
--- a/Bot.Rasa/Models/AIRequest.cs
+++ b/BotSharp.Core/Models/AIRequest.cs
@@ -3,24 +3,18 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Models
+namespace BotSharp.Core.Models
{
- [JsonObject]
public class AIRequest : QuestionMetadata
{
- [JsonProperty("query")]
public string[] Query { get; set; }
- [JsonProperty("confidence")]
public float[] Confidence { get; set; }
- [JsonProperty("contexts")]
public List Contexts { get; set; }
- [JsonProperty("resetContexts")]
public bool? ResetContexts { get; set; }
- [JsonProperty("originalRequest")]
public OriginalRequest OriginalRequest { get; set; }
public AIRequest()
@@ -32,6 +26,7 @@ namespace Bot.Rasa.Models
{
Query = new string[] { text };
Confidence = new float[] { 1.0f };
+ Contexts = new List();
}
public AIRequest(string text, RequestExtras requestExtras) : this(text)
diff --git a/Bot.Rasa/Models/AIResponse.cs b/BotSharp.Core/Models/AIResponse.cs
similarity index 95%
rename from Bot.Rasa/Models/AIResponse.cs
rename to BotSharp.Core/Models/AIResponse.cs
index 0350b45c..3bf8445c 100644
--- a/Bot.Rasa/Models/AIResponse.cs
+++ b/BotSharp.Core/Models/AIResponse.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Models
+namespace BotSharp.Core.Models
{
public class AIResponse
{
diff --git a/Bot.Rasa/Models/AIResponseCustomPayload.cs b/BotSharp.Core/Models/AIResponseCustomPayload.cs
similarity index 88%
rename from Bot.Rasa/Models/AIResponseCustomPayload.cs
rename to BotSharp.Core/Models/AIResponseCustomPayload.cs
index e769b6fe..57701442 100644
--- a/Bot.Rasa/Models/AIResponseCustomPayload.cs
+++ b/BotSharp.Core/Models/AIResponseCustomPayload.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Models
+namespace BotSharp.Core.Models
{
public class AIResponseCustomPayload : AIResponseMessageBase
{
diff --git a/Bot.Rasa/Models/AIResponseFulfillment.cs b/BotSharp.Core/Models/AIResponseFulfillment.cs
similarity index 67%
rename from Bot.Rasa/Models/AIResponseFulfillment.cs
rename to BotSharp.Core/Models/AIResponseFulfillment.cs
index 752573d8..ae94b54b 100644
--- a/Bot.Rasa/Models/AIResponseFulfillment.cs
+++ b/BotSharp.Core/Models/AIResponseFulfillment.cs
@@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Text;
-namespace Bot.Rasa.Models
+namespace BotSharp.Core.Models
{
public class AIResponseFulfillment
{
public string Speech { get; set; }
- public List