add rasa rest api.
This commit is contained in:
parent
122b5bad71
commit
027b9fdbe4
|
|
@ -15,6 +15,10 @@ namespace BotSharp.Core.Models
|
||||||
public List<RasaResponseEntity> Entities { get; set; }
|
public List<RasaResponseEntity> Entities { get; set; }
|
||||||
|
|
||||||
public String Text { get; set; }
|
public String Text { get; set; }
|
||||||
|
|
||||||
|
public String Project { get; set; }
|
||||||
|
|
||||||
|
public String Model { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RasaResponseIntent
|
public class RasaResponseIntent
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<DocumentationFile>bin\Debug\netcoreapp2.1\BotSharp.RestApi.xml</DocumentationFile>
|
<DocumentationFile>bin\Debug\netcoreapp2.1\BotSharp.RestApi.xml</DocumentationFile>
|
||||||
<DefineConstants>TRACE;DEBUG;MODE_DIALOGFLOW</DefineConstants>
|
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
<DefineConstants>TRACE;MODE_DIALOGFLOW</DefineConstants>
|
<DefineConstants>TRACE;MODE_DIALOGFLOW;RELEASE;NETCOREAPP;NETCOREAPP2_1;RELEASE;NETCOREAPP;NETCOREAPP2_1</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ namespace BotSharp.RestApi.Dialogflow
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dialogflow mode query controller
|
/// Dialogflow mode query controller
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize]
|
|
||||||
[Route("v1/[controller]")]
|
[Route("v1/[controller]")]
|
||||||
public class QueryController : ControllerBase
|
public class QueryController : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
|
||||||
28
BotSharp.RestApi/Rasa/ConfigController.cs
Normal file
28
BotSharp.RestApi/Rasa/ConfigController.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
#if MODE_RASA
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class ConfigController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<RasaVersionModel> Get()
|
||||||
|
{
|
||||||
|
var status = new RasaStatusModel();
|
||||||
|
status.AvailableProjects = JObject.FromObject(new RasaProjectModel
|
||||||
|
{
|
||||||
|
Status = "ready",
|
||||||
|
AvailableModels = new List<string> { "model_XXXXXX" },
|
||||||
|
LoadedModels = new List<string> { "model_XXXXXX" }
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
55
BotSharp.RestApi/Rasa/ParseController.cs
Normal file
55
BotSharp.RestApi/Rasa/ParseController.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
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
|
||||||
|
}
|
||||||
13
BotSharp.RestApi/Rasa/RasaConfigModel.cs
Normal file
13
BotSharp.RestApi/Rasa/RasaConfigModel.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
public class RasaConfigModel
|
||||||
|
{
|
||||||
|
public string Config { get; set; }
|
||||||
|
|
||||||
|
public string Data { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
17
BotSharp.RestApi/Rasa/RasaRequestModel.cs
Normal file
17
BotSharp.RestApi/Rasa/RasaRequestModel.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
public class RasaRequestModel
|
||||||
|
{
|
||||||
|
[JsonProperty("q")]
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
public string Project { get; set; }
|
||||||
|
|
||||||
|
public string Model { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
26
BotSharp.RestApi/Rasa/RasaStatusModel.cs
Normal file
26
BotSharp.RestApi/Rasa/RasaStatusModel.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
public class RasaStatusModel
|
||||||
|
{
|
||||||
|
[JsonProperty("available_projects")]
|
||||||
|
public JObject AvailableProjects { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RasaProjectModel
|
||||||
|
{
|
||||||
|
[JsonProperty("status")]
|
||||||
|
public string Status { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("available_models")]
|
||||||
|
public List<string> AvailableModels { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("loaded_models")]
|
||||||
|
public List<string> LoadedModels { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
15
BotSharp.RestApi/Rasa/RasaVersionModel.cs
Normal file
15
BotSharp.RestApi/Rasa/RasaVersionModel.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
public class RasaVersionModel
|
||||||
|
{
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("minimum_compatible_version")]
|
||||||
|
public string MinimumCompatibleVersion { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
27
BotSharp.RestApi/Rasa/StatusController.cs
Normal file
27
BotSharp.RestApi/Rasa/StatusController.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
#if MODE_RASA
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class StatusController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<RasaVersionModel> Get()
|
||||||
|
{
|
||||||
|
var status = new RasaStatusModel();
|
||||||
|
status.AvailableProjects = JObject.FromObject(new RasaProjectModel
|
||||||
|
{
|
||||||
|
Status = "ready",
|
||||||
|
AvailableModels = new List<string> { "<model_XXXXXX>" }
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
23
BotSharp.RestApi/Rasa/VersionController.cs
Normal file
23
BotSharp.RestApi/Rasa/VersionController.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.RestApi.Rasa
|
||||||
|
{
|
||||||
|
#if MODE_RASA
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class VersionController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<RasaVersionModel> Get()
|
||||||
|
{
|
||||||
|
return Ok(new RasaVersionModel
|
||||||
|
{
|
||||||
|
Version = "0.13.0",
|
||||||
|
MinimumCompatibleVersion = "0.13.0"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,10 @@
|
||||||
<RuntimeIdentifiers>Portable;win10-x64;centos.7-x64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>Portable;win10-x64;centos.7-x64</RuntimeIdentifiers>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DefineConstants>TRACE;DEBUG;MODE_RASA</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="App_Data\ModelFiles\**" />
|
<Compile Remove="App_Data\ModelFiles\**" />
|
||||||
<Compile Remove="App_Data\NewFolder\**" />
|
<Compile Remove="App_Data\NewFolder\**" />
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ namespace BotSharp.WebHost
|
||||||
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
|
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
#if MODE_RASA
|
||||||
|
.UseUrls("http://0.0.0.0:5000")
|
||||||
|
#else
|
||||||
.UseUrls("http://0.0.0.0:3112")
|
.UseUrls("http://0.0.0.0:3112")
|
||||||
|
#endif
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue