articulate integration in progress.
This commit is contained in:
parent
a06745ffb0
commit
5fc98cc327
|
|
@ -25,13 +25,6 @@ namespace BotSharp.Platform.Abstraction
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
StandardAgent StandardizeAgent(TAgent agent);
|
StandardAgent StandardizeAgent(TAgent agent);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Recover standard agent to specific agent format
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="agent"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
TAgent RecoverAgent(StandardAgent agent);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BotSharp.Platform.Models
|
namespace BotSharp.Platform.Models
|
||||||
{
|
{
|
||||||
public abstract class EntityBase
|
public abstract class EntityBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Guid
|
||||||
|
/// </summary>
|
||||||
|
[StringLength(36)]
|
||||||
|
public String Id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using BotSharp.Platform.Models;
|
||||||
using Platform.Articulate.Models;
|
using Platform.Articulate.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Platform.Articulate
|
namespace Platform.Articulate
|
||||||
|
|
@ -20,19 +21,40 @@ namespace Platform.Articulate
|
||||||
{
|
{
|
||||||
public DialogRequestOptions RequestOptions { get; set; }
|
public DialogRequestOptions RequestOptions { get; set; }
|
||||||
|
|
||||||
public TAgent RecoverAgent(StandardAgent agent)
|
public Tuple<TAgent, DomainModel> GetAgentByDomainId(String domainId)
|
||||||
{
|
{
|
||||||
if (agent == null) return default(TAgent);
|
var results = GetAllAgents();
|
||||||
|
|
||||||
var agent1 = new AgentModel
|
foreach (TAgent agent in results)
|
||||||
{
|
{
|
||||||
Id = agent.Id,
|
var domain = (agent as AgentModel).Domains.FirstOrDefault(x => x.Id == domainId);
|
||||||
Name = agent.Name,
|
|
||||||
Description = agent.Description,
|
|
||||||
Language = agent.Language
|
|
||||||
};
|
|
||||||
|
|
||||||
return (TAgent)(agent1 as Object);
|
if (domain != null)
|
||||||
|
{
|
||||||
|
return new Tuple<TAgent, DomainModel>(agent, domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tuple<TAgent, DomainModel, IntentModel> GetAgentByIntentId(String intentId)
|
||||||
|
{
|
||||||
|
var results = GetAllAgents();
|
||||||
|
|
||||||
|
foreach (TAgent agent in results)
|
||||||
|
{
|
||||||
|
foreach (DomainModel domain in (agent as AgentModel).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 StandardAgent StandardizeAgent(TAgent specificAgent)
|
public StandardAgent StandardizeAgent(TAgent specificAgent)
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ namespace Platform.Articulate.Controllers
|
||||||
public DomainPageViewModel GetAgentDomains([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
public DomainPageViewModel GetAgentDomains([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||||
{
|
{
|
||||||
var agent = builder.GetAgentById(agentId);
|
var agent = builder.GetAgentById(agentId);
|
||||||
|
|
||||||
|
|
||||||
return new DomainPageViewModel { /*Domains = agent.d, Total = domains.Count*/ };
|
return new DomainPageViewModel { Domains = agent.Domains, Total = agent.Domains.Count };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,8 @@ namespace Platform.Articulate.Controllers
|
||||||
[HttpGet("/agent/{agentId}/entity")]
|
[HttpGet("/agent/{agentId}/entity")]
|
||||||
public EntityPageViewModel GetAgentEntities([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
public EntityPageViewModel GetAgentEntities([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||||
{
|
{
|
||||||
var entities = new List<EntityModel>();
|
var agent = builder.GetAgentById(agentId);
|
||||||
|
return new EntityPageViewModel { Entities = agent.Entities.Select(x => x as EntityModel).ToList(), Total = agent.Entities.Count };
|
||||||
return new EntityPageViewModel { Entities = entities, Total = entities.Count };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -57,7 +56,7 @@ namespace Platform.Articulate.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var agent = builder.GetAgentByName(entity.Agent);
|
var agent = builder.GetAgentByName(entity.Agent);
|
||||||
|
entity.Id = Guid.NewGuid().ToString();
|
||||||
agent.Entities.Add(entity);
|
agent.Entities.Add(entity);
|
||||||
|
|
||||||
builder.SaveAgent(agent);
|
builder.SaveAgent(agent);
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,9 @@ namespace Platform.Articulate.Controllers
|
||||||
[HttpGet("{intentId}")]
|
[HttpGet("{intentId}")]
|
||||||
public IntentModel GetIntent([FromRoute] string intentId)
|
public IntentModel GetIntent([FromRoute] string intentId)
|
||||||
{
|
{
|
||||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
var agent = builder.GetAgentByIntentId(intentId);
|
||||||
|
|
||||||
string dataPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.EndsWith($"-intent-{intentId}.json"));
|
return agent.Item3;
|
||||||
|
|
||||||
string json = System.IO.File.ReadAllText(dataPath);
|
|
||||||
|
|
||||||
var intent = JsonConvert.DeserializeObject<IntentModel>(json);
|
|
||||||
|
|
||||||
return intent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -56,20 +50,6 @@ namespace Platform.Articulate.Controllers
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{intentId}/scenario")]
|
|
||||||
public IntentScenarioViewModel GetIntentScenario([FromRoute] string intentId)
|
|
||||||
{
|
|
||||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
|
||||||
|
|
||||||
string dataPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.Contains($"-intent-{intentId}-scenario-"));
|
|
||||||
|
|
||||||
string json = System.IO.File.ReadAllText(dataPath);
|
|
||||||
|
|
||||||
var scenario = JsonConvert.DeserializeObject<IntentScenarioViewModel>(json);
|
|
||||||
|
|
||||||
return scenario;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{intentId}/webhook")]
|
[HttpGet("{intentId}/webhook")]
|
||||||
public void GetIntentWebhook([FromRoute] string intentId)
|
public void GetIntentWebhook([FromRoute] string intentId)
|
||||||
{
|
{
|
||||||
|
|
@ -137,10 +117,8 @@ namespace Platform.Articulate.Controllers
|
||||||
[HttpGet("/domain/{domainId}/intent")]
|
[HttpGet("/domain/{domainId}/intent")]
|
||||||
public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit)
|
public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit)
|
||||||
{
|
{
|
||||||
var intents = new List<IntentModel>();
|
var agent = builder.GetAgentByDomainId(domainId);
|
||||||
|
var intents = agent.Item2.Intents.Select(x => x as IntentModel).ToList();
|
||||||
var results = builder.GetAllAgents();
|
|
||||||
//var agents = results.Select(x => builder.RecoverAgent(x) as AgentModel).Where(x => x.).ToList();
|
|
||||||
|
|
||||||
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
|
return new IntentPageViewModel { Intents = intents, Total = intents.Count };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
Platform.Articulate/Controllers/ParseControllercs.cs
Normal file
19
Platform.Articulate/Controllers/ParseControllercs.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Platform.Articulate.Controllers
|
||||||
|
{
|
||||||
|
#if ARTICULATE
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class ParseControllercs : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("/agent/{agentId}/parse")]
|
||||||
|
public void ParseText([FromRoute] string agentId, [FromQuery] string text)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
67
Platform.Articulate/Controllers/ScenarioController.cs
Normal file
67
Platform.Articulate/Controllers/ScenarioController.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
using BotSharp.Core;
|
||||||
|
using DotNetToolkit;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Platform.Articulate.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Platform.Articulate.Controllers
|
||||||
|
{
|
||||||
|
#if ARTICULATE
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class ScenarioController : ControllerBase
|
||||||
|
{
|
||||||
|
private ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel> builder;
|
||||||
|
|
||||||
|
public ScenarioController()
|
||||||
|
{
|
||||||
|
builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("/intent/{intentId}/scenario")]
|
||||||
|
public IntentScenarioViewModel GetIntentScenario([FromRoute] string intentId)
|
||||||
|
{
|
||||||
|
var agent = 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 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 = builder.GetAgentByName(scenario.Agent);
|
||||||
|
|
||||||
|
var model = scenario.ToObject<ScenarioModel>();
|
||||||
|
|
||||||
|
agent.Domains.First(x => x.DomainName == scenario.Domain)
|
||||||
|
.Intents
|
||||||
|
.First(x => x.IntentName == scenario.Intent)
|
||||||
|
.Scenario = model;
|
||||||
|
|
||||||
|
builder.SaveAgent(agent);
|
||||||
|
|
||||||
|
return scenario;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,11 @@ namespace Platform.Articulate.Models
|
||||||
{
|
{
|
||||||
public class DomainModel
|
public class DomainModel
|
||||||
{
|
{
|
||||||
|
public DomainModel()
|
||||||
|
{
|
||||||
|
Intents = new List<IntentModel>();
|
||||||
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
public string Agent { get; set; }
|
public string Agent { get; set; }
|
||||||
|
|
@ -21,6 +26,6 @@ namespace Platform.Articulate.Models
|
||||||
|
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
|
||||||
public List<IntentBase> Intents { get; set; }
|
public List<IntentModel> Intents { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ namespace Platform.Articulate.Models
|
||||||
{
|
{
|
||||||
public class EntityModel : EntityBase
|
public class EntityModel : EntityBase
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string Regex { get; set; }
|
public string Regex { get; set; }
|
||||||
|
|
||||||
public string Agent { get; set; }
|
public string Agent { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ namespace Platform.Articulate.Models
|
||||||
{
|
{
|
||||||
public class IntentModel : IntentBase
|
public class IntentModel : IntentBase
|
||||||
{
|
{
|
||||||
[JsonProperty("IntentName")]
|
public string IntentName { get; set; }
|
||||||
public new string Name { get; set; }
|
|
||||||
|
|
||||||
public string Agent { get; set; }
|
public string Agent { get; set; }
|
||||||
|
|
||||||
|
|
@ -21,6 +20,6 @@ namespace Platform.Articulate.Models
|
||||||
|
|
||||||
public List<IntentExampleModel> Examples { get; set; }
|
public List<IntentExampleModel> Examples { get; set; }
|
||||||
|
|
||||||
public IntentResponseBase Response { get; set; }
|
public ScenarioModel Scenario { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
Platform.Articulate/Models/ScenarioModel.cs
Normal file
22
Platform.Articulate/Models/ScenarioModel.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,18 +4,12 @@ using System.Text;
|
||||||
|
|
||||||
namespace Platform.Articulate.Models
|
namespace Platform.Articulate.Models
|
||||||
{
|
{
|
||||||
public class IntentScenarioViewModel
|
public class IntentScenarioViewModel : ScenarioModel
|
||||||
{
|
{
|
||||||
public string Domain { get; set; }
|
public string Domain { get; set; }
|
||||||
|
|
||||||
public string Agent { get; set; }
|
public string Agent { get; set; }
|
||||||
|
|
||||||
public string Intent { get; set; }
|
public string Intent { get; set; }
|
||||||
|
|
||||||
public string ScenarioName { get; set; }
|
|
||||||
|
|
||||||
public List<String> IntentResponses { get; set; }
|
|
||||||
|
|
||||||
public List<SlotModel> Slots { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue