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

Experimental Skills (Restaurant Booking and News) #446

Merged
merged 26 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,452 changes: 1,452 additions & 0 deletions solutions/Virtual-Assistant/docs/transcripts/newsskill.transcript

Large diffs are not rendered by default.

3,909 changes: 3,909 additions & 0 deletions solutions/Virtual-Assistant/docs/transcripts/restaurantbooking.transcript

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Experimental Skills

## Overview

Experimental Skills are early prototypes of Skills to help bring skill concepts to life for demonstrations and proof-of-concepts along with providing different examples to get you started.

These skills by their very nature are not complete, will likely have rudimentary language models, limited language support and limited testing hence are located in a experimental folder to ensure this is understood before you make use of them.

## Restaurant Booking Skill

The [Restaurant Booking skill](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/src/csharp/experimental/skills/restaurantbooking) provides a simple restaurant booking experience guiding the user through booking a table and leverages Adaptive Cards throughout to demonstrate how Speech, Text and UX can be combined for a compelling user experience. No integration to restaurant booking services exists at this time so is simulated with static data for testing purposes.

An example transcript file demonstrating the Skill in action can be found [here](./transcripts/restaurantbooking.transcript), you can use the Bot Framework Emulator to open transcripts.

![ Restaurant Booking Transcript Example](./media/skills-restaurant-transcript.png)

## News Skill

The [News skill](https://github.com/Microsoft/AI/blob/master/solutions/Virtual-Assistant/src/csharp/experimental/skills/newsskill) provides a simple Skill that integrates with the Bing News Cognitive Service to demonstrate how a news experience can be integrated into a Virtual Assistant.

An example transcript file demonstrating the Skill in action can be found [here](./transcripts/newsskill.transcript), you can use the Bot Framework Emulator to open transcripts.

![ News Skill Transcript Example](./media/skills-news-transcript.png)

## Deploying Experimental Skills in local-mode

Experimental Skills not added by default when deploying the Virtual Assistant due to their experimental nature.

Run this PowerShell script to deploy shared resources and LUIS models required for an experimental skill.

```
PowerShell.exe -ExecutionPolicy Bypass -File DeploymentScripts\deploy_bot.ps1
```

You will be prompted to provide the following parameters:
- Name - A name for your bot and resource group. This must be **unique**.
- Location - The Azure region for your services (e.g. westus)
- LUIS Authoring Key - Refer to [this documentation page](./virtualassistant-createvirtualassitant.md) for retrieving this key.

The msbot tool will outline the deployment plan including location and SKU. Ensure you review before proceeding.

> After deployment is complete, it's **imperative** that you make a note of the .bot file secret provided as this will be required for later steps. The secret can be found near the top of the execution output and will be in purple text.

- Update your `appsettings.json` file with the newly created .bot file name and .bot file secret.
- Run the following command and retrieve the InstrumentationKey for your Application Insights instance and update `InstrumentationKey` in your `appsettings.json` file.

```
msbot list --bot YOURBOTFILE.bot --secret YOUR_BOT_SECRET
```

```
{
"botFilePath": ".\\YOURBOTFILE.bot",
"botFileSecret": "YOUR_BOT_SECRET",
"ApplicationInsights": {
"InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
}
}
```

- Finally, add the .bot file paths for each of your language configurations (English only at this time).

```
"defaultLocale": "en-us",
"languageModels": {
"en": {
"botFilePath": ".\\LocaleConfigurations\\YOUR_EN_BOT_PATH.bot",
"botFileSecret": ""
}
}
```
## Testing the skill in local-mode

Once you have followed the deployment instructions above, open the provided .bot file with the Bot Framework Emulator.

## Adding Experimental Skills to your Virtual Assistant deployment.

Instructions on how to add experimental skills will be available soon.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
> # Intent definitions

## FindArticles
- find me news about {topic=xbox}
- find me news on {topic=microsoft}
- find news about {topic}
- latest news
- news about {topic=microsoft}
- news about {topic=the stock market}
- {topic=sports} news
- tell me the news
- whats the latest news
- whats the latest news on {topic=brexit}
- whats the latest on {topic=microsoft}
- what's the latest on {topic=usa}
- whats the news
- what's the latest on {topic}
- whats the latest news on {topic}
- find me news on {topic}
- find news on {topic}
- news about {topic}

## None

> # Entity definitions

$topic:simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
"Version": "8.13.10627.1",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?LinkID=798432"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "1.0",
"resources": [
{
"type": "endpoint",
"id": "1",
"name": "development",
"url": "http://localhost:3980/api/messages"
},
{
"type": "endpoint",
"id": "108",
"name": "production",
"url": "https://your-bot-url.azurewebsites.net/api/messages"
},
{
"type": "abs",
"id": "199",
"name": "ABS"
},
{
"type": "blob",
"id": "2",
"name": "AzStorage",
"container": "transcripts"
},
{
"type": "appInsights",
"id": "3",
"name": "AppInsights"
},
{
"type": "cosmosdb",
"id": "8",
"name": "CosmosDB",
"database": "botstate-db",
"collection": "botstate-collection"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# all msbot clone parameters and locales
Param(
[string] [Parameter(Mandatory=$true)]$name,
[string] [Parameter(Mandatory=$true)]$location,
[string] [Parameter(Mandatory=$true)]$luisAuthoringKey,
[string] $locales = "en-us",
[switch] $languagesOnly,
[string] $luisAuthoringRegion,
[string] $luisPublishRegion,
[string] $subscriptionId,
[string] $insightsRegion,
[string] $groupName,
[string] $sdkLanguage,
[string] $sdkVersion,
[string] $prefix,
[string] $appId,
[string] $appSecret
)

if (!$languagesOnly)
{
# Change to project directory for .bot file
Write-Host "Changing to project directory ..."
cd "$($PSScriptRoot)\..\"

# Deploy the common resources (Azure Bot Service, App Insights, Azure Storage, Cosmos DB, etc)
Write-Host "Deploying common resources..."
msbot clone services -n $name -l $location --luisAuthoringKey $luisAuthoringKey --folder "$($PSScriptRoot)" --appId $appId --appSecret $appSecret --force --quiet
}

$localeArr = $locales.Split(',')

foreach ($locale in $localeArr)
{
# Update deployment scripts for the locale
Invoke-Expression "$($PSScriptRoot)\generate_deployment_scripts.ps1 -locale $($locale)"

# Get language code from locale (first two characters, i.e. "en")
$langCode = ($locale -split "-")[0]

# Create LocaleConfigurations folder and change directory
md -Force "$($PSScriptRoot)\..\LocaleConfigurations" > $null
cd "$($PSScriptRoot)\..\LocaleConfigurations" > $null

# Deploy Dispatch, LUIS (calendar, email, todo, and general), and QnA Maker for the locale
Write-Host "Deploying $($locale) resources..."
msbot clone services -n "$($name)$($langCode)" -l $location --luisAuthoringKey $luisAuthoringKey --groupName $name --force --quiet --folder "$($PSScriptRoot)\$($langCode)" | Out-Null
}

Write-Host "Done."
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0",
"resources": [
{
"type": "luis",
"id": "general",
"name": "General"
},
{
"type": "luis",
"id": "news",
"name": "news"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
param (
[string] [Parameter(Mandatory=$true)]$locale
)

$langCode = ($locale -split "-")[0]
$basePath = "$($PSScriptRoot)\.."
$outputPath = "$($PSScriptRoot)\$($langCode)"

# lu file paths
$newsLUPath = "$($basePath)\CognitiveModels\LUIS\$($langCode)\news.lu"
$generalLUPath = "$($basePath)..\..\..\..\..\..\assistant\CognitiveModels\LUIS\$($langCode)\general.lu"

$luArr = @($newsLUPath, $generalLUPath)

Write-Host "Updating $($locale) deployment scripts ..."
foreach ($lu in $luArr)
{
$duplicates = Get-Content $lu | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name

if ($duplicates.Count -gt 1)
{
Write-Error "$($duplicates.Count - 1) duplicate utterances found in $($lu). This could cause issues in your model accuracy."
}
}

Write-Host "Generating $($locale) LUIS and QnA Maker models from .lu files ..."
ludown parse toluis -c $($locale) -o $outputPath --in $newsLUPath --out news.luis -n news
ludown parse toluis -c $($locale) -o $outputPath --in $generalLUPath --out general.luis -n General
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ECHO Updating deployment files in News Skill

call ludown parse toluis --in ..\..\..\..\..\assistant\CognitiveModels\LUIS\en\general.lu -o %0\..\en -n General --out general.luis
call ludown parse toluis --in ..\CognitiveModels\LUIS\en\news.lu -o %0\..\en -n news --out news.luis

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
param (
[string] $locales = "de-de,en-us,es-es,fr-fr,it-it,zh-cn",
[string] $domains = "general,calendar"
)

$localeArr = $locales.Split(",")
$domainArr = $domains.Split(",")
$basePath = "$($PSScriptRoot)\..\LocaleConfigurations\"
$botFiles = get-childitem $basePath -recurse | where {$_.extension -eq ".bot"}

Write-Host "Updating deployment scripts..."
foreach ($locale in $localeArr)
{
Invoke-Expression "$($PSScriptRoot)\generate_deployment_scripts.ps1 -locale $($locale)"
}

foreach ($botFile in $botFiles)
{
$botFileName = $botFile | % {$_.BaseName}
$langCode = $botFileName.Substring($botFileName.Length - 2, 2)

if ($localeArr | where {$_ -like "*$($langCode)*"})
{
Write-Host "Updating $($langCode) LUIS models ..."
foreach ($domain in $domainArr)
{
# Check for existing old version
$versions = msbot get $domain --bot "$($basePath)$($botFile)" | luis list versions --stdin | ConvertFrom-Json
if ($versions | where {$_.version -eq "backup"})
{
msbot get $domain --bot "$($basePath)$($botFile)" | luis delete version --stdin --versionId backup --force --wait
}

msbot get $domain --bot "$($basePath)$($botFile)" | luis rename version --newVersionId backup --stdin --wait
msbot get $domain --bot "$($basePath)$($botFile)" | luis import version --stdin --in "$($PSScriptRoot)\$($langCode)\$($domain).luis" --wait
msbot get $domain --bot "$($basePath)$($botFile)" | luis train version --wait --stdin
msbot get $domain --bot "$($basePath)$($botFile)" | luis publish version --stdin
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Solutions.Skills;

namespace NewsSkill
{
public class FindArticlesDialog : NewsDialog
{
private NewsClient _client;
private FindArticlesResponses _responder = new FindArticlesResponses();

public FindArticlesDialog(
ISkillConfiguration services,
IStatePropertyAccessor<NewsSkillState> accessor)
: base(nameof(FindArticlesDialog), services, accessor)
{
Accessor = accessor;

var key = services.Properties["BingNewsKey"] ?? throw new Exception("The BingNewsKey must be provided to use this dialog. Please provide this key in your Skill Configuration.");

_client = new NewsClient((string)key);

var findArticles = new WaterfallStep[]
{
GetQuery,
ShowArticles,
};

AddDialog(new WaterfallDialog(nameof(FindArticlesDialog), findArticles));
AddDialog(new TextPrompt(nameof(TextPrompt)));
}

private async Task<DialogTurnResult> GetQuery(WaterfallStepContext sc, CancellationToken cancellationToken)
{
var state = await Accessor.GetAsync(sc.Context, () => new NewsSkillState());

// Let's see if we have a topic
if (state.LuisResult.Entities.topic != null)
{
// If we have a topic let's skip the topic prompt
if (state.LuisResult.Entities.topic.Length > 0)
{
return await sc.NextAsync(state.LuisResult.Entities.topic[0]);
}
}

return await sc.PromptAsync(nameof(TextPrompt), new PromptOptions()
{
Prompt = await _responder.RenderTemplate(sc.Context, sc.Context.Activity.Locale, FindArticlesResponses.TopicPrompt)
});
}

private async Task<DialogTurnResult> ShowArticles(WaterfallStepContext sc, CancellationToken cancellationToken)
{
var query = (string)sc.Result;
var articles = await _client.GetNewsForTopic(query);
await _responder.ReplyWith(sc.Context, FindArticlesResponses.ShowArticles, articles);

return await sc.EndDialogAsync();
}
}
}
Loading