Contents

Bot Framework CLI for LUIS Management

Problem Statement

I wanted to automate the creation of my bots and the necessary services a bit. Therefore, I first took a look at what can be done in order to save time when working with LUIS. This post may be turning out to be the first of a many to come series about automating Bot Framework development and deployment. But first let’s take a look at how one can leverage the BotFramework CLI in order to create, train and publish LUIS apps using only the CLI and not the portal.

Create new LUIS app and import .lu file using BF CLI

This section will outline how to create a new LUIS app from a .lu file as well as training it and publishing it all from the BotFramework CLI .

Convert .lu to .json file

At first we need to create a new .lu file or reuse one which has already been created. For sample .lu files simply check out this link .

Typically a .lu file looks as follows:

> LUIS application information
> !# @app.name = bisserioLUISapp
> !# @app.desc = LUIS app for bisserio
> !# @app.versionId = 0.1
> !# @app.culture = en-us
> !# @app.luis_schema_version = 6.0.0

> Help intent and its utterances
# Help
- help
- i need help
- please help
- can you please help
- what do you do
- what is this bot for

> Greeting intent and its utterances
# Greeting
- hi
- hey
- hello
- good afternoon
- good evening
- good morning

> BuySurface intent and its utterances
# BuySurface
- How can I buy {ProductType=Surface PRO}
- I want to buy {ProductType=Surface PRO}
- I want to buy {ProductType=Surface laptop}
- Can I buy {ProductType=Surface PRO} online

After all intents and utterances have been setup correctly int that file we need to convert this .lu file to a .json file to be able to import it later on by using the following command:

bf luis:convert --in "pathToLuFile" --culture "cultureCodeOfLuisApp" --out "pathToJsonFile"

NOTE: The culture code needs to be in the format like “en-us” or “de-de” to be correct.

See here for more details on this command.

Import new LUIS application

Next we can import the previously created json file and create a new LUIS app from that json file using the following command:

bf luis:application:import --endpoint "https://<region>.api.cognitive.microsoft.com" --subscriptionKey "LuisSubscriptionKey" --name "LuisAppName" --in "pathToJsonFile"

NOTE: The subscriptionKey needs to be the authoringKey which you can get either from the Azure Portal or from the LUIS Portal . The region needs to be the Azure region you deployed your LUIS authoring service into.

See here for more details on this command.

This will create a new LUIS app and you should get the according App ID as a console output like this:

App successfully imported with id 2d79d034-8d67-46e7-a20e-ca087640d872.

Now copy this id as you will need that later on.

Show LUIS app

To verify if the import has been correct we can use the following command to show the LUIS app:

bf luis:application:show --appId "appIdFromPreviousCommand" --endpoint "https://<region>.api.cognitive.microsoft.com" --subscriptionKey "LuisSubscriptionKey"

See here for more details on this command.

Train LUIS app

After the application has been imported correctly we can train it before we publish it by executing this command:

bf luis:train:run --appId "appIdFromPreviousCommand" --versionId "0.1" --endpoint "https://<region>.api.cognitive.microsoft.com" --subscriptionKey "LuisSubscriptionKey"

See here for more details on this command.

After that we can verify if the train command executed successfully by executing this command:

bf luis:train:show --appId "appIdFromPreviousCommand" --versionId "0.1" --endpoint "https://<region>.api.cognitive.microsoft.com" --subscriptionKey "LuisSubscriptionKey"

See here for more details on this command.

This should output something like the following:

[
  {
    "modelId": "2881763e-7d05-4e01-9161-64efc22eaeaa",
    "details": {
      "statusId": 0,
      "status": "Success",
      "exampleCount": 22,
      "trainingDateTime": "2020-03-06T12:01:27.000Z"
    }
  },
  {
    "modelId": "c2f5279a-4fb4-45bd-82ac-fc7ea5c64d5b",
    "details": {
      "statusId": 0,
      "status": "Success",
      "exampleCount": 22,
      "trainingDateTime": "2020-03-06T12:01:27.000Z"
    }
  },
  {
    "modelId": "b867a8dd-2a0c-46f6-8a4c-730cce87920a",
    "details": {
      "statusId": 0,
      "status": "Success",
      "exampleCount": 22,
      "trainingDateTime": "2020-03-06T12:01:27.000Z"
    }
  },
  {
    "modelId": "ddc2cfe2-a545-42c7-9093-679aeff3cc7a",
    "details": {
      "statusId": 0,
      "status": "Success",
      "exampleCount": 22,
      "trainingDateTime": "2020-03-06T12:01:27.000Z"
    }
  }
]

Publish LUIS app

If the train operation has been successful, we can publish the LUIS app by executing this command:

bf luis:application:publish --endpoint "https://<region>.api.cognitive.microsoft.com" --subscriptionKey "LuisSubscriptionKey" --versionId "0.1" --appId "appIdFromPreviousCommand"

See here for more details on this command.

The output of this will look as follows:

{
  "versionId": "0.1",
  "isStaging": false,
  "endpointUrl": "https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/2d79d034-8d67-46e7-a20e-ca087640d872",
  "region": "westeurope",
  "assignedEndpointKey": null,
  "endpointRegion": "westeurope",
  "failedRegions": "",
  "publishedDateTime": "2020-03-06T12:02:09Z",
  "directVersionPublish": false
}

Now your LUIS app should be ready to use for your bot.