add articulate ai platform

This commit is contained in:
Oceania2018 2019-03-16 11:34:32 -05:00
parent 870bd7a5a8
commit 0419396555
35 changed files with 1152 additions and 0 deletions

View file

@ -0,0 +1,170 @@
using BotSharp.Core;
using BotSharp.Core.Engines;
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Models;
using BotSharp.Platform.Models.AiRequest;
using BotSharp.Platform.Models.AiResponse;
using BotSharp.Platform.Models.Contexts;
using BotSharp.Platform.Models.Entities;
using DotNetToolkit;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate
{
/// <summary>
/// A platform for building conversational interfaces with intelligent agents (chatbots)
/// http://spg.ai/projects/articulate
/// This implementation takes over APIs of Articulate's 7500 port.
/// </summary>
public class ArticulateAi<TAgent> :
PlatformBuilderBase<TAgent>,
IPlatformBuilder<TAgent>
where TAgent : AgentModel
{
public ArticulateAi(IAgentStorageFactory<TAgent> agentStorageFactory, IContextStorageFactory<AIContext> contextStorageFactory, IPlatformSettings settings, IConfiguration config)
: base(agentStorageFactory, contextStorageFactory, settings)
{
}
public async Task<Tuple<TAgent, DomainModel>> GetAgentByDomainId(String domainId)
{
var results = await GetAllAgents();
foreach (TAgent agent in results)
{
var domain = agent.Domains.FirstOrDefault(x => x.Id == domainId);
if (domain != null)
{
return new Tuple<TAgent, DomainModel>(agent, domain);
}
}
return null;
}
public async Task<Tuple<TAgent, DomainModel, IntentModel>> GetAgentByIntentId(String intentId)
{
var results = await GetAllAgents();
foreach (TAgent agent in results)
{
foreach (DomainModel domain in agent.Domains)
{
var intent = domain.Intents.FirstOrDefault(x => x.Id == intentId);
if (intent != null)
{
return new Tuple<TAgent, DomainModel, IntentModel>(agent, domain, intent);
}
}
}
return null;
}
public async Task<List<IntentModel>> GetReferencedIntentsByEntity(string entityId)
{
var intents = new List<IntentModel>();
var allAgents = await GetAllAgents();
foreach (TAgent agent in allAgents)
{
foreach (DomainModel domain in agent.Domains)
{
foreach (IntentModel intent in domain.Intents)
{
if(intent.Examples.Exists(x => x.Entities.Exists(y => y.EntityId == entityId)))
{
intents.Add(intent);
}
}
}
}
return intents;
}
public async Task<TrainingCorpus> ExtractorCorpus(TAgent agent)
{
var corpus = new TrainingCorpus();
corpus.Entities = agent.Entities.Select(x => new TrainingEntity
{
Entity = x.EntityName,
Values = x.Examples.Select(y => new TrainingEntitySynonym
{
Value = y.Value,
Synonyms = y.Synonyms
}).ToList()
}).ToList();
corpus.UserSays = new List<TrainingIntentExpression<TrainingIntentExpressionPart>>();
foreach(DomainModel domain in agent.Domains)
{
foreach(IntentModel intent in domain.Intents)
{
foreach(IntentExampleModel example in intent.Examples)
{
var say = new TrainingIntentExpression<TrainingIntentExpressionPart>()
{
Intent = intent.IntentName,
Text = example.UserSays,
Entities = example.Entities.Select(x => new TrainingIntentExpressionPart
{
Entity = x.Entity,
Start = x.Start,
Value = x.Value
}).ToList()
};
corpus.UserSays.Add(say);
}
}
}
return corpus;
}
public override async Task<bool> SaveAgent(TAgent agent)
{
agent.Status = "Changed";
agent.LastTraining = DateTime.UtcNow;
return await base.SaveAgent(agent);
}
public async Task<AiResponse> TextRequest(AiRequest request)
{
var aiResponse = new AiResponse();
// Load agent
var projectPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", request.AgentId);
var model = Directory.GetDirectories(projectPath).Where(x => x.Contains("model_")).Last().Split(Path.DirectorySeparatorChar).Last();
var modelPath = Path.Combine(projectPath, model);
request.AgentDir = projectPath;
request.Model = model;
var agent = await GetAgentById(request.AgentId);
var preditor = new BotPredictor();
var doc = await preditor.Predict(agent, request);
var parameters = new Dictionary<String, Object>();
if (doc.Sentences[0].Entities == null)
{
doc.Sentences[0].Entities = new List<NlpEntity>();
}
doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value);
aiResponse.Intent = doc.Sentences[0].Intent.Label;
//aiResponse.Speech = aiResponse.Intent;
return aiResponse;
}
}
}

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BotSharp\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,76 @@
using BotSharp.Core;
using BotSharp.Core.Engines;
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Articulate.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class AgentController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
/// <summary>
/// Initialize agent controller and get a platform instance
/// </summary>
/// <param name="platform"></param>
public AgentController(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpPost]
public async Task<AgentModel> PostAgent()
{
AgentModel agent = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
agent = JsonConvert.DeserializeObject<AgentModel>(body);
}
// convert to standard Agent structure
agent.Id = new Random().Next(Int32.MaxValue).ToString();
agent.Name = agent.AgentName;
await builder.SaveAgent(agent);
return agent;
}
[HttpGet]
public async Task<List<AgentModel>> GetAgent()
{
var results = await builder.GetAllAgents();
var agents = results.ToList();
return agents;
}
[HttpGet("{agentId}")]
public async Task<AgentModel> GetAgentById([FromRoute] string agentId)
{
var agent = await builder.GetAgentById(agentId);
return agent;
}
[HttpGet("name/{agentName}")]
public async Task<AgentModel> GetAgentByName([FromRoute] string agentName)
{
var agent = await builder.GetAgentByName(agentName);
return agent;
}
}
}

