BotSharp/Platform.Articulate/Controllers/ParseControllercs.cs

50 lines
1.4 KiB
C#
Raw Normal View History

2018-10-03 01:44:11 +00:00
using BotSharp.NLP;
2018-10-02 02:49:01 +00:00
using BotSharp.Platform.Models.AiRequest;
using Microsoft.AspNetCore.Mvc;
2018-10-01 17:15:17 +00:00
using Microsoft.Extensions.Configuration;
2018-10-02 02:49:01 +00:00
using Platform.Articulate.Models;
using Platform.Articulate.ViewModels;
2018-09-30 15:11:36 +00:00
using System;
using System.Collections.Generic;
2018-10-02 02:49:01 +00:00
using System.Drawing;
using System.IO;
using System.Linq;
2018-09-30 15:11:36 +00:00
using System.Text;
2018-10-02 02:49:01 +00:00
using Console = Colorful.Console;
2018-09-30 15:11:36 +00:00
namespace Platform.Articulate.Controllers
{
#if ARTICULATE
[Route("[controller]")]
public class ParseControllercs : ControllerBase
{
2018-10-01 17:15:17 +00:00
private readonly IConfiguration configuration;
2018-10-02 02:49:01 +00:00
private ArticulateAi<AgentModel> builder;
public ParseControllercs(IConfiguration configuration)
{
builder = new ArticulateAi<AgentModel>();
builder.PlatformConfig = configuration.GetSection("ArticulateAi");
}
2018-10-01 17:15:17 +00:00
[HttpGet("/agent/{agentId}/converse")]
public ActionResult ParseText([FromRoute] string agentId, [FromQuery] string text, [FromQuery] string sessionId)
2018-09-30 15:11:36 +00:00
{
2018-10-02 02:49:01 +00:00
var response = new ResponseViewModel();
Console.WriteLine($"Got message from {Request.Host}: {text}", Color.Green);
var aiResponse = builder.TextRequest(new AiRequest
{
AgentId = agentId,
Text = text
});
response.TextResponse = aiResponse.Speech;
return Ok(response);
2018-09-30 15:11:36 +00:00
}
}
#endif
}