BotSharp/BotSharp.RestApi/Rasa/ParseController.cs

74 lines
2 KiB
C#
Raw Normal View History

2018-08-14 14:23:15 +00:00
using BotSharp.Core.Engines;
using BotSharp.Core.Models;
using BotSharp.NLP;
2018-08-14 14:23:15 +00:00
using Microsoft.AspNetCore.Mvc;
2018-08-23 04:24:13 +00:00
using Newtonsoft.Json;
2018-08-14 14:23:15 +00:00
using System;
using System.Collections.Generic;
2018-08-23 04:24:13 +00:00
using System.IO;
2018-08-14 14:23:15 +00:00
using System.Text;
namespace BotSharp.RestApi.Rasa
{
#if RASA_UI
2018-08-23 04:24:13 +00:00
/// <summary>
/// send a text request
/// </summary>
2018-08-14 14:23:15 +00:00
[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;
}
2018-08-23 04:24:13 +00:00
/// <summary>
/// parse request
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, HttpGet]
public ActionResult<RasaResponse> Parse()
2018-08-14 14:23:15 +00:00
{
String clientAccessToken = Request.Headers["ClientAccessToken"];
2018-08-23 04:24:13 +00:00
var config = new AIConfiguration("", SupportedLanguage.English);
2018-08-14 14:23:15 +00:00
config.SessionId = "rasa nlu";
2018-08-23 04:24:13 +00:00
string body = "";
using (var reader = new StreamReader(Request.Body))
{
body = reader.ReadToEnd();
}
var request = JsonConvert.DeserializeObject<RasaRequestModel>(body);
//_platform.LoadAgent(clientAccessToken);
2018-08-14 14:23:15 +00:00
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>
{
},
2018-08-23 04:24:13 +00:00
Text = ""
2018-08-14 14:23:15 +00:00
};
}
}
#endif
}