View file

@ -0,0 +1,66 @@
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Articulate.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class DomainController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public DomainController(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpGet("{domainId}")]
public async Task<DomainModel> GetDomain([FromRoute] int domainId)
{
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
var dataPath = Directory.GetFiles(dataDir).FirstOrDefault(x => Regex.IsMatch(x, $"-domain-{domainId}.json"));
string json = System.IO.File.ReadAllText(dataPath);
var domain = JsonConvert.DeserializeObject<DomainModel>(json);
return domain;
}
[HttpPost]
public async Task<DomainModel> PostDomain()
{
DomainModel domain = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
domain = JsonConvert.DeserializeObject<DomainModel>(body);
}
var agent = await builder.GetAgentByName(domain.Agent);
domain.Id = Guid.NewGuid().ToString();
(agent as AgentModel).Domains.Add(domain);
await builder.SaveAgent(agent);
return domain;
}
[HttpGet("/agent/{agentId}/domain")]
public async Task<DomainPageViewModel> GetAgentDomains([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
{
var agent = await builder.GetAgentById(agentId);
return new DomainPageViewModel { Domains = agent.Domains, Total = agent.Domains.Count };
}
}
}

View file

@ -0,0 +1,66 @@
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Articulate.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class EntityController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public EntityController(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpGet("{entityId}")]
public async Task<EntityModel> GetEntity([FromRoute] string entityId)
{
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
string dataPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.EndsWith($"-entity-{entityId}.json"));
string json = System.IO.File.ReadAllText(dataPath);
var entity = JsonConvert.DeserializeObject<EntityModel>(json);
return entity;
}
[HttpGet("/agent/{agentId}/entity")]
public async Task<EntityPageViewModel> GetAgentEntities([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
{
var agent = await builder.GetAgentById(agentId);
return new EntityPageViewModel { Entities = agent.Entities.Select(x => x as EntityModel).ToList(), Total = agent.Entities.Count };
}
[HttpPost]
public async Task<EntityModel> PostEntity()
{
EntityModel entity = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
entity = JsonConvert.DeserializeObject<EntityModel>(body);
}
var agent = await builder.GetAgentByName(entity.Agent);
entity.Id = Guid.NewGuid().ToString();
agent.Entities.Add(entity);
await builder.SaveAgent(agent);
return entity;
}
}
}

View file

