仅从LUIS返回实体

时间:2017-05-11 18:30:59

标签: botframework microsoft-cognitive luis

如果我只想从BotFramework发送给LUIS的文本中返回一个实体但是它没有被任何意图触发怎么办?例如我的机器人已经要求用户指定一个时间范围,例如((星期一下午3点到星期一晚上9点)我只是想发送这个以获得一个builtin.datetimeV2.datetimerange?我目前只是将它发送给LuisIntent (“无”)并且它有效,但这感觉不对。我应该这样做吗?

1 个答案:

答案 0 :(得分:0)

与@Steven G一样,您可以直接调用LUIS,并解析json结果。

public class LUISRestService
{
    public static async Task<string> GetLuisResult(string searchFor)
    {
        string LUISEndpoint = $"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[YOURLUSAPPID]?subscription-key=[YOURSUBSCRIPTIONKEY]&timezoneOffset=0&verbose=true&q={searchFor}";
        string result = "";
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(LUISEndpoint);

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response = await client.GetAsync(LUISEndpoint);
        if (response.IsSuccessStatusCode)
        {
            result = await response.Content.ReadAsStringAsync();                
        }
        else
        {
            Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
        }
        return result;
    }
}