From 6c472545c0810ec7a073c6ad085804124f2611ef Mon Sep 17 00:00:00 2001 From: "haiping008@gmail.com" Date: Wed, 28 Mar 2018 17:08:49 -0500 Subject: [PATCH] Rename project --- Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj | 21 --- Bot.Rasa/Models/UserSay.cs | 19 --- Bot.UnitTest/AgentTest.cs | 53 ------- Bot.WebStarter/Bot.WebStarter.csproj | 2 +- Bot.WebStarter/Startup.cs | 6 +- Bot.WebStarter/settings.db.json | 2 +- .../Adapters/Dialogflow/DialogflowAgent.cs | 2 +- .../Adapters/Dialogflow/DialogflowEntity.cs | 2 +- .../Dialogflow/DialogflowEntityEntry.cs | 2 +- .../Adapters/Dialogflow/DialogflowIntent.cs | 4 +- .../Dialogflow/DialogflowIntentEvent.cs | 2 +- .../Dialogflow/DialogflowIntentExpression.cs | 2 +- .../DialogflowIntentExpressionPart.cs | 2 +- .../Dialogflow/DialogflowIntentResponse.cs | 6 +- .../DialogflowIntentResponseMessage.cs | 4 +- .../DialogflowIntentResponseParameter.cs | 2 +- {Bot.Rasa => BotSharp.Core}/Agents/Agent.cs | 16 +- .../Agents/AgentExtension.cs | 44 ++++-- .../BotSharp.Core.csproj | 13 +- .../Engines}/AgentImporterInDialogflow.cs | 12 +- .../Engines}/IAgentImporter.cs | 4 +- .../Engines}/RasaAi.cs | 29 ++-- .../Engines}/RasaOptions.cs | 2 +- .../Engines}/RequestExtension.cs | 145 +++++++++++++----- .../Entities/Entity.cs | 2 +- .../Entities/EntityEntry.cs | 2 +- .../Entities/EntityTypeExtension.cs | 4 +- .../Expressions/IntentExpressionPart.cs | 2 +- .../Intents/ContextModelMapping.cs | 2 +- {Bot.Rasa => BotSharp.Core}/Intents/Intent.cs | 2 +- .../Intents/IntentExpression.cs | 4 +- .../Intents/IntentExtension.cs | 4 +- .../Intents/IntentInputContext.cs | 2 +- .../Intents/IntentResponse.cs | 2 +- .../Intents/IntentResponseContext.cs | 2 +- .../Intents/IntentResponseMessage.cs | 4 +- .../Intents/IntentResponseParameter.cs | 2 +- .../Loader/DbInitializer.cs | 2 +- .../Loader/IHookDbInitializer.cs | 2 +- .../Loader/IInitializationLoader.cs | 2 +- .../Loader/InitializationLoader.cs | 2 +- BotSharp.Core/Models/AIConfiguration.cs | 70 +++++++++ .../Models/AIContext.cs | 2 +- .../Models/AIRequest.cs | 9 +- .../Models/AIResponse.cs | 2 +- .../Models/AIResponseCustomPayload.cs | 2 +- .../Models/AIResponseFulfillment.cs | 4 +- .../Models/AIResponseMessageBase.cs | 2 +- .../Models/AIResponseMessageType.cs | 2 +- .../Models/AIResponseMetadata.cs | 2 +- .../Models/AIResponseResult.cs | 4 +- .../Models/AIResponseStatus.cs | 2 +- .../Models/OriginalRequest.cs | 2 +- .../Models/QuestionMetadata.cs | 4 +- BotSharp.Core/Models/RasaIntentExpression.cs | 19 +++ .../Models/RasaIntentExpressionPart.cs | 14 ++ .../Models/RasaResponse.cs | 10 +- BotSharp.Core/Models/RasaResponseEntity.cs | 11 ++ .../Models/RasaTrainingData.cs | 4 +- .../Models/RequestExtras.cs | 4 +- BotSharp.Core/Models/SupportedLanguage.cs | 60 ++++++++ .../Sessions/SessionContext.cs | 2 +- .../AgentController.cs | 19 ++- BotSharp.RestApi/BotSharp.RestApi.csproj | 15 ++ .../EntityController.cs | 4 +- .../EntityDbContextBuilderExtensions.cs | 0 .../EntityItemController.cs | 2 +- .../EntityTypeController.cs | 6 +- .../EssentialController.cs | 4 +- .../InitLoaderBuilderExtensions.cs | 2 +- .../IntentController.cs | 6 +- BotSharp.UnitTest/AgentTest.cs | 64 ++++++++ .../BotSharp.UnitTest.csproj | 4 +- BotSharp.UnitTest/EntityTest.cs | 12 ++ BotSharp.UnitTest/IntentTest.cs | 28 ++++ .../TestEssential.cs | 18 +-- Bot.Rasa.sln => BotSharp.sln | 32 ++-- 77 files changed, 595 insertions(+), 290 deletions(-) delete mode 100644 Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj delete mode 100644 Bot.Rasa/Models/UserSay.cs delete mode 100644 Bot.UnitTest/AgentTest.cs rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowAgent.cs (88%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowEntity.cs (95%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowEntityEntry.cs (93%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntent.cs (90%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentEvent.cs (79%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentExpression.cs (86%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentExpressionPart.cs (87%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentResponse.cs (84%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentResponseMessage.cs (79%) rename {Bot.Rasa => BotSharp.Core}/Adapters/Dialogflow/DialogflowIntentResponseParameter.cs (89%) rename {Bot.Rasa => BotSharp.Core}/Agents/Agent.cs (65%) rename {Bot.Rasa => BotSharp.Core}/Agents/AgentExtension.cs (62%) rename Bot.Rasa/Bot.Rasa.csproj => BotSharp.Core/BotSharp.Core.csproj (77%) rename {Bot.Rasa/Consoles => BotSharp.Core/Engines}/AgentImporterInDialogflow.cs (96%) rename {Bot.Rasa/Consoles => BotSharp.Core/Engines}/IAgentImporter.cs (88%) rename {Bot.Rasa/Consoles => BotSharp.Core/Engines}/RasaAi.cs (72%) rename {Bot.Rasa/Consoles => BotSharp.Core/Engines}/RasaOptions.cs (91%) rename {Bot.Rasa/Consoles => BotSharp.Core/Engines}/RequestExtension.cs (60%) rename {Bot.Rasa => BotSharp.Core}/Entities/Entity.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Entities/EntityEntry.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Entities/EntityTypeExtension.cs (92%) rename {Bot.Rasa => BotSharp.Core}/Expressions/IntentExpressionPart.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Intents/ContextModelMapping.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Intents/Intent.cs (96%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentExpression.cs (92%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentExtension.cs (87%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentInputContext.cs (93%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentResponse.cs (96%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentResponseContext.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentResponseMessage.cs (93%) rename {Bot.Rasa => BotSharp.Core}/Intents/IntentResponseParameter.cs (95%) rename {Bot.Rasa => BotSharp.Core}/Loader/DbInitializer.cs (97%) rename {Bot.Rasa => BotSharp.Core}/Loader/IHookDbInitializer.cs (95%) rename {Bot.Rasa => BotSharp.Core}/Loader/IInitializationLoader.cs (87%) rename {Bot.Rasa => BotSharp.Core}/Loader/InitializationLoader.cs (97%) create mode 100644 BotSharp.Core/Models/AIConfiguration.cs rename {Bot.Rasa => BotSharp.Core}/Models/AIContext.cs (94%) rename {Bot.Rasa => BotSharp.Core}/Models/AIRequest.cs (79%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponse.cs (95%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseCustomPayload.cs (88%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseFulfillment.cs (67%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseMessageBase.cs (85%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseMessageType.cs (83%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseMetadata.cs (87%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseResult.cs (98%) rename {Bot.Rasa => BotSharp.Core}/Models/AIResponseStatus.cs (90%) rename {Bot.Rasa => BotSharp.Core}/Models/OriginalRequest.cs (90%) rename {Bot.Rasa => BotSharp.Core}/Models/QuestionMetadata.cs (88%) create mode 100644 BotSharp.Core/Models/RasaIntentExpression.cs create mode 100644 BotSharp.Core/Models/RasaIntentExpressionPart.cs rename {Bot.Rasa => BotSharp.Core}/Models/RasaResponse.cs (57%) create mode 100644 BotSharp.Core/Models/RasaResponseEntity.cs rename {Bot.Rasa => BotSharp.Core}/Models/RasaTrainingData.cs (65%) rename {Bot.Rasa => BotSharp.Core}/Models/RequestExtras.cs (95%) create mode 100644 BotSharp.Core/Models/SupportedLanguage.cs rename {Bot.Rasa => BotSharp.Core}/Sessions/SessionContext.cs (94%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/AgentController.cs (53%) create mode 100644 BotSharp.RestApi/BotSharp.RestApi.csproj rename {Bot.Rasa.RestApi => BotSharp.RestApi}/EntityController.cs (82%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/EntityDbContextBuilderExtensions.cs (100%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/EntityItemController.cs (89%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/EntityTypeController.cs (89%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/EssentialController.cs (94%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/InitLoaderBuilderExtensions.cs (94%) rename {Bot.Rasa.RestApi => BotSharp.RestApi}/IntentController.cs (86%) create mode 100644 BotSharp.UnitTest/AgentTest.cs rename Bot.UnitTest/Bot.UnitTest.csproj => BotSharp.UnitTest/BotSharp.UnitTest.csproj (88%) create mode 100644 BotSharp.UnitTest/EntityTest.cs create mode 100644 BotSharp.UnitTest/IntentTest.cs rename {Bot.UnitTest => BotSharp.UnitTest}/TestEssential.cs (68%) rename Bot.Rasa.sln => BotSharp.sln (50%) 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 Messages { get; set; } + public List Messages { get; set; } } } diff --git a/Bot.Rasa/Models/AIResponseMessageBase.cs b/BotSharp.Core/Models/AIResponseMessageBase.cs similarity index 85% rename from Bot.Rasa/Models/AIResponseMessageBase.cs rename to BotSharp.Core/Models/AIResponseMessageBase.cs index d7b70842..0b952be0 100644 --- a/Bot.Rasa/Models/AIResponseMessageBase.cs +++ b/BotSharp.Core/Models/AIResponseMessageBase.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class AIResponseMessageBase { diff --git a/Bot.Rasa/Models/AIResponseMessageType.cs b/BotSharp.Core/Models/AIResponseMessageType.cs similarity index 83% rename from Bot.Rasa/Models/AIResponseMessageType.cs rename to BotSharp.Core/Models/AIResponseMessageType.cs index 5c7e3f87..8c643889 100644 --- a/Bot.Rasa/Models/AIResponseMessageType.cs +++ b/BotSharp.Core/Models/AIResponseMessageType.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public enum AIResponseMessageType { diff --git a/Bot.Rasa/Models/AIResponseMetadata.cs b/BotSharp.Core/Models/AIResponseMetadata.cs similarity index 87% rename from Bot.Rasa/Models/AIResponseMetadata.cs rename to BotSharp.Core/Models/AIResponseMetadata.cs index 23fb1e1b..152c6c35 100644 --- a/Bot.Rasa/Models/AIResponseMetadata.cs +++ b/BotSharp.Core/Models/AIResponseMetadata.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class AIResponseMetadata { diff --git a/Bot.Rasa/Models/AIResponseResult.cs b/BotSharp.Core/Models/AIResponseResult.cs similarity index 98% rename from Bot.Rasa/Models/AIResponseResult.cs rename to BotSharp.Core/Models/AIResponseResult.cs index b59f2bd6..306c5735 100644 --- a/Bot.Rasa/Models/AIResponseResult.cs +++ b/BotSharp.Core/Models/AIResponseResult.cs @@ -1,4 +1,4 @@ -using Bot.Rasa.Intents; +using BotSharp.Core.Intents; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -7,7 +7,7 @@ using System.Globalization; using System.Linq; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class AIResponseResult { diff --git a/Bot.Rasa/Models/AIResponseStatus.cs b/BotSharp.Core/Models/AIResponseStatus.cs similarity index 90% rename from Bot.Rasa/Models/AIResponseStatus.cs rename to BotSharp.Core/Models/AIResponseStatus.cs index 5f14b284..025f793f 100644 --- a/Bot.Rasa/Models/AIResponseStatus.cs +++ b/BotSharp.Core/Models/AIResponseStatus.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class AIResponseStatus { diff --git a/Bot.Rasa/Models/OriginalRequest.cs b/BotSharp.Core/Models/OriginalRequest.cs similarity index 90% rename from Bot.Rasa/Models/OriginalRequest.cs rename to BotSharp.Core/Models/OriginalRequest.cs index c926edf3..5864e36b 100644 --- a/Bot.Rasa/Models/OriginalRequest.cs +++ b/BotSharp.Core/Models/OriginalRequest.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 OriginalRequest diff --git a/Bot.Rasa/Models/QuestionMetadata.cs b/BotSharp.Core/Models/QuestionMetadata.cs similarity index 88% rename from Bot.Rasa/Models/QuestionMetadata.cs rename to BotSharp.Core/Models/QuestionMetadata.cs index 6a3e398d..bbcb0ece 100644 --- a/Bot.Rasa/Models/QuestionMetadata.cs +++ b/BotSharp.Core/Models/QuestionMetadata.cs @@ -1,10 +1,10 @@ -using Bot.Rasa.Entities; +using BotSharp.Core.Entities; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { [JsonObject] public class QuestionMetadata diff --git a/BotSharp.Core/Models/RasaIntentExpression.cs b/BotSharp.Core/Models/RasaIntentExpression.cs new file mode 100644 index 00000000..621a962b --- /dev/null +++ b/BotSharp.Core/Models/RasaIntentExpression.cs @@ -0,0 +1,19 @@ +using BotSharp.Core.Expressions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core.Models +{ + public class RasaIntentExpression + { + public RasaIntentExpression() + { + Entities = new List(); + } + + public String Text { get; set; } + public String Intent { get; set; } + public List Entities { get; set; } + } +} diff --git a/BotSharp.Core/Models/RasaIntentExpressionPart.cs b/BotSharp.Core/Models/RasaIntentExpressionPart.cs new file mode 100644 index 00000000..d4c254c2 --- /dev/null +++ b/BotSharp.Core/Models/RasaIntentExpressionPart.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core.Models +{ + public class RasaIntentExpressionPart + { + public int Start { get; set; } + public int End { get; set; } + public String Value { get; set; } + public String Entity { get; set; } + } +} diff --git a/Bot.Rasa/Models/RasaResponse.cs b/BotSharp.Core/Models/RasaResponse.cs similarity index 57% rename from Bot.Rasa/Models/RasaResponse.cs rename to BotSharp.Core/Models/RasaResponse.cs index 441e3594..af3694e6 100644 --- a/Bot.Rasa/Models/RasaResponse.cs +++ b/BotSharp.Core/Models/RasaResponse.cs @@ -1,13 +1,19 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class RasaResponse { public RasaResponseIntent Intent { get; set; } + [JsonProperty("intent_ranking")] + public List IntentRanking { get; set; } + + public List Entities { get; set; } + public String Text { get; set; } } diff --git a/BotSharp.Core/Models/RasaResponseEntity.cs b/BotSharp.Core/Models/RasaResponseEntity.cs new file mode 100644 index 00000000..5914b260 --- /dev/null +++ b/BotSharp.Core/Models/RasaResponseEntity.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core.Models +{ + public class RasaResponseEntity : RasaIntentExpressionPart + { + public string Extractor { get; set; } + } +} diff --git a/Bot.Rasa/Models/RasaTrainingData.cs b/BotSharp.Core/Models/RasaTrainingData.cs similarity index 65% rename from Bot.Rasa/Models/RasaTrainingData.cs rename to BotSharp.Core/Models/RasaTrainingData.cs index 6629eff3..02a1ed55 100644 --- a/Bot.Rasa/Models/RasaTrainingData.cs +++ b/BotSharp.Core/Models/RasaTrainingData.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class RasaTrainingData { [JsonProperty("common_examples")] - public List UserSays { get; set; } + public List UserSays { get; set; } } } diff --git a/Bot.Rasa/Models/RequestExtras.cs b/BotSharp.Core/Models/RequestExtras.cs similarity index 95% rename from Bot.Rasa/Models/RequestExtras.cs rename to BotSharp.Core/Models/RequestExtras.cs index f0dc18a3..08a66e42 100644 --- a/Bot.Rasa/Models/RequestExtras.cs +++ b/BotSharp.Core/Models/RequestExtras.cs @@ -1,9 +1,9 @@ -using Bot.Rasa.Entities; +using BotSharp.Core.Entities; using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.Models +namespace BotSharp.Core.Models { public class RequestExtras { diff --git a/BotSharp.Core/Models/SupportedLanguage.cs b/BotSharp.Core/Models/SupportedLanguage.cs new file mode 100644 index 00000000..db09af18 --- /dev/null +++ b/BotSharp.Core/Models/SupportedLanguage.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.Core.Models +{ + public class SupportedLanguage + { + public static readonly SupportedLanguage English = new SupportedLanguage("en"); + public static readonly SupportedLanguage Russian = new SupportedLanguage("ru"); + public static readonly SupportedLanguage German = new SupportedLanguage("de"); + public static readonly SupportedLanguage Portuguese = new SupportedLanguage("pt"); + public static readonly SupportedLanguage PortugueseBrazil = new SupportedLanguage("pt-BR"); + public static readonly SupportedLanguage Spanish = new SupportedLanguage("es"); + public static readonly SupportedLanguage French = new SupportedLanguage("fr"); + public static readonly SupportedLanguage Italian = new SupportedLanguage("it"); + public static readonly SupportedLanguage Dutch = new SupportedLanguage("nl"); + public static readonly SupportedLanguage Japanese = new SupportedLanguage("ja"); + public static readonly SupportedLanguage ChineseChina = new SupportedLanguage("zh-CN"); + public static readonly SupportedLanguage ChineseHongKong = new SupportedLanguage("zh-HK"); + public static readonly SupportedLanguage ChineseTaiwan = new SupportedLanguage("zh-TW"); + + private static readonly SupportedLanguage[] AllLangs = + { + English, + Russian, + German, + Portuguese, + PortugueseBrazil, + Spanish, + French, + Italian, + Dutch, + Japanese, + ChineseChina, + ChineseHongKong, + ChineseTaiwan + }; + + public readonly string code; + + private SupportedLanguage(string code) + { + this.code = code; + } + + public static SupportedLanguage FromLanguageTag(string languageTag) + { + foreach (var item in AllLangs) + { + if (string.Equals(item.code, languageTag, StringComparison.OrdinalIgnoreCase)) + { + return item; + } + } + + return English; + } + } +} diff --git a/Bot.Rasa/Sessions/SessionContext.cs b/BotSharp.Core/Sessions/SessionContext.cs similarity index 94% rename from Bot.Rasa/Sessions/SessionContext.cs rename to BotSharp.Core/Sessions/SessionContext.cs index 26eb83e0..54b3704b 100644 --- a/Bot.Rasa/Sessions/SessionContext.cs +++ b/BotSharp.Core/Sessions/SessionContext.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text; -namespace Bot.Rasa.Sessions +namespace BotSharp.Core.Sessions { [Table("Bot_SessionContext")] public class SessionContext : DbRecord, IDbRecord diff --git a/Bot.Rasa.RestApi/AgentController.cs b/BotSharp.RestApi/AgentController.cs similarity index 53% rename from Bot.Rasa.RestApi/AgentController.cs rename to BotSharp.RestApi/AgentController.cs index 352ed178..97de12db 100644 --- a/Bot.Rasa.RestApi/AgentController.cs +++ b/BotSharp.RestApi/AgentController.cs @@ -1,5 +1,5 @@ -using Bot.Rasa.Agents; -using Bot.Rasa.Consoles; +using BotSharp.Core.Agents; +using BotSharp.Core.Engines; using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Mvc; using System; @@ -7,24 +7,29 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { public class AgentController : EssentialController { [HttpGet("id")] public Agent Get([FromRoute] String id) { - var console = new RasaAi(dc); - return console.LoadAgent(id); + var console = new RasaAi(dc, null); + return console.LoadAgent(); } + /// + /// New agent with basic configuration + /// + /// + /// [HttpPost] public String Create([FromBody] Agent agent) { - var console = new RasaAi(dc); + var rasa = new RasaAi(dc, null); dc.DbTran(() => { - console.SaveAgent(agent); + rasa.SaveAgent(agent); }); return agent.Id; diff --git a/BotSharp.RestApi/BotSharp.RestApi.csproj b/BotSharp.RestApi/BotSharp.RestApi.csproj new file mode 100644 index 00000000..9139d1e9 --- /dev/null +++ b/BotSharp.RestApi/BotSharp.RestApi.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.0 + + + + + + + + + + + diff --git a/Bot.Rasa.RestApi/EntityController.cs b/BotSharp.RestApi/EntityController.cs similarity index 82% rename from Bot.Rasa.RestApi/EntityController.cs rename to BotSharp.RestApi/EntityController.cs index 7aa9332d..7632aac8 100644 --- a/Bot.Rasa.RestApi/EntityController.cs +++ b/BotSharp.RestApi/EntityController.cs @@ -1,10 +1,10 @@ -using Bot.Rasa.Entities; +using BotSharp.Core.Entities; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { public class EntityController : EssentialController { diff --git a/Bot.Rasa.RestApi/EntityDbContextBuilderExtensions.cs b/BotSharp.RestApi/EntityDbContextBuilderExtensions.cs similarity index 100% rename from Bot.Rasa.RestApi/EntityDbContextBuilderExtensions.cs rename to BotSharp.RestApi/EntityDbContextBuilderExtensions.cs diff --git a/Bot.Rasa.RestApi/EntityItemController.cs b/BotSharp.RestApi/EntityItemController.cs similarity index 89% rename from Bot.Rasa.RestApi/EntityItemController.cs rename to BotSharp.RestApi/EntityItemController.cs index b4094dae..60c118e1 100644 --- a/Bot.Rasa.RestApi/EntityItemController.cs +++ b/BotSharp.RestApi/EntityItemController.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { public class EntityItemController : EssentialController { diff --git a/Bot.Rasa.RestApi/EntityTypeController.cs b/BotSharp.RestApi/EntityTypeController.cs similarity index 89% rename from Bot.Rasa.RestApi/EntityTypeController.cs rename to BotSharp.RestApi/EntityTypeController.cs index 4550aa3a..a140a204 100644 --- a/Bot.Rasa.RestApi/EntityTypeController.cs +++ b/BotSharp.RestApi/EntityTypeController.cs @@ -1,12 +1,12 @@ -using Bot.Rasa.Agents; -using Bot.Rasa.Entities; +using BotSharp.Core.Agents; +using BotSharp.Core.Entities; using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { public class EntityTypeController : EssentialController { diff --git a/Bot.Rasa.RestApi/EssentialController.cs b/BotSharp.RestApi/EssentialController.cs similarity index 94% rename from Bot.Rasa.RestApi/EssentialController.cs rename to BotSharp.RestApi/EssentialController.cs index c7db40c5..1c5b5491 100644 --- a/Bot.Rasa.RestApi/EssentialController.cs +++ b/BotSharp.RestApi/EssentialController.cs @@ -1,4 +1,4 @@ -using Bot.Rasa.Consoles; +using BotSharp.Core.Engines; using DotNetToolkit; using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Authorization; @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { //[Authorize] [Produces("application/json")] diff --git a/Bot.Rasa.RestApi/InitLoaderBuilderExtensions.cs b/BotSharp.RestApi/InitLoaderBuilderExtensions.cs similarity index 94% rename from Bot.Rasa.RestApi/InitLoaderBuilderExtensions.cs rename to BotSharp.RestApi/InitLoaderBuilderExtensions.cs index 9390668e..37cb336a 100644 --- a/Bot.Rasa.RestApi/InitLoaderBuilderExtensions.cs +++ b/BotSharp.RestApi/InitLoaderBuilderExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -using Bot.Rasa.Loader; +using BotSharp.Core.Loader; namespace Microsoft.AspNetCore.Builder { diff --git a/Bot.Rasa.RestApi/IntentController.cs b/BotSharp.RestApi/IntentController.cs similarity index 86% rename from Bot.Rasa.RestApi/IntentController.cs rename to BotSharp.RestApi/IntentController.cs index de1ec468..a8aae9c1 100644 --- a/Bot.Rasa.RestApi/IntentController.cs +++ b/BotSharp.RestApi/IntentController.cs @@ -1,11 +1,11 @@ -using Bot.Rasa.Agents; -using Bot.Rasa.Intents; +using BotSharp.Core.Agents; +using BotSharp.Core.Intents; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text; -namespace Bot.Rasa.RestApi +namespace BotSharp.Core.RestApi { public class IntentController : EssentialController { diff --git a/BotSharp.UnitTest/AgentTest.cs b/BotSharp.UnitTest/AgentTest.cs new file mode 100644 index 00000000..a1a59293 --- /dev/null +++ b/BotSharp.UnitTest/AgentTest.cs @@ -0,0 +1,64 @@ +using BotSharp.Core.Agents; +using BotSharp.Core.Engines; +using BotSharp.Core.Models; +using EntityFrameworkCore.BootKit; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BotSharp.UnitTest +{ + [TestClass] + public class AgentTest : TestEssential + { + [TestMethod] + public void CreateAgent() + { + var agent = new Agent + { + Id = BOT_ID, + Name = BOT_NAME, + Language = "en" + }; + var rasa = new RasaAi(dc); + + int row = dc.DbTran(() => rasa.SaveAgent(agent)); + } + + [TestMethod] + public void UpdateAgent() + { + var agent = new Agent + { + Id = BOT_ID, + Name = BOT_NAME, + Language = "en" + }; + var rasa = new RasaAi(dc); + + int row = dc.DbTran(() => rasa.SaveAgent(agent)); + } + + [TestMethod] + public void RestoreAgent() + { + var rasa = new RasaAi(dc); + var importer = new AgentImporterInDialogflow(); + + var agent = rasa.RestoreAgent(importer, BOT_NAME); + agent.Id = BOT_ID; + agent.ClientAccessToken = BOT_CLIENT_TOKEN; + agent.DeveloperAccessToken = BOT_DEVELOPER_TOKEN; + + int row = dc.DbTran(() => rasa.SaveAgent(agent)); + } + + [TestMethod] + public void Train() + { + var rasa = new RasaAi(dc); + } + } +} diff --git a/Bot.UnitTest/Bot.UnitTest.csproj b/BotSharp.UnitTest/BotSharp.UnitTest.csproj similarity index 88% rename from Bot.UnitTest/Bot.UnitTest.csproj rename to BotSharp.UnitTest/BotSharp.UnitTest.csproj index 4978c4ec..c0466d62 100644 --- a/Bot.UnitTest/Bot.UnitTest.csproj +++ b/BotSharp.UnitTest/BotSharp.UnitTest.csproj @@ -9,13 +9,13 @@ - + - + diff --git a/BotSharp.UnitTest/EntityTest.cs b/BotSharp.UnitTest/EntityTest.cs new file mode 100644 index 00000000..132f47fb --- /dev/null +++ b/BotSharp.UnitTest/EntityTest.cs @@ -0,0 +1,12 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.UnitTest +{ + [TestClass] + public class EntityTest : TestEssential + { + } +} diff --git a/BotSharp.UnitTest/IntentTest.cs b/BotSharp.UnitTest/IntentTest.cs new file mode 100644 index 00000000..4b1bfad1 --- /dev/null +++ b/BotSharp.UnitTest/IntentTest.cs @@ -0,0 +1,28 @@ +using BotSharp.Core.Engines; +using BotSharp.Core.Models; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BotSharp.UnitTest +{ + [TestClass] + public class IntentTest : TestEssential + { + [TestMethod] + public void TextRequest() + { + var config = new AIConfiguration(BOT_CLIENT_TOKEN, SupportedLanguage.English); + config.SessionId = Guid.NewGuid().ToString(); + + var rasa = new RasaAi(dc, config); + + var response = rasa.TextRequest(new AIRequest { Query = new String[] { "Create a work order for PetSmart" } }); + Assert.IsTrue(response.Result.Metadata.IntentName == "Create Work Order"); + + response = rasa.TextRequest(new AIRequest { Query = new String[] { "1010" } }); + Assert.IsTrue(response.Result.Metadata.IntentName == "Telling Store Number"); + } + } +} diff --git a/Bot.UnitTest/TestEssential.cs b/BotSharp.UnitTest/TestEssential.cs similarity index 68% rename from Bot.UnitTest/TestEssential.cs rename to BotSharp.UnitTest/TestEssential.cs index f5e7974c..49f3c5f5 100644 --- a/Bot.UnitTest/TestEssential.cs +++ b/BotSharp.UnitTest/TestEssential.cs @@ -1,4 +1,4 @@ -using Bot.Rasa.Consoles; +using BotSharp.Core.Engines; using EntityFrameworkCore.BootKit; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Configuration; @@ -6,10 +6,15 @@ using System; using System.IO; using System.Linq; -namespace Bot.UnitTest +namespace BotSharp.UnitTest { public abstract class TestEssential { + public static String BOT_ID = "2b6a288e-d891-40c6-96ce-6a0cf324545c"; + public static String BOT_CLIENT_TOKEN = "23a53c46d6244840bbb10c89c171d299"; + public static String BOT_DEVELOPER_TOKEN = "d86103f446d049ff8d5f506e8dfe5f3f"; + public static String BOT_NAME = "VirtualAssistant"; + protected Database dc { get; set; } protected string contentRoot; @@ -25,17 +30,10 @@ namespace Bot.UnitTest }); Database.Configuration = configurationBuilder.Build(); - Database.Assemblies = new String[] { "Bot.Rasa" }; + Database.Assemblies = new String[] { "BotSharp.Core" }; Database.ContentRootPath = contentRoot; dc = new DefaultDataContextLoader().GetDefaultDc(); - - RasaAi.Options = new RasaOptions - { - HostUrl = Database.Configuration.GetSection("Rasa:Host").Value, - ContentRootPath = contentRoot, - Assembles = new String[] { "Bot.Rasa" } - }; } } diff --git a/Bot.Rasa.sln b/BotSharp.sln similarity index 50% rename from Bot.Rasa.sln rename to BotSharp.sln index 7e984f0b..a8cf7971 100644 --- a/Bot.Rasa.sln +++ b/BotSharp.sln @@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Rasa", "Bot.Rasa\Bot.Rasa.csproj", "{8E57A9A5-EB37-4F83-93FE-3324A069B568}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.WebStarter", "Bot.WebStarter\Bot.WebStarter.csproj", "{ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.UnitTest", "Bot.UnitTest\Bot.UnitTest.csproj", "{90705625-1342-4ED8-A05B-46C720D20EE4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.UnitTest", "BotSharp.UnitTest\BotSharp.UnitTest.csproj", "{1C883AA3-9182-469A-A17E-697DCAAB0121}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Rasa.RestApi", "Bot.Rasa.RestApi\Bot.Rasa.RestApi.csproj", "{310EECBB-8B77-4F4A-A09C-6B5EED29155E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core", "BotSharp.Core\BotSharp.Core.csproj", "{95780673-2A1A-4953-962F-C46CBFDD07FF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot.WebStarter", "Bot.WebStarter\Bot.WebStarter.csproj", "{ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.RestApi", "BotSharp.RestApi\BotSharp.RestApi.csproj", "{A1DDFCE9-10A1-45AF-8F1C-DE0A9145BA48}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,22 +17,22 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8E57A9A5-EB37-4F83-93FE-3324A069B568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E57A9A5-EB37-4F83-93FE-3324A069B568}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E57A9A5-EB37-4F83-93FE-3324A069B568}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E57A9A5-EB37-4F83-93FE-3324A069B568}.Release|Any CPU.Build.0 = Release|Any CPU - {90705625-1342-4ED8-A05B-46C720D20EE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90705625-1342-4ED8-A05B-46C720D20EE4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {90705625-1342-4ED8-A05B-46C720D20EE4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {90705625-1342-4ED8-A05B-46C720D20EE4}.Release|Any CPU.Build.0 = Release|Any CPU - {310EECBB-8B77-4F4A-A09C-6B5EED29155E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {310EECBB-8B77-4F4A-A09C-6B5EED29155E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {310EECBB-8B77-4F4A-A09C-6B5EED29155E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {310EECBB-8B77-4F4A-A09C-6B5EED29155E}.Release|Any CPU.Build.0 = Release|Any CPU {ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}.Debug|Any CPU.Build.0 = Debug|Any CPU {ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}.Release|Any CPU.ActiveCfg = Release|Any CPU {ACBEB546-00AB-4EB7-8DBF-4BFF722FC9EA}.Release|Any CPU.Build.0 = Release|Any CPU + {1C883AA3-9182-469A-A17E-697DCAAB0121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C883AA3-9182-469A-A17E-697DCAAB0121}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C883AA3-9182-469A-A17E-697DCAAB0121}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C883AA3-9182-469A-A17E-697DCAAB0121}.Release|Any CPU.Build.0 = Release|Any CPU + {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}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95780673-2A1A-4953-962F-C46CBFDD07FF}.Release|Any CPU.Build.0 = Release|Any CPU + {A1DDFCE9-10A1-45AF-8F1C-DE0A9145BA48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1DDFCE9-10A1-45AF-8F1C-DE0A9145BA48}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1DDFCE9-10A1-45AF-8F1C-DE0A9145BA48}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1DDFCE9-10A1-45AF-8F1C-DE0A9145BA48}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE