BotSharp/Platform.Dialogflow/Controllers/TrainController.cs

54 lines
1.5 KiB
C#
Raw Normal View History

2018-10-03 06:00:07 +00:00
using BotSharp.Core.Engines;
2018-10-02 19:49:37 +00:00
using BotSharp.Platform.Models;
using Microsoft.AspNetCore.Mvc;
2018-10-03 06:00:07 +00:00
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
2018-10-03 06:00:07 +00:00
using Platform.Dialogflow.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
2018-10-02 19:49:37 +00:00
namespace Platform.Dialogflow.Controllers
{
#if DIALOGFLOW
/// <summary>
/// You can post your training data to this endpoint to train a new model for a project.
/// This request will wait for the server answer: either the model was trained successfully or the training exited with an error.
/// </summary>
[Route("v1/[controller]")]
public class TrainController : ControllerBase
{
2018-10-03 06:00:07 +00:00
private DialogflowAi<AgentModel> builder;
2018-10-03 06:00:07 +00:00
public TrainController(IConfiguration configuration)
{
2018-10-03 06:00:07 +00:00
builder = new DialogflowAi<AgentModel>();
builder.PlatformConfig = configuration.GetSection("DialogflowAi");
}
[HttpPost]
2018-10-03 06:00:07 +00:00
public async Task<ActionResult<AgentModel>> Train([FromQuery] string agentId)
{
2018-10-03 06:00:07 +00:00
var agent = builder.GetAgentById(agentId);
2018-10-03 06:00:07 +00:00
if(agent == null)
{
2018-10-03 06:00:07 +00:00
agent = builder.GetAgentByName(agentId);
}
var corpus = builder.ExtractorCorpus(agent);
2018-10-03 06:00:07 +00:00
await builder.Train(agent, corpus);
2018-10-03 01:44:11 +00:00
2018-10-03 06:00:07 +00:00
return agent;
}
}
#endif
}