Fix parse entity issue for Rasa UI.
This commit is contained in:
parent
c0efaf0346
commit
465e3b97e8
|
|
@ -7,6 +7,7 @@ using Newtonsoft.Json;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.RestApi.Rasa
|
||||
|
|
@ -35,7 +36,7 @@ namespace BotSharp.RestApi.Rasa
|
|||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, HttpGet]
|
||||
public ActionResult<RasaResponse> Parse()
|
||||
public ActionResult<List<RasaResponse>> Parse()
|
||||
{
|
||||
var config = new AIConfiguration("", SupportedLanguage.English);
|
||||
config.SessionId = "rasa nlu";
|
||||
|
|
@ -64,19 +65,25 @@ namespace BotSharp.RestApi.Rasa
|
|||
Query = new String[] { request.Text }
|
||||
});
|
||||
|
||||
return new RasaResponse
|
||||
var rasaResponse = new RasaResponse
|
||||
{
|
||||
Intent = new RasaResponseIntent
|
||||
{
|
||||
Name = aIResponse.Result.Metadata.IntentName,
|
||||
Confidence = aIResponse.Result.Score
|
||||
},
|
||||
Entities = new List<RasaResponseEntity>
|
||||
Entities = aIResponse.Result.Parameters.Select(x => new RasaResponseEntity
|
||||
{
|
||||
|
||||
},
|
||||
Text = ""
|
||||
Entity = x.Key,
|
||||
Value = x.Value.ToString()
|
||||
}).ToList(),
|
||||
Text = request.Text,
|
||||
Model = request.Model,
|
||||
Project = request.Project,
|
||||
IntentRanking = new List<RasaResponseIntent> { }
|
||||
};
|
||||
|
||||
return new List<RasaResponse> { rasaResponse };
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ namespace BotSharp.RestApi.Rasa
|
|||
/// <summary>
|
||||
/// Using the HTTP server, you must specify the project you want to train a new model for to be able to use it during parse requests later on : /train?project=my_project.
|
||||
/// </summary>
|
||||
/// <param name="agent">Model name</param>
|
||||
/// <param name="model">Model name</param>
|
||||
/// <param name="project"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<String>> Train([FromQuery] string agent, [FromQuery] string project)
|
||||
public async Task<ActionResult<String>> Train([FromQuery] string model, [FromQuery] string project)
|
||||
{
|
||||
string body = "";
|
||||
using (var reader = new StreamReader(Request.Body))
|
||||
|
|
@ -49,7 +49,7 @@ namespace BotSharp.RestApi.Rasa
|
|||
}
|
||||
|
||||
var rasa_nlu_data = JsonConvert.DeserializeObject<RasaTrainRequestModel>(body);
|
||||
rasa_nlu_data.Model = agent;
|
||||
rasa_nlu_data.Model = model;
|
||||
var trainResult = await Train(rasa_nlu_data, project);
|
||||
|
||||
return trainResult;
|
||||
|
|
|
|||
Loading…
Reference in a new issue