BotSharp/Platform.Articulate/Controllers/TrainController.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2018-10-01 01:27:57 +00:00
using BotSharp.Core;
using Microsoft.AspNetCore.Mvc;
2018-10-01 17:15:17 +00:00
using Microsoft.Extensions.Configuration;
2018-10-01 01:27:57 +00:00
using Platform.Articulate.Models;
using System;
using System.Collections.Generic;
using System.Text;
2018-10-01 17:15:17 +00:00
using System.Threading.Tasks;
2018-10-01 01:27:57 +00:00
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class TrainController : ControllerBase
{
2018-10-01 17:15:17 +00:00
private readonly IConfiguration configuration;
private ArticulateAi<AgentModel> builder;
2018-10-01 01:27:57 +00:00
2018-10-01 17:15:17 +00:00
public TrainController(IConfiguration configuration)
2018-10-01 01:27:57 +00:00
{
2018-10-01 17:15:17 +00:00
builder = new ArticulateAi<AgentModel>();
builder.PlatformConfig = configuration.GetSection("ArticulateAi");
2018-10-01 01:27:57 +00:00
}
[HttpGet("/agent/{agentId}/train")]
2018-10-01 17:15:17 +00:00
public async Task<AgentModel> TrainAgent([FromRoute] string agentId)
2018-10-01 01:27:57 +00:00
{
var agent = builder.GetAgentById(agentId);
2018-10-01 17:15:17 +00:00
var corpus = builder.ExtractorCorpus(agent);
2018-10-01 17:15:17 +00:00
await builder.Train(agent, corpus);
agent.Status = "Ready";
2018-10-01 01:27:57 +00:00
builder.SaveAgent(agent);
2018-10-01 01:27:57 +00:00
return agent;
}
}
#endif
}