1
votes

Ok so this is how my LUIS app is configured in my bot.
On the LUIS website I can add Bing Spell Check to correct common spelling mistakes and have a better intent and entity match.

All that is required is that a BING API key needs to be added to the LUIS query string. But where do I configure that in the LuisRecognizerMiddleware?

I'm not even sure if that's the right place. But I guess it does put together the URI.

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddBot<MyBot>(options =>
    {
        options.CredentialProvider = new ConfigurationCredentialProvider(_configuration);

        options.Middleware.Add(new CatchExceptionMiddleware<Exception>(async (context, exception) =>
        {
            await context.TraceActivity("MyBotException", exception);
            await context.SendActivity("Sorry, it looks like something went wrong!");
        }));

        IStorage dataStore = new MemoryStorage();

        options.Middleware.Add(new ConversationState<MyBotConversationState>(dataStore));

        // Add LUIS recognizer as middleware
        // see https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=cs
        (string modelId, string subscriptionKey, Uri url) = GetLuisConfiguration(_configuration);
        LuisModel luisModel = new LuisModel(modelId, subscriptionKey, url);
        options.Middleware.Add(new LuisRecognizerMiddleware(luisModel));
    });
}

private static (string modelId, string subscriptionKey, Uri url) GetLuisConfiguration(IConfiguration configuration)
{
    string modelId = configuration.GetSection("Luis-ModelId")?.Value;
    string subscriptionKey = configuration.GetSection("Luis-SubscriptionId")?.Value;
    string url = configuration.GetSection("Luis-Url")?.Value;
    Uri baseUri = new Uri(url);

    return (modelId, subscriptionKey, baseUri);
}

All I get so far is...

GET https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/?subscription-key=&q=test234&log=True HTTP/1.1

What I expect is something among those lines (copied from the LUIS web portal)

GET https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/?subscription-key=&spellCheck=true&bing-spell-check-subscription-key=&verbose=true&timezoneOffset=0&q=test234

1

1 Answers

1
votes

I just had a quick glimpse at the source code and figured ILuisOptions is what I am looking for. There was no concrete implementation to that. It's "roll your own" I guess...

public class MyLuisOptions : ILuisOptions
{
    public bool? Log { get; set; }
    public bool? SpellCheck { get; set; }
    public bool? Staging { get; set; }
    public double? TimezoneOffset { get; set; }
    public bool? Verbose { get; set; }
    public string BingSpellCheckSubscriptionKey { get; set; }
}

...and of course you have to pass this along to the LuisRecognizerMiddleware.

options.Middleware.Add(new LuisRecognizerMiddleware(luisModel, new LuisRecognizerOptions { Verbose = true }, new MyLuisOptions { SpellCheck = true, BingSpellCheckSubscriptionKey = "test123" }));