static async Task<string> GetLuisResult(string reqString)
{
//最多是 500 個 ascii chars,中文我先取 230 個
if (reqString.Length > 230)
{
reqString = reqString.Substring(0, 230);
}
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
const string appId = "你的appid";
const string subscriptionKey = "你的訂閱key";
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
// Request parameters
//如果回傳的內容中需要各 Intent 的話,請將 verbose 設定為 true
queryString["verbose"] = "true";
//queryString["spellCheck"] = "{boolean}";
//queryString["staging"] = "{boolean}";
//queryString["bing-spell-check-subscription-key"] = "bing key";
//queryString["log"] = "{boolean}";
var uri = $"https://eastasia.api.cognitive.microsoft.com/luis/v2.0/apps/{appId}?q=" + HttpUtility.UrlEncode(reqString)+ "&" + queryString;;
var response = await client.GetAsync(uri);
var result = await response.Content.ReadAsStringAsync();
return result;
}
static async Task<string> GetLuisResultPost(string reqString)
{
//最多是 500 個 ascii chars,中文我先取 230 個
if (reqString.Length > 230)
{
reqString = reqString.Substring(0, 230);
}
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
const string appId = "你的appid";
const string subscriptionKey = "你的訂閱key";
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
// Request parameters
//如果回傳的內容中需要各 Intent 的話,請將 verbose 設定為 true
queryString["verbose"] = "true";
//queryString["spellCheck"] = "{boolean}";
//queryString["staging"] = "{boolean}";
//queryString["bing-spell-check-subscription-key"] = "bing key";
//queryString["log"] = "{boolean}";
var uri = $"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/{appId}?" + queryString;
HttpResponseMessage response;
// Request body,前後要加上 雙引號 哦!
byte[] byteData = Encoding.UTF8.GetBytes("\"" + reqString + "\"");
using (var content = new ByteArrayContent(byteData))
{
response = await client.PostAsync(uri, content);
var result = await response.Content.ReadAsStringAsync();
return result;
}
}
static async Task<string> GetLuisResultTest(string reqString)
{
//最多是 500 個 ascii chars,中文我先取 230 個
if (reqString.Length > 230)
{
reqString = reqString.Substring(0, 230);
}
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
const string appId = "你的appid";
const string subscriptionKey = "你的免費訂閱key";
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
var uri = $"https://westus.api.cognitive.microsoft.com/luis/webapi/v2.0/apps/{appId}/versions/0.1/predict?example=" + HttpUtility.UrlEncode(reqString);
var response = await client.GetAsync(uri);
var result = await response.Content.ReadAsStringAsync();
return result;
}
{
"query": "下載下來可以用了,可是什麼是網址識別",
"topScoringIntent": {
"intent": "FAQ",
"score": 1.0
},
"intents": [
{
"intent": "FAQ",
"score": 1.0
},
{
"intent": "None",
"score": 0.05330094
}
],
"entities": [
{
"entity": "網址",
"type": "Keyword",
"startIndex": 14,
"endIndex": 15,
"score": 0.9081365
},
{
"entity": "識別",
"type": "Keyword",
"startIndex": 16,
"endIndex": 17,
"score": 0.9102927
},
{
"entity": "下載",
"type": "Action",
"startIndex": 0,
"endIndex": 1,
"score": 0.9999258
}
]
}
{
"id": null,
"text": "下載下來可以用了,可是什麼是網址識別",
"alteredText": "下載下來可以用了,可是什麼是網址識別",
"tokenizedText": [
"下" ],
"intentPredictions": [
{
"id": "9e70ed0a-561c-45f4-b8a4-2439de42acb1",
"name": "FAQ",
"score": 1.0 },
{
"id": "8d898fa2-667f-471d-b87f-309011627b5d",
"name": "None",
"score": 0.05 }
],
"entityPredictions": [
{
"id": "cb403a63-347c-448c-9b08-3e48d6ac0c61",
"entityName": "Keyword",
"startTokenIndex": 14,
"endTokenIndex": 15,
"phrase": "網 址",
"entityType": 1 },
{
"id": "cb403a63-347c-448c-9b08-3e48d6ac0c61",
"entityName": "Keyword",
"startTokenIndex": 16,
"endTokenIndex": 17,
"phrase": "識 別",
"entityType": 1 },
{
"id": "1771cbab-fb7b-4a83-b46d-4c085ba88341",
"entityName": "Action",
"startTokenIndex": 0,
"endTokenIndex": 1,
"phrase": "下 載",
"entityType": 1 }
],
"tokenMetadata": null}
預設 call 正式 api 時,會 log 查詢的資料,最近幾筆資料可以從 「 Review endpoint utterances 」 看到,如下