refactor articulate platform
This commit is contained in:
parent
43cac5c07c
commit
a06745ffb0
|
|
@ -11,16 +11,16 @@ namespace BotSharp.Core
|
|||
/// Save agent instance into memory.
|
||||
/// Caution: Data will be lost once application restarts.
|
||||
/// </summary>
|
||||
public class AgentStorageInMemory<TExtraData, TEntity> : IAgentStorage<TExtraData, TEntity>
|
||||
public class AgentStorageInMemory<TAgent> : IAgentStorage<TAgent> where TAgent : AgentBase
|
||||
{
|
||||
private static Dictionary<string, StandardAgent<TExtraData, TEntity>> agents;
|
||||
private static Dictionary<string, TAgent> agents;
|
||||
|
||||
public AgentStorageInMemory()
|
||||
{
|
||||
if (agents == null) agents = new Dictionary<string, StandardAgent<TExtraData, TEntity>>();
|
||||
if (agents == null) agents = new Dictionary<string, TAgent>();
|
||||
}
|
||||
|
||||
public StandardAgent<TExtraData, TEntity> FetchById(string agentId)
|
||||
public TAgent FetchById(string agentId)
|
||||
{
|
||||
if (agents.ContainsKey(agentId))
|
||||
{
|
||||
|
|
@ -32,14 +32,14 @@ namespace BotSharp.Core
|
|||
}
|
||||
}
|
||||
|
||||
public StandardAgent<TExtraData, TEntity> FetchByName(string agentName)
|
||||
public TAgent FetchByName(string agentName)
|
||||
{
|
||||
var data = agents.FirstOrDefault(x => x.Value.Name == agentName);
|
||||
|
||||
return data.Value;
|
||||
}
|
||||
|
||||
public bool Persist(StandardAgent<TExtraData, TEntity> agent)
|
||||
public bool Persist(TAgent agent)
|
||||
{
|
||||
if (String.IsNullOrEmpty(agent.Id))
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ namespace BotSharp.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
public List<StandardAgent<TExtraData, TEntity>> Query()
|
||||
public List<TAgent> Query()
|
||||
{
|
||||
return agents.Select(x => x.Value).ToList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ using System.Text;
|
|||
|
||||
namespace BotSharp.Core
|
||||
{
|
||||
public abstract class PlatformBuilderBase<TStorage, TExtraData, TEntity>
|
||||
where TStorage : IAgentStorage<TExtraData, TEntity>, new ()
|
||||
public abstract class PlatformBuilderBase<TStorage, TAgent>
|
||||
where TStorage : IAgentStorage<TAgent>, new ()
|
||||
{
|
||||
protected static TStorage storage;
|
||||
|
||||
|
|
@ -16,23 +16,23 @@ namespace BotSharp.Core
|
|||
if (storage == null) storage = new TStorage();
|
||||
}
|
||||
|
||||
public List<StandardAgent<TExtraData, TEntity>> GetAllAgents()
|
||||
public List<TAgent> GetAllAgents()
|
||||
{
|
||||
return storage.Query();
|
||||
}
|
||||
|
||||
|
||||
public StandardAgent<TExtraData, TEntity> GetAgentById(string agentId)
|
||||
public TAgent GetAgentById(string agentId)
|
||||
{
|
||||
return storage.FetchById(agentId);
|
||||
}
|
||||
|
||||
public StandardAgent<TExtraData, TEntity> GetAgentByName(string agentName)
|
||||
public TAgent GetAgentByName(string agentName)
|
||||
{
|
||||
return storage.FetchByName(agentName);
|
||||
}
|
||||
|
||||
public virtual bool SaveAgent(StandardAgent<TExtraData, TEntity> agent)
|
||||
public virtual bool SaveAgent(TAgent agent)
|
||||
{
|
||||
// default save agent in FileStorage
|
||||
storage.Persist(agent);
|
||||
|
|
|
|||
|
|
@ -9,33 +9,33 @@ namespace BotSharp.Platform.Abstraction
|
|||
/// Agent could be persisted in any kind of storage.
|
||||
/// Example: local file storage, cloud storage, relational database, key-value database or memory
|
||||
/// </summary>
|
||||
public interface IAgentStorage<TExtraData, TEntity>
|
||||
public interface IAgentStorage<TAgent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Save agent instance
|
||||
/// </summary>
|
||||
/// <param name="agent"></param>
|
||||
/// <returns></returns>
|
||||
bool Persist(StandardAgent<TExtraData, TEntity> agent);
|
||||
bool Persist(TAgent agent);
|
||||
|
||||
/// <summary>
|
||||
/// Get agent by id
|
||||
/// </summary>
|
||||
/// <param name="agentId"></param>
|
||||
/// <returns></returns>
|
||||
StandardAgent<TExtraData, TEntity> FetchById(string agentId);
|
||||
TAgent FetchById(string agentId);
|
||||
|
||||
/// <summary>
|
||||
/// Get agent by name
|
||||
/// </summary>
|
||||
/// <param name="agentName"></param>
|
||||
/// <returns></returns>
|
||||
StandardAgent<TExtraData, TEntity> FetchByName(string agentName);
|
||||
TAgent FetchByName(string agentName);
|
||||
|
||||
/// <summary>
|
||||
/// Query agents
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<StandardAgent<TExtraData, TEntity>> Query();
|
||||
List<TAgent> Query();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace BotSharp.Platform.Abstraction
|
|||
/// Platform abstraction
|
||||
/// Implement this interface to build a Chatbot platform
|
||||
/// </summary>
|
||||
public interface IPlatformBuilder<TStorage, TAgent, TExtraData, TEntity>
|
||||
where TStorage : IAgentStorage<TExtraData, TEntity>, new()
|
||||
public interface IPlatformBuilder<TStorage, TAgent>
|
||||
where TStorage : IAgentStorage<TAgent>, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Parse options for the incoming text or voice request from the sender.
|
||||
|
|
@ -23,14 +23,14 @@ namespace BotSharp.Platform.Abstraction
|
|||
/// </summary>
|
||||
/// <param name="agent"></param>
|
||||
/// <returns></returns>
|
||||
StandardAgent<TExtraData, TEntity> 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<TExtraData, TEntity> agent);
|
||||
TAgent RecoverAgent(StandardAgent agent);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
@ -38,8 +38,6 @@ namespace BotSharp.Platform.Abstraction
|
|||
/// <typeparam name="TStorage"></typeparam>
|
||||
/// <param name="agent"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveAgent(StandardAgent<TExtraData, TEntity> agent);
|
||||
|
||||
StandardAgent<TExtraData, TEntity> GetAgentById(string agentId);
|
||||
bool SaveAgent(TAgent agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
36
BotSharp.Platform.Models/AgentBase.cs
Normal file
36
BotSharp.Platform.Models/AgentBase.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Platform.Models
|
||||
{
|
||||
public abstract class AgentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Guid
|
||||
/// </summary>
|
||||
[StringLength(36)]
|
||||
public String Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of chatbot
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public virtual String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Description of chatbot
|
||||
/// </summary>
|
||||
[MaxLength(256)]
|
||||
public String Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(5)]
|
||||
public String Language { get; set; }
|
||||
}
|
||||
}
|
||||
10
BotSharp.Platform.Models/EntityBase.cs
Normal file
10
BotSharp.Platform.Models/EntityBase.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Platform.Models
|
||||
{
|
||||
public abstract class EntityBase
|
||||
{
|
||||
}
|
||||
}
|
||||
23
BotSharp.Platform.Models/IntentBase.cs
Normal file
23
BotSharp.Platform.Models/IntentBase.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Platform.Models
|
||||
{
|
||||
public abstract class IntentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Guid
|
||||
/// </summary>
|
||||
[StringLength(36)]
|
||||
public String Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of chatbot
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public String Name { get; set; }
|
||||
}
|
||||
}
|
||||
16
BotSharp.Platform.Models/IntentResponseBase.cs
Normal file
16
BotSharp.Platform.Models/IntentResponseBase.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Platform.Models
|
||||
{
|
||||
public abstract class IntentResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Guid
|
||||
/// </summary>
|
||||
[StringLength(36)]
|
||||
public String Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -10,45 +10,20 @@ namespace BotSharp.Platform.Models
|
|||
/// Standard agent data structure
|
||||
/// All other platform agent has to align with this standard data structure.
|
||||
/// </summary>
|
||||
public class StandardAgent<TExtraData, TEntity>
|
||||
public class StandardAgent : AgentBase
|
||||
{
|
||||
public StandardAgent()
|
||||
{
|
||||
CreatedDate = DateTime.UtcNow;
|
||||
Entities = new List<TEntity>();
|
||||
Entities = new List<EntityBase>();
|
||||
Intents = new List<IntentBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Guid
|
||||
/// </summary>
|
||||
[StringLength(36)]
|
||||
public String Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of chatbot
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Description of chatbot
|
||||
/// </summary>
|
||||
[MaxLength(256)]
|
||||
public String Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the chatbot public or private
|
||||
/// </summary>
|
||||
public Boolean Published { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Required]
|
||||
[MaxLength(5)]
|
||||
public String Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only access text/ audio rquest
|
||||
/// </summary>
|
||||
|
|
@ -61,9 +36,9 @@ namespace BotSharp.Platform.Models
|
|||
[StringLength(32)]
|
||||
public String DeveloperAccessToken { get; set; }
|
||||
|
||||
//public List<Intent> Intents { get; set; }
|
||||
public List<IntentBase> Intents { get; set; }
|
||||
|
||||
public List<TEntity> Entities { get; set; }
|
||||
public List<EntityBase> Entities { get; set; }
|
||||
|
||||
public String Birthday
|
||||
{
|
||||
|
|
@ -74,10 +49,5 @@ namespace BotSharp.Platform.Models
|
|||
}
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save extra information for specific platform
|
||||
/// </summary>
|
||||
public TExtraData ExtraData { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,8 @@ namespace BotSharp.WebHost
|
|||
c.RoutePrefix = String.Empty;
|
||||
c.DocumentTitle = info.Title;
|
||||
c.InjectStylesheet(Configuration.GetValue<String>("Swagger:Stylesheet"));
|
||||
|
||||
Console.WriteLine($"Current Mode: {info.Title}");
|
||||
});
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
|
|
|
|||
|
|
@ -13,21 +13,21 @@ namespace Platform.Articulate
|
|||
/// http://spg.ai/projects/articulate
|
||||
/// This implementation takes over APIs of Articulate's 7500 port.
|
||||
/// </summary>
|
||||
public class ArticulateAi<TStorage, TAgent, TExtraData, TEntity> :
|
||||
PlatformBuilderBase<TStorage, TExtraData, TEntity>,
|
||||
IPlatformBuilder<TStorage, TAgent, TExtraData, TEntity>
|
||||
where TStorage : IAgentStorage<TExtraData, TEntity>, new()
|
||||
public class ArticulateAi<TStorage, TAgent> :
|
||||
PlatformBuilderBase<TStorage, TAgent>,
|
||||
IPlatformBuilder<TStorage, TAgent>
|
||||
where TStorage : IAgentStorage<TAgent>, new()
|
||||
{
|
||||
public DialogRequestOptions RequestOptions { get; set; }
|
||||
|
||||
public TAgent RecoverAgent(StandardAgent<TExtraData, TEntity> agent)
|
||||
public TAgent RecoverAgent(StandardAgent agent)
|
||||
{
|
||||
if (agent == null) return default(TAgent);
|
||||
|
||||
var agent1 = new AgentModel
|
||||
{
|
||||
Id = agent.Id,
|
||||
AgentName = agent.Name,
|
||||
Name = agent.Name,
|
||||
Description = agent.Description,
|
||||
Language = agent.Language
|
||||
};
|
||||
|
|
@ -35,13 +35,13 @@ namespace Platform.Articulate
|
|||
return (TAgent)(agent1 as Object);
|
||||
}
|
||||
|
||||
public StandardAgent<TExtraData, TEntity> StandardizeAgent(TAgent specificAgent)
|
||||
public StandardAgent StandardizeAgent(TAgent specificAgent)
|
||||
{
|
||||
var agent1 = specificAgent as AgentModel;
|
||||
|
||||
var standardAgent = new StandardAgent<TExtraData, TEntity>
|
||||
var standardAgent = new StandardAgent
|
||||
{
|
||||
Name = agent1.AgentName,
|
||||
Name = agent1.Name,
|
||||
Language = agent1.Language,
|
||||
Description = agent1.Description
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ namespace Platform.Articulate.Controllers
|
|||
public class AgentController : ControllerBase
|
||||
{
|
||||
private readonly IBotPlatform _platform;
|
||||
private ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel> builder;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize agent controller and get a platform instance
|
||||
|
|
@ -29,6 +30,7 @@ namespace Platform.Articulate.Controllers
|
|||
public AgentController(IBotPlatform platform)
|
||||
{
|
||||
_platform = platform;
|
||||
builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
|
@ -43,11 +45,10 @@ namespace Platform.Articulate.Controllers
|
|||
}
|
||||
|
||||
// convert to standard Agent structure
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<DomainModel, EntityModel>, AgentModel, DomainModel, EntityModel>();
|
||||
var standardAgent = builder.StandardizeAgent(agent);
|
||||
builder.SaveAgent(standardAgent);
|
||||
|
||||
agent.Id = standardAgent.Id;
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||
agent.Id = Guid.NewGuid().ToString();
|
||||
agent.Name = agent.AgentName;
|
||||
builder.SaveAgent(agent);
|
||||
|
||||
return agent;
|
||||
}
|
||||
|
|
@ -55,24 +56,8 @@ namespace Platform.Articulate.Controllers
|
|||
[HttpGet]
|
||||
public List<AgentModel> GetAgent()
|
||||
{
|
||||
/*var agents = new List<AgentModel>();
|
||||
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
var agentPaths = Directory.GetFiles(dataDir).Where(x => Regex.IsMatch(x, @"agent-\d+.json")).ToList();
|
||||
for (int i = 0; i< agentPaths.Count; i++)
|
||||
{
|
||||
string json = System.IO.File.ReadAllText(agentPaths[i]);
|
||||
|
||||
var agent = JsonConvert.DeserializeObject<AgentModel>(json);
|
||||
|
||||
agents.Add(agent);
|
||||
}*/
|
||||
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<DomainModel, EntityModel>, AgentModel, DomainModel, EntityModel>();
|
||||
|
||||
var results = builder.GetAllAgents();
|
||||
var agents = results.Select(x => builder.RecoverAgent(x)).ToList();
|
||||
var agents = results.Select(x => x as AgentModel).ToList();
|
||||
|
||||
return agents;
|
||||
}
|
||||
|
|
@ -80,9 +65,7 @@ namespace Platform.Articulate.Controllers
|
|||
[HttpGet("{agentId}")]
|
||||
public AgentModel GetAgentById([FromRoute] string agentId)
|
||||
{
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<DomainModel, EntityModel>, AgentModel, DomainModel, EntityModel>();
|
||||
var standardAgent = builder.GetAgentById(agentId);
|
||||
var agent = builder.RecoverAgent(standardAgent);
|
||||
var agent = builder.GetAgentById(agentId);
|
||||
|
||||
return agent;
|
||||
}
|
||||
|
|
@ -102,7 +85,7 @@ namespace Platform.Articulate.Controllers
|
|||
|
||||
var agentTmp = JsonConvert.DeserializeObject<AgentModel>(json);
|
||||
|
||||
if(agentTmp.AgentName == agentName)
|
||||
if(agentTmp.Name == agentName)
|
||||
{
|
||||
agent = agentTmp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Core;
|
||||
using BotSharp.Platform.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -17,6 +18,13 @@ namespace Platform.Articulate.Controllers
|
|||
[Route("[controller]")]
|
||||
public class DomainController : ControllerBase
|
||||
{
|
||||
private ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel> builder;
|
||||
|
||||
public DomainController()
|
||||
{
|
||||
builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||
}
|
||||
|
||||
[HttpGet("{domainId}")]
|
||||
public DomainModel GetDomain([FromRoute] int domainId)
|
||||
{
|
||||
|
|
@ -41,32 +49,21 @@ namespace Platform.Articulate.Controllers
|
|||
domain = JsonConvert.DeserializeObject<DomainModel>(body);
|
||||
}
|
||||
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<DomainModel, EntityModel>, AgentModel, DomainModel, EntityModel>();
|
||||
var agent = builder.GetAgentByName(domain.Agent);
|
||||
agent.ExtraData = domain;
|
||||
domain.Id = Guid.NewGuid().ToString();
|
||||
(agent as AgentModel).Domains.Add(domain);
|
||||
builder.SaveAgent(agent);
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
[HttpGet("/agent/{agentId}/domain")]
|
||||
public DomainPageViewModel GetAgentDomains([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
public DomainPageViewModel GetAgentDomains([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
{
|
||||
var domains = new List<DomainModel>();
|
||||
var agent = builder.GetAgentById(agentId);
|
||||
|
||||
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
var agentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-domain-")).ToList();
|
||||
for (int i = 0; i < agentPaths.Count; i++)
|
||||
{
|
||||
string json = System.IO.File.ReadAllText(agentPaths[i]);
|
||||
|
||||
var domain = JsonConvert.DeserializeObject<DomainModel>(json);
|
||||
|
||||
domains.Add(domain);
|
||||
}
|
||||
|
||||
return new DomainPageViewModel { Domains = domains, Total = domains.Count };
|
||||
return new DomainPageViewModel { /*Domains = agent.d, Total = domains.Count*/ };
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Core;
|
||||
using BotSharp.Platform.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Platform.Articulate.Models;
|
||||
|
|
@ -15,8 +16,15 @@ namespace Platform.Articulate.Controllers
|
|||
[Route("[controller]")]
|
||||
public class EntityController : ControllerBase
|
||||
{
|
||||
private ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel> builder;
|
||||
|
||||
public EntityController()
|
||||
{
|
||||
builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||
}
|
||||
|
||||
[HttpGet("{entityId}")]
|
||||
public EntityModel GetEntity([FromRoute] int entityId)
|
||||
public EntityModel GetEntity([FromRoute] string entityId)
|
||||
{
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
|
|
@ -30,7 +38,7 @@ namespace Platform.Articulate.Controllers
|
|||
}
|
||||
|
||||
[HttpGet("/agent/{agentId}/entity")]
|
||||
public EntityPageViewModel GetAgentEntities([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
public EntityPageViewModel GetAgentEntities([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
{
|
||||
var entities = new List<EntityModel>();
|
||||
|
||||
|
|
@ -48,7 +56,6 @@ namespace Platform.Articulate.Controllers
|
|||
entity = JsonConvert.DeserializeObject<EntityModel>(body);
|
||||
}
|
||||
|
||||
var builder = new ArticulateAi<AgentStorageInMemory<DomainModel, EntityModel>, AgentModel, DomainModel, EntityModel>();
|
||||
var agent = builder.GetAgentByName(entity.Agent);
|
||||
|
||||
agent.Entities.Add(entity);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using BotSharp.Core;
|
||||
using BotSharp.Platform.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Platform.Articulate.Models;
|
||||
using Platform.Articulate.ViewModels;
|
||||
|
|
@ -14,8 +16,15 @@ namespace Platform.Articulate.Controllers
|
|||
[Route("[controller]")]
|
||||
public class IntentController : ControllerBase
|
||||
{
|
||||
private ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel> builder;
|
||||
|
||||
public IntentController()
|
||||
{
|
||||
builder = new ArticulateAi<AgentStorageInMemory<AgentModel>, AgentModel>();
|
||||
}
|
||||
|
||||
[HttpGet("{intentId}")]
|
||||
public IntentModel GetIntent([FromRoute] int intentId)
|
||||
public IntentModel GetIntent([FromRoute] string intentId)
|
||||
{
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
|
|
@ -28,8 +37,27 @@ namespace Platform.Articulate.Controllers
|
|||
return intent;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IntentModel PostIntent()
|
||||
{
|
||||
IntentModel intent = null;
|
||||
|
||||
using (var reader = new StreamReader(Request.Body))
|
||||
{
|
||||
string body = reader.ReadToEnd();
|
||||
intent = JsonConvert.DeserializeObject<IntentModel>(body);
|
||||
}
|
||||
|
||||
var agent = builder.GetAgentByName(intent.Agent);
|
||||
intent.Id = Guid.NewGuid().ToString();
|
||||
agent.Domains[0].Intents.Add(intent);
|
||||
builder.SaveAgent(agent);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
[HttpGet("{intentId}/scenario")]
|
||||
public IntentScenarioModel GetIntentScenario([FromRoute] int intentId)
|
||||
public IntentScenarioViewModel GetIntentScenario([FromRoute] string intentId)
|
||||
{
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
|
|
@ -37,25 +65,25 @@ namespace Platform.Articulate.Controllers
|
|||
|
||||
string json = System.IO.File.ReadAllText(dataPath);
|
||||
|
||||
var scenario = JsonConvert.DeserializeObject<IntentScenarioModel>(json);
|
||||
var scenario = JsonConvert.DeserializeObject<IntentScenarioViewModel>(json);
|
||||
|
||||
return scenario;
|
||||
}
|
||||
|
||||
[HttpGet("{intentId}/webhook")]
|
||||
public void GetIntentWebhook([FromRoute] int intentId)
|
||||
public void GetIntentWebhook([FromRoute] string intentId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("{intentId}/postFormat")]
|
||||
public void GetIntentPostFormat([FromRoute] int intentId)
|
||||
public void GetIntentPostFormat([FromRoute] string intentId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("/agent/{agentId}/intent")]
|
||||
public IntentPageViewModel GetAgentIntents([FromRoute] int agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
public IntentPageViewModel GetAgentIntents([FromRoute] string agentId, [FromQuery] int start, [FromQuery] int limit)
|
||||
{
|
||||
var intents = new List<IntentModel>();
|
||||
|
||||
|
|
@ -75,7 +103,7 @@ namespace Platform.Articulate.Controllers
|
|||
}
|
||||
|
||||
[HttpGet("/entity/{entityId}/intent")]
|
||||
public List<IntentModel> GetReferencedIntentsByEntity([FromRoute] int entityId, [FromQuery] int start, [FromQuery] int limit)
|
||||
public List<IntentModel> GetReferencedIntentsByEntity([FromRoute] string entityId, [FromQuery] int start, [FromQuery] int limit)
|
||||
{
|
||||
var intents = new List<IntentModel>();
|
||||
|
||||
|
|
@ -107,33 +135,12 @@ namespace Platform.Articulate.Controllers
|
|||
}
|
||||
|
||||
[HttpGet("/domain/{domainId}/intent")]
|
||||
public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] int domainId, [FromQuery] int start, [FromQuery] int limit)
|
||||
public IntentPageViewModel GetReferencedIntentsByDomain([FromRoute] string domainId, [FromQuery] int start, [FromQuery] int limit)
|
||||
{
|
||||
var intents = new List<IntentModel>();
|
||||
|
||||
string dataDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Articulate");
|
||||
|
||||
string domainPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.Contains($"-domain-{domainId}.json"));
|
||||
var domain = JsonConvert.DeserializeObject<DomainModel>(System.IO.File.ReadAllText(domainPath));
|
||||
|
||||
string agentId = domainPath.Split(Path.DirectorySeparatorChar).Last().Split('-')[1];
|
||||
|
||||
string agentPath = Directory.GetFiles(dataDir).FirstOrDefault(x => x.Contains($"agent-{agentId}.json"));
|
||||
var agent = JsonConvert.DeserializeObject<AgentModel>(System.IO.File.ReadAllText(agentPath));
|
||||
|
||||
var intentPaths = Directory.GetFiles(dataDir).Where(x => x.Contains($"agent-{agentId}-intent-")).ToList();
|
||||
|
||||
for (int i = 0; i < intentPaths.Count; i++)
|
||||
{
|
||||
string json = System.IO.File.ReadAllText(intentPaths[i]);
|
||||
|
||||
var intent = JsonConvert.DeserializeObject<IntentModel>(json);
|
||||
|
||||
if (intent.Domain == domain.DomainName)
|
||||
{
|
||||
intents.Add(intent);
|
||||
}
|
||||
}
|
||||
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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
using System;
|
||||
using BotSharp.Platform.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Platform.Articulate.Models
|
||||
{
|
||||
public class AgentModel
|
||||
public class AgentModel : AgentBase
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public AgentModel()
|
||||
{
|
||||
Domains = new List<DomainModel>();
|
||||
Entities = new List<EntityBase>();
|
||||
}
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public string Timezone { get; set; }
|
||||
|
||||
public string Language { get; set; }
|
||||
|
||||
public string AgentName { get; set; }
|
||||
|
||||
public bool UseWebhook { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public bool UsePostFormat { get; set; }
|
||||
|
||||
public bool ExtraTrainingData { get; set; }
|
||||
|
|
@ -29,5 +31,9 @@ namespace Platform.Articulate.Models
|
|||
public bool EnableModelsPerDomain { get; set; }
|
||||
|
||||
public decimal DomainClassifierThreshold { get; set; }
|
||||
|
||||
public List<DomainModel> Domains { get; set; }
|
||||
|
||||
public List<EntityBase> Entities { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using BotSharp.Platform.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
|
@ -6,7 +7,7 @@ namespace Platform.Articulate.Models
|
|||
{
|
||||
public class DomainModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Agent { get; set; }
|
||||
|
||||
|
|
@ -19,5 +20,7 @@ namespace Platform.Articulate.Models
|
|||
public decimal IntentThreshold { get; set; }
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public List<IntentBase> Intents { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
using System;
|
||||
using BotSharp.Platform.Abstraction;
|
||||
using BotSharp.Platform.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Platform.Articulate.Models
|
||||
{
|
||||
public class EntityModel
|
||||
public class EntityModel : EntityBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ namespace Platform.Articulate.Models
|
|||
|
||||
public class ArticulateTrainingIntentExpressionPart : TrainingIntentExpressionPart
|
||||
{
|
||||
public int EntityId { get; set; }
|
||||
public string EntityId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
using System;
|
||||
using BotSharp.Platform.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Platform.Articulate.Models
|
||||
{
|
||||
public class IntentModel
|
||||
public class IntentModel : IntentBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string IntentName { get; set; }
|
||||
[JsonProperty("IntentName")]
|
||||
public new string Name { get; set; }
|
||||
|
||||
public string Agent { get; set; }
|
||||
|
||||
|
|
@ -19,5 +20,7 @@ namespace Platform.Articulate.Models
|
|||
public bool UseWebhook { get; set; }
|
||||
|
||||
public List<IntentExampleModel> Examples { get; set; }
|
||||
|
||||
public IntentResponseBase Response { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ using System.Text;
|
|||
|
||||
namespace Platform.Articulate.Models
|
||||
{
|
||||
public class IntentScenarioModel
|
||||
public class IntentScenarioViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Domain { get; set; }
|
||||
|
||||
public string Agent { get; set; }
|
||||
Loading…
Reference in a new issue