@ -0,0 +1,129 @@
using BotSharp.Core;
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Articulate.ViewModels;
using BotSharp.Platform.Models;
using DotNetToolkit;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class IntentController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public IntentController(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpGet("{intentId}")]
public async Task<IntentViewModel> GetIntent([FromRoute] string intentId)
{
var agent = await builder.GetAgentByIntentId(intentId);
return agent.Item3.ToObject<IntentViewModel>();
}
[HttpPost]
public async Task<IntentViewModel> PostIntent()
{
IntentViewModel intent = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
intent = JsonConvert.DeserializeObject<IntentViewModel>(body);
}
var agent = await builder.GetAgentByName(intent.Agent);
intent.Id = Guid.NewGuid().ToString();
var domain = agent.Domains.First(x => x.DomainName == intent.Domain);
domain.Intents.Add(intent.ToObject<IntentModel>());
await builder.SaveAgent(agent);
return intent;
}
[HttpPut("{intentId}")]
public async Task<IntentViewModel> PutIntent([FromRoute] string intentId)
{
IntentViewModel intent = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
intent = JsonConvert.DeserializeObject<IntentViewModel>(body);
}
var agent = await builder.GetAgentByIntentId(intentId);
var updateAgent = agent.Item1;
var updateIntents = updateAgent.Domains.First(x => x.Id == agent.Item2.Id).Intents;
var updateIntent = updateIntents.First(x => x.Id == agent.Item3.Id);
updateIntent.IntentName = intent.IntentName;
updateIntent.Examples = intent.Examples;
await builder.SaveAgent(updateAgent);
return intent;
}
[HttpGet("{intentId}/webhook")]
public async Task GetIntentWebhook([FromRoute] string intentId)
{
}
[HttpGet("{intentId}/postFormat")]
public async Task GetIntentPostFormat([FromRoute] string intentId)
{
}
[HttpGet("/agent/{agentId}/intent")]
public async Task<IntentPageViewModel> GetAgentIntents([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
{
var intents = new List<IntentViewModel>();
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
var agentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-intent-")).ToList();
for (int i = 0; i < agentPaths.Count; i++)
{
string json = System.IO.File.ReadAllText(agentPaths[i]);
var intent = JsonConvert.DeserializeObject<IntentViewModel>(json);
intents.Add(intent);
}
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
}
[HttpGet("/entity/{entityId}/intent")]
public async Task<List<IntentViewModel>> GetReferencedIntentsByEntity([FromRoute] string entityId, [FromQuery] int start, [FromQuery] int limit)
{
var models = await builder.GetReferencedIntentsByEntity(entityId);
return models.Select(x => x.ToObject<IntentViewModel>()).ToList();
}
[HttpGet("/domain/{domainId}/intent")]
public async Task<IntentPageViewModel> GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit)
{
var agent = await builder.GetAgentByDomainId(domainId);
var intents = agent.Item2.Intents.Select(x => x.ToObject<IntentViewModel>()).ToList();
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
}
}
}

View file

@ -0,0 +1,45 @@
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Articulate.ViewModels;
using BotSharp.Platform.Models.AiRequest;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Console = Colorful.Console;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class ParseControllercs : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public ParseControllercs(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpGet("/agent/{agentId}/converse")]
public async Task<ActionResult> ParseText([FromRoute] string agentId, [FromQuery] string text, [FromQuery] string sessionId)
{
var response = new ResponseViewModel();
Console.WriteLine($"Got message from {Request.Host}: {text}", Color.Green);
var aiResponse = await builder.TextRequest(new AiRequest
{
AgentId = agentId,
Text = text
});
response.TextResponse = aiResponse.Text;
return Ok(response);
}
}
}

View file

@ -0,0 +1,64 @@
using BotSharp.Core;
using BotSharp.Platform.Articulate.Models;
using DotNetToolkit;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class ScenarioController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public ScenarioController(ArticulateAi<AgentModel> platform)
{
builder = platform;
}
[HttpGet("/intent/{intentId}/scenario")]
public async Task<IntentScenarioViewModel> GetIntentScenario([FromRoute] string intentId)
{
var agent = await builder.GetAgentByIntentId(intentId);
var view = agent.Item3.Scenario.ToObject<IntentScenarioViewModel>();
view.Agent = agent.Item1.AgentName;
view.Domain = agent.Item2.DomainName;
view.Intent = agent.Item3.IntentName;
return view;
}
[HttpPost("/intent/{intentId}/scenario")]
public async Task<IntentScenarioViewModel> PostIntentScenario()
{
IntentScenarioViewModel scenario = null;
using (var reader = new StreamReader(Request.Body))
{
string body = reader.ReadToEnd();
scenario = JsonConvert.DeserializeObject<IntentScenarioViewModel>(body);
}
scenario.Id = Guid.NewGuid().ToString();
var agent = await builder.GetAgentByName(scenario.Agent);
var domain = agent.Domains.FirstOrDefault(x => x.DomainName == scenario.Domain);
var intent = domain.Intents.FirstOrDefault(x => x.IntentName == scenario.Intent);
intent.Scenario = scenario.ToObject<ScenarioModel>();
await builder.SaveAgent(agent);
return scenario;
}
}
}

View file

@ -0,0 +1,52 @@
using BotSharp.Platform.Articulate.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class SettingsController : ControllerBase
{
[HttpGet]
public async Task<SettingsModel> GetSettings()
{
string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json");
string json = System.IO.File.ReadAllText(dataPath);
var settings = JsonConvert.DeserializeObject<SettingsModel>(json);
return settings;
}
[HttpGet("/agent/{agentId}/settings")]
public async Task<SettingsModel> GetSettingsByAgent([FromRoute] string agentId)
{
string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json");
string json = System.IO.File.ReadAllText(dataPath);
var settings = JsonConvert.DeserializeObject<SettingsModel>(json);
return settings;
}
[HttpPut("/agent/{agentId}/settings")]
public async Task<SettingsModel> PutSettingsByAgent([FromRoute] string agentId)
{
string dataPath = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate", "settings.json");
string json = System.IO.File.ReadAllText(dataPath);
var settings = JsonConvert.DeserializeObject<SettingsModel>(json);
return settings;
}
}
}

View file

@ -0,0 +1,38 @@
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace BotSharp.Platform.Articulate.Controllers
{
[Route("[controller]")]
public class TrainController : ControllerBase
{
private ArticulateAi<AgentModel> builder;
public TrainController(ArticulateAi<AgentModel> articulateAi)
{
builder = articulateAi;
}
[HttpGet("/agent/{agentId}/train")]
public async Task<AgentModel> TrainAgent([FromRoute] string agentId)
{
var agent = await builder.GetAgentById(agentId);
var corpus = await builder.ExtractorCorpus(agent);
await builder.Train(agent, corpus, new BotTrainOptions { });
agent.Status = "Ready";
await builder.SaveAgent(agent);
return agent;
}
}
}

View file

@ -0,0 +1,41 @@
using BotSharp.Platform.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class AgentModel : AgentBase
{
public AgentModel()
{
Domains = new List<DomainModel>();
Entities = new List<EntityModel>();
}
public string Status { get; set; }
public string Timezone { get; set; }
public string AgentName { get; set; }
public bool UseWebhook { get; set; }
public bool UsePostFormat { get; set; }
public bool ExtraTrainingData { get; set; }
public List<String> FallbackResponses { get; set; }
public bool EnableModelsPerDomain { get; set; }
public decimal DomainClassifierThreshold { get; set; }
public List<DomainModel> Domains { get; set; }
public List<EntityModel> Entities { get; set; }
public DateTime LastTraining { get; set; }
}
}

View file

@ -0,0 +1,31 @@
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class DomainModel
{
public DomainModel()
{
Intents = new List<IntentModel>();
}
public string Id { get; set; }
public string Agent { get; set; }
public string DomainName { get; set; }
public bool Enabled { get; set; }
public bool ExtraTrainingData { get; set; }
public decimal IntentThreshold { get; set; }
public string Status { get; set; }
public List<IntentModel> Intents { get; set; }
}
}

View file

