Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
skill fixes (#2449)
Browse files Browse the repository at this point in the history
* POI: align tests to code, update lu
* Bing search: add locale to GetSearchResult, update lu
  • Loading branch information
xieofxie authored and ryanisgrig committed Sep 30, 2019
1 parent 3ba2d2b commit d6825be
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
- tell me about the {MovieTitle=jurassic park} movie
- tell me about the movie {MovieTitle=gone with the wind}
- what is {MovieTitle=jurassic park}
- whats {MovieTitle=hello} about?
- whats the move {MovieTitle=harry potter} about?
- what's {MovieTitle=hello} about?
- what's the move {MovieTitle=harry potter} about?
- how is {MovieTitlePatten}
- tell me about the {MovieTitlePatten} movie
- what's {MovieTitlePatten} about?
- whats the move {MovieTitlePatten} about?
- whats {MovieTitlePatten} about
- whats {MovieTitlePatten} about?
- what's the move {MovieTitlePatten} about?
- what's {MovieTitlePatten} about
- what's {MovieTitlePatten} about?
- tell me about the movie {MovieTitlePatten}
- what's {MovieTitlePatten} about

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private async Task<DialogTurnResult> ShowResult(WaterfallStepContext stepContext
var bingSearchKey = Settings.BingSearchKey ?? throw new Exception("The BingSearchKey must be provided to use this dialog. Please provide this key in your Skill Configuration.");
var bingAnswerSearchKey = Settings.BingAnswerSearchKey ?? throw new Exception("The BingSearchKey must be provided to use this dialog. Please provide this key in your Skill Configuration.");
var client = new BingSearchClient(bingSearchKey, bingAnswerSearchKey);
var entitiesResult = await client.GetSearchResult(state.SearchEntityName, state.SearchEntityType);
// https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cognitive-services/Labs/Answer-Search/overview.md
var entitiesResult = await client.GetSearchResult(state.SearchEntityName, "en-us", state.SearchEntityType);

Activity prompt = null;
if (entitiesResult != null && entitiesResult.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ private async Task<Entities> GetEntitySearchResult(string query)
}
}

public async Task<List<SearchResultModel>> GetSearchResult(string query, SearchResultModel.EntityType queryType = SearchResultModel.EntityType.Unknown)
public async Task<List<SearchResultModel>> GetSearchResult(string query, string locale, SearchResultModel.EntityType queryType = SearchResultModel.EntityType.Unknown)
{
var results = new List<SearchResultModel>();
var answerSearchResult = await GetAnswerSearchResult(query);
var answerSearchResult = await GetAnswerSearchResult(query, locale);
if (answerSearchResult != null)
{
results.Add(answerSearchResult);
Expand Down Expand Up @@ -114,11 +114,11 @@ public async Task<List<SearchResultModel>> GetSearchResult(string query, SearchR
}
}

private async Task<SearchResultModel> GetAnswerSearchResult(string query)
private async Task<SearchResultModel> GetAnswerSearchResult(string query, string locale)
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _bingAnswerSearchKey);
var responseString = await httpClient.GetStringAsync($"https://api.labs.cognitive.microsoft.com/answerSearch/v7.0/search?q={query}&mkt=en-us");
var responseString = await httpClient.GetStringAsync($"https://api.labs.cognitive.microsoft.com/answerSearch/v7.0/search?q={query}&mkt={locale}");
var responseJson = JToken.Parse(responseString);
var factsJson = responseJson["facts"];
if (factsJson != null)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
- 去 2 a {Keyword=融合餐厅}
- 去 2 a {Keyword=车库}
- {Address=吉布斯村} 地图我怎么才能去那里
- {Keyword=来自地球的礼物} 上 {Address=} 在城里,请我怎么去那里
- {Keyword=来自地球的礼物} 上 {Address=法院} 在城里,请我怎么去那里
- {Keyword=哈德里安的墙} 在这里,请我怎么去那里
- 让我们去一个 {Keyword=君主酒馆} 在 {Address=罗切斯特大道} 和 {Address=杰克逊法院}
- 让我们去一个 {Keyword=帕内拉面包} 在 {Address=麦克基弗地方} 和 {Address=约翰逊街}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ public MockServiceManager()
mockClient = new HttpClient(new MockHttpClientHandlerGen().GetMockHttpClientHandler());
}

public IGeoSpatialService InitMapsService(BotSettings services, string locale = "en-us")
public IGeoSpatialService InitMapsService(BotSettings settings, string locale = "en-us")
{
services.Properties.TryGetValue("FoursquareClientId", out var clientId);
services.Properties.TryGetValue("FoursquareClientSecret", out var clientSecret);

var clientIdStr = (string)clientId;
var clientSecretStr = (string)clientSecret;
var clientIdStr = settings.FoursquareClientId;
var clientSecretStr = settings.FoursquareClientSecret;

if (clientIdStr != null && clientSecretStr != null)
{
return new FoursquareGeoSpatialService().InitClientAsync(clientIdStr, clientSecretStr, MockData.Radius, MockData.Limit, MockData.RouteLimit, MockData.Locale, mockClient).Result;
}
else
{
var key = GetAzureMapsKey(services);
var key = GetAzureMapsKey(settings);

return new AzureMapsGeoSpatialService().InitKeyAsync(key, MockData.Radius, MockData.Limit, MockData.RouteLimit, locale, mockClient).Result;
}
Expand All @@ -47,11 +44,9 @@ public IGeoSpatialService InitRoutingMapsService(BotSettings services, string lo
return new AzureMapsGeoSpatialService().InitKeyAsync(key, MockData.Radius, MockData.Limit, MockData.RouteLimit, locale, mockClient).Result;
}

protected string GetAzureMapsKey(BotSettings services)
protected string GetAzureMapsKey(BotSettings settings)
{
services.Properties.TryGetValue("AzureMapsKey", out var key);

var keyStr = (string)key;
var keyStr = settings.AzureMapsKey;
if (string.IsNullOrWhiteSpace(keyStr))
{
throw new Exception("Could not get the required Azure Maps key. Please make sure your settings are correctly configured.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public override void Initialize()
Services = new ServiceCollection();
Services.AddSingleton(new BotSettings()
{
Properties = new Dictionary<string, string>()
{
{ "AzureMapsKey", MockData.Key }
}
AzureMapsKey = MockData.Key
});
Services.AddSingleton(new BotServices()
{
Expand Down

0 comments on commit d6825be

Please sign in to comment.