Как заставить намерение быть динамичным в Луисе
Я хочу сделать значение Intent динамическим на основе ответа строки JSON из URL-адреса конечной точки LUIS. На основе совпадающего значения intent он будет извлекать записи из базы данных SQL Server. У меня есть такая проблема: как сделать значение intent динамическим при вызове функции intent?
Что я уже пробовал:
public static async Task<string> MakeRequest(string Query) { var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); // Request headers client.DefaultRequestHeaders.Add("XXXXXXX", "XXXXXXX"); var uri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/XXXXX=0&q=" + Query; var response = await client.GetAsync(uri); var responseContent = await response.Content.ReadAsStringAsync(); var responseitem = JsonConvert.SerializeObject(responseContent, Formatting.Indented); JToken content = JToken.Parse(responseitem); var intentOnly =Convert.ToString((from s in content.Children()["responseContent"] select s).ToList()); var jsonresponse = JObject.Parse(responseContent); intentOnly = jsonresponse.SelectToken("intents[1].intent").ToString(); return intentOnly; } [LuisIntent("HI")] public async Task FindIntent(IDialogContext context, LuisResult result) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); if (con.State == ConnectionState.Closed) { con.Open(); } DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("USP_GET_RESP", con); cmd.Parameters.Add(new SqlParameter("@ACTION", "A")); cmd.Parameters.Add(new SqlParameter("@INTENT", result.Intents[0].Intent.ToString())); cmd.CommandType = CommandType.StoredProcedure; da.SelectCommand = cmd; cmd.ExecuteNonQuery(); da.Fill(dt); if (dt.Rows.Count > 0) { await context.PostAsync(dt.Rows[0]["VCH_ANSWER"].ToString()); } else { await context.PostAsync("Please get in touch with your account manager. Contact details are on the top right corner of this page."); } context.Wait(MessageReceived); }
I want to make Intent value dynamic based on JSON string response from LUIS endpoint url. Based on intent value matched, it will fetch records from SQL Server database. I have this issue: How do I make the intent value dynamic while calling the intent function? public static async Task<string> MakeRequest(string Query) { var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); // Request headers client.DefaultRequestHeaders.Add("XXXXXXX", "XXXXXXX"); var uri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/XXXXX=0&q=" + Query; var response = await client.GetAsync(uri); var responseContent = await response.Content.ReadAsStringAsync(); var responseitem = JsonConvert.SerializeObject(responseContent, Formatting.Indented); JToken content = JToken.Parse(responseitem); var intentOnly =Convert.ToString((from s in content.Children()["responseContent"] select s).ToList()); var jsonresponse = JObject.Parse(responseContent); intentOnly = jsonresponse.SelectToken("intents[1].intent").ToString(); return intentOnly; } [LuisIntent("HI")] public async Task FindIntent(IDialogContext context, LuisResult result) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); if (con.State == ConnectionState.Closed) { con.Open(); } DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("USP_GET_RESP", con); cmd.Parameters.Add(new SqlParameter("@ACTION", "A")); cmd.Parameters.Add(new SqlParameter("@INTENT", result.Intents[0].Intent.ToString())); cmd.CommandType = CommandType.StoredProcedure; da.SelectCommand = cmd; cmd.ExecuteNonQuery(); da.Fill(dt); if (dt.Rows.Count > 0) { await context.PostAsync(dt.Rows[0]["VCH_ANSWER"].ToString()); } else { await context.PostAsync("Please get in touch with your account manager. Contact details are on the top right corner of this page."); } context.Wait(MessageReceived); } I want to place dynamic intent value in place of HI ex- [LuisIntent("HI")]