@ -0,0 +1,23 @@
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class EntityModel : EntityBase
{
public string Regex { get; set; }
public string Agent { get; set; }
public string EntityName { get; set; }
public string Type { get; set; }
public string UiColor { get; set; }
public List<EntitySynonymModel> Examples { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class EntitySynonymModel
{
public string Value { get; set; }
public List<String> Synonyms { get; set; }
}
}

View file

@ -0,0 +1,20 @@
using BotSharp.Core.Engines;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class IntentExampleModel
{
public string UserSays { get; set; }
public List<ArticulateTrainingIntentExpressionPart> Entities { get; set; }
}
public class ArticulateTrainingIntentExpressionPart : TrainingIntentExpressionPart
{
public string EntityId { get; set; }
}
}

View file

@ -0,0 +1,31 @@
using BotSharp.Platform.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class IntentModel : IntentBase
{
public string IntentName { get; set; }
public string Agent { get; set; }
public string Domain { get; set; }
public bool UsePostFormat { get; set; }
public bool UseWebhook { get; set; }
/// <summary>
/// User says
/// </summary>
public List<IntentExampleModel> Examples { get; set; }
/// <summary>
/// Intent responses
/// </summary>
public ScenarioModel Scenario { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class LanguageModel
{
public string Text { get; set; }
public string Value { get; set; }
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class PipelineModel
{
public string Name { get; set; }
}
}

View file

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class ScenarioModel
{
/// <summary>
/// Guid
/// </summary>
[StringLength(36)]
public String Id { get; set; }
public string ScenarioName { get; set; }
public List<String> IntentResponses { get; set; }
public List<SlotModel> Slots { get; set; }
}
}

View file

@ -0,0 +1,38 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class SettingsModel
{
public string DucklingURL { get; set; }
public string UiLanguage { get; set; }
public string DefaultAgentLanguage { get; set; }
public string DefaultTimezone { get; set; }
public List<String> Timezones { get; set; }
public List<PipelineModel> DomainClassifierPipeline { get; set; }
public List<PipelineModel> IntentClassifierPipeline { get; set; }
public List<String> DucklingDimension { get; set; }
public List<PipelineModel> EntityClassifierPipeline { get; set; }
public List<String> DefaultAgentFallbackResponses { get; set; }
public string RasaURL { get; set; }
public List<String> SpacyPretrainedEntities { get; set; }
public List<LanguageModel> AgentLanguages { get; set; }
public List<LanguageModel> UiLanguages { get; set; }
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class SlotModel
{
public string Entity { get; set; }
public bool IsList { get; set; }
public bool IsRequired { get; set; }
public string SlotName { get; set; }
public List<String> TextPrompts { get; set; }
}
}

View file

@ -0,0 +1,29 @@
using BotSharp.Core;
using BotSharp.Core.AgentStorage;
using BotSharp.Core.Modules;
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Articulate.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
namespace BotSharp.Platform.Articulate
{
public class ModuleInjector : IModule
{
public void ConfigureServices(IServiceCollection services, IConfiguration config)
{
services.AddSingleton<ArticulateAi<AgentModel>>();
AgentStorageServiceRegister.Register<AgentModel>(services);
PlatformConfigServiceRegister.Register<PlatformSettings>("articulateAi", services, config);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
}
}
}

View file

@ -0,0 +1,11 @@
using BotSharp.Core;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate
{
public class PlatformSettings : PlatformSettingsBase
{
}
}

View file

@ -0,0 +1,2 @@
# botsharp-articulate
BotSharp platform emulator extension which is compatible with Articulate AI.

View file

@ -0,0 +1,14 @@
using BotSharp.Platform.Articulate.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.ViewModels
{
public class DomainPageViewModel
{
public List<DomainModel> Domains { get; set; }
public int Total { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using BotSharp.Platform.Articulate.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.ViewModels
{
public class EntityPageViewModel
{
public List<EntityModel> Entities { get; set; }
public int Total { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.ViewModels
{
public class IntentPageViewModel
{
public List<IntentViewModel> Intents { get; set; }
public int Total { get; set; }
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.Models
{
public class IntentScenarioViewModel : ScenarioModel
{
public string Domain { get; set; }
public string Agent { get; set; }
public string Intent { get; set; }
}
}

View file

@ -0,0 +1,23 @@
using BotSharp.Platform.Articulate.Models;
using BotSharp.Platform.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.ViewModels
{
public class IntentViewModel : IntentBase
{
public string IntentName { get; set; }
public string Agent { get; set; }
public string Domain { get; set; }
public bool UsePostFormat { get; set; }
public bool UseWebhook { get; set; }
public List<IntentExampleModel> Examples { get; set; }
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Platform.Articulate.ViewModels
{
public class ResponseViewModel
{
public string TextResponse { get; set; }
}
}

View file

@ -90,6 +90,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\BotSharp.Channel.FacebookMessenger\BotSharp.Channel.FacebookMessenger.csproj" /> <ProjectReference Include="..\BotSharp.Channel.FacebookMessenger\BotSharp.Channel.FacebookMessenger.csproj" />
<ProjectReference Include="..\BotSharp.Channel.Weixin\BotSharp.Channel.Weixin.csproj" /> <ProjectReference Include="..\BotSharp.Channel.Weixin\BotSharp.Channel.Weixin.csproj" />
<ProjectReference Include="..\BotSharp.Platform.Articulate\BotSharp.Platform.Articulate.csproj" />
<ProjectReference Include="..\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj" /> <ProjectReference Include="..\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj" />
<ProjectReference Include="..\BotSharp.Platform.OwnThink\BotSharp.Platform.OwnThink.csproj" /> <ProjectReference Include="..\BotSharp.Platform.OwnThink\BotSharp.Platform.OwnThink.csproj" />
<ProjectReference Include="..\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj" /> <ProjectReference Include="..\BotSharp.Platform.Rasa\BotSharp.Platform.Rasa.csproj" />

View file

@ -18,6 +18,10 @@
"Name": "OwnThink", "Name": "OwnThink",
"Type": "BotSharp.Platform.OwnThink" "Type": "BotSharp.Platform.OwnThink"
}, },
{
"Name": "Articulate",
"Type": "BotSharp.Platform.Articulate"
},
{ {
"Name": "WeixinChannel", "Name": "WeixinChannel",
"Type": "BotSharp.Channel.Weixin" "Type": "BotSharp.Channel.Weixin"

View file

@ -0,0 +1,9 @@
{
// if you want to override platform setting, please set corresponding value,
// otherwise you don't need this section.
"articulateAi": {
"botEngine": "BotSharpNLU",
"agentStorage": "AgentStorageInFile",
"contextStorage": "ContextStorageInFile"
}
}

View file

@ -0,0 +1,9 @@
{
// if you want to override platform setting, please set corresponding value,
// otherwise you don't need this section.
"rasaAi": {
"botEngine": "BotSharpNLU",
"agentStorage": "AgentStorageInFile",
"contextStorage": "ContextStorageInFile"
}
}

View file

@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Rasa", "B
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Platform.OwnThink", "BotSharp.Platform.OwnThink\BotSharp.Platform.OwnThink.csproj", "{96820DD6-0806-40A3-943A-7F2EF69E8EDB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Platform.OwnThink", "BotSharp.Platform.OwnThink\BotSharp.Platform.OwnThink.csproj", "{96820DD6-0806-40A3-943A-7F2EF69E8EDB}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Articulate", "BotSharp.Platform.Articulate\BotSharp.Platform.Articulate.csproj", "{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -91,6 +93,14 @@ Global
{96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|Any CPU.Build.0 = Release|Any CPU {96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|Any CPU.Build.0 = Release|Any CPU
{96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|x64.ActiveCfg = Release|Any CPU {96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|x64.ActiveCfg = Release|Any CPU
{96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|x64.Build.0 = Release|Any CPU {96820DD6-0806-40A3-943A-7F2EF69E8EDB}.Release|x64.Build.0 = Release|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Debug|x64.ActiveCfg = Debug|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Debug|x64.Build.0 = Debug|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Release|Any CPU.Build.0 = Release|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Release|x64.ActiveCfg = Release|Any CPU
{7290AC89-88DE-4CF8-946A-A1BB0E4C30EB}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE