BotSharp/BotSharp.RestApi/Rasa/ParseController.cs

56 lines
1.5 KiB
C#
Raw Normal View History

2018-08-14 14:23:15 +00:00
using BotSharp.Core.Engines;
using BotSharp.Core.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.RestApi.Rasa
{
#if MODE_RASA
[Route("[controller]")]
public class ParseController : ControllerBase
{
private readonly IBotPlatform _platform;
/// <summary>
/// Initialize dialog controller and get a platform instance
/// </summary>
/// <param name="platform"></param>
public ParseController(IBotPlatform platform)
{
_platform = platform;
}
[HttpPost]
public ActionResult<RasaResponse> Parse(RasaRequestModel request)
{
String clientAccessToken = Request.Headers["ClientAccessToken"];
var config = new AIConfiguration(clientAccessToken, SupportedLanguage.English);
config.SessionId = "rasa nlu";
_platform.LoadAgent(clientAccessToken);
var aIResponse = _platform.TextRequest(new AIRequest
{
Query = new String[] { request.Text }
});
return new RasaResponse
{
Intent = new RasaResponseIntent
{
Name = aIResponse.Result.Metadata.IntentName,
Confidence = aIResponse.Result.Score
},
Entities = new List<RasaResponseEntity>
{
},
Text = request.Text
};
}
}
#endif
}