Skip to content

Commit

Permalink
Update LG samples and docs to 4.7.0 (microsoft#2052)
Browse files Browse the repository at this point in the history
* first LG JS sample

* first sample with LG

* updates

* cards sample

* core bot with lg

* interim updates with docs. Pending C# samples

* Updating all LG Csharp samples to 4.7.0

* Fixing readme.

* Fix up

* Add receipt card to sample

* Updates based on PR comments
  • Loading branch information
vishwacsena authored Dec 19, 2019
1 parent f1d9e1d commit 24ea48e
Show file tree
Hide file tree
Showing 83 changed files with 5,072 additions and 144 deletions.
40 changes: 32 additions & 8 deletions experimental/language-generation/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Language Generation ***_[PREVIEW]_***

> See [here](#Change-Log) for what's new in **4.6 PREVIEW 2** release.
> See [here](#Change-Log) for what's new in **4.7.0 PREVIEW** release.
Learning from our customers experiences and bringing together capabilities first implemented by Cortana and Cognition teams, we are introducing Language Generation; which allows the developer to extract the embedded strings from their code and resource files and manage them through a Language Generation runtime and file format. Language Generation enable customers to define multiple variations on a phrase, execute simple expressions based on context, refer to conversational memory, and over time will enable us to bring additional capabilities all leading to a more natural conversational experience.

Expand Down Expand Up @@ -52,10 +52,10 @@ For NodeJS

```typescript
// multi lg files
let lgEngine = new TemplateEngine.addFiles(filePaths, importResolver?);
let lgEngine = new TemplateEngine().addFiles(filePaths, importResolver?);

// single lg file
let lgEngine = new TemplateEngine.addFile(filePath, importResolver?);
let lgEngine = new TemplateEngine().addFile(filePath, importResolver?);
```
When you need template expansion, call the templateEngine and pass in the relevant template name
Expand All @@ -69,7 +69,7 @@ For C#
For NodeJS
```typescript
await turnContext.sendActivity(lgEngine.evaluateTemplate("<TemplateName>", entitiesCollection));
await turnContext.sendActivity(ActivityFactory.createActivity(lgEngine.evaluateTemplate("<TemplateName>", entitiesCollection)));
```
If your template needs specific entity values to be passed for resolution/ expansion, you can pass them in on the call to `evaluateTemplate`
Expand All @@ -83,8 +83,8 @@ For C#
For NodeJS
```node
await turnContext.sendActivity(lgEngine.evaluateTemplate("WordGameReply", { GameName = "MarcoPolo" } ));
```typescript
await turnContext.sendActivity(ActivityFactory.createActivity(lgEngine.evaluateTemplate("WordGameReply", { GameName = "MarcoPolo" } )));
```
## Multi-lingual generation and language fallback policy
Expand All @@ -95,10 +95,31 @@ Quite often your bot might target more than one spoken/ display language. To do
The current library does not include any capabilities for grammar check or correction.
## Packages
Latest preview packages are available here
- C# -> [NuGet][14]
- JS -> [npm][15]
Packages for C# are available under the [BotBuilder MyGet feed][12]
Nightly packages for C# are available here
- C# -> [BotBuilder MyGet feed][12]
- JS -> [BotBuilder MyGet feed][13]
## Change Log
### 4.7 PREVIEW
- \[**BREAKING CHANGES**\]:
- Old way to refer to a template via `[TemplateName]` notation is deprecated in favor of `@{TemplateName()}` notation. There are no changes to how structured response templates are defined.
- All expressions must now be enclosed within `@{<expression>}`. The old notation `{<expression>}` is no longer supported.
- `ActivityBuilder` has been deprecated and removed in favor of `ActivityFactory`. Note that by stable release, functionality offered by `ActivityFactory` is likely to move into `MessageFactory`.
| Old | New |
|-------|-----|
| # myTemplate <br/> - I have {user.name} as your name | # myTemplate <br/> - I have @{user.name} as your name |
| # myTemplate <br/> - [ackPhrase] <br/><br/> # ackPhrase <br/> - hi <br/>- hello | # myTemplate <br/> - @{ackPhrase()} <br/><br/> # ackPhrase <br/> - hi <br/>- hello |
- \[**NEW**\]:
- Language generation preview is now available for JavaScript as well. Checkout packages [here][15]. Samples are [here][26]
- New `ActivityFactory` class that helps transform structured response template output from LG into a Bot framework activity.
- Bug fixes and stability improvements.
### 4.6 PREVIEW 2
- \[**BREAKING CHANGES**\]:
- Old `display || speak` notation is deprecated in favor of structured template support. See below for more details on structured template.
Expand Down Expand Up @@ -130,9 +151,12 @@ Packages for C# are available under the [BotBuilder MyGet feed][12]
[10]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#message-cards
[11]:https://github.com/Microsoft/botbuilder-tools/tree/master/packages/Chatdown#message-attachments
[12]:https://botbuilder.myget.org/F/botbuilder-v4-dotnet-daily/api/v3/index.json
[13]:https://botbuilder.myget.org/gallery/botbuilder-v4-js-daily
[14]:https://www.nuget.org/packages/Microsoft.Bot.Builder.LanguageGeneration/4.7.0-preview
[15]:https://www.npmjs.com/package/botbuilder-lg
[20]:./docs/lg-file-format.md#Switch..Case
[21]:./docs/lg-file-format.md#Importing-external-references
[22]:https://aka.ms/lg-vscode-extension
[23]:https://github.com/microsoft/botbuilder-tools/tree/V.Future/packages/MSLG
[25]:./csharp_dotnetcore/05.a.multi-turn-prompt-with-language-fallback/
[26]:./javascript_nodejs/
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using Microsoft.Bot.Builder;
using Microsoft.Extensions.Logging;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.LanguageGeneration;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;
using System.Collections.Generic;

namespace Microsoft.BotBuilderSamples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
using System.Collections.Generic;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;

using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;
namespace Microsoft.BotBuilderSamples
{
public class UserProfileDialog : ComponentDialog
Expand Down Expand Up @@ -117,7 +116,7 @@ private async Task<DialogTurnResult> ConfirmStepAsync(WaterfallStepContext stepC
}, stepContext);

// We can send messages to the user at any point in the WaterfallStep.
await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(msg), cancellationToken);
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(msg.ToString()), cancellationToken);

// WaterfallStep always finishes with the end of the Waterfall or with another dialog, here it is a Prompt Dialog.
return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions {
Expand All @@ -138,7 +137,7 @@ private async Task<DialogTurnResult> SummaryStepAsync(WaterfallStepContext stepC

var msg = _lgGenerator.GenerateActivity("SummaryReadout", userProfile, stepContext);

await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(msg), cancellationToken);
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(msg.ToString()), cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Collections.Generic;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Builder.LanguageGeneration;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;
using System;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs.Adaptive;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;

namespace Microsoft.BotBuilderSamples
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private Activity InternalGenerateActivity(string templateName, object data, stri

if (TemplateEnginesPerLocale.ContainsKey(iLocale))
{
return ActivityBuilder.GenerateFromLG(TemplateEnginesPerLocale[locale].EvaluateTemplate(templateName, data));
return ActivityFactory.CreateActivity(TemplateEnginesPerLocale[locale].EvaluateTemplate(templateName, data).ToString());
}
var locales = new string[] { string.Empty };
if (!LangFallBackPolicy.TryGetValue(iLocale, out locales))
Expand All @@ -120,7 +120,7 @@ private Activity InternalGenerateActivity(string templateName, object data, stri
{
if (TemplateEnginesPerLocale.ContainsKey(fallBackLocale))
{
return ActivityBuilder.GenerateFromLG(TemplateEnginesPerLocale[fallBackLocale].EvaluateTemplate(templateName, data));
return ActivityFactory.CreateActivity(TemplateEnginesPerLocale[fallBackLocale].EvaluateTemplate(templateName, data).ToString());
}
}
return new Activity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.LanguageGeneration" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.LanguageGeneration" Version="4.7.0-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.7.0-preview" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.LanguageGeneration;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;

namespace Microsoft.BotBuilderSamples
{
Expand All @@ -29,7 +29,7 @@ public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger<B
logger.LogError($"Exception caught : {exception.Message}");

// Send a catch-all apology to the user.
await turnContext.SendActivityAsync(ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("SomethingWentWrong", exception)));
await turnContext.SendActivityAsync(ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("SomethingWentWrong", exception).ToString()));

if (conversationState != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Bot.Builder.LanguageGeneration;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;

namespace Microsoft.BotBuilderSamples
{
Expand Down Expand Up @@ -55,7 +55,7 @@ private static async Task<DialogTurnResult> TransportStepAsync(WaterfallStepCont
new PromptOptions
{

Prompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("ModeOfTransportPrompt")),
Prompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("ModeOfTransportPrompt").ToString()),
Choices = ChoiceFactory.ToChoices(new List<string> { "Car", "Bus", "Bicycle" }),
}, cancellationToken);
}
Expand All @@ -64,20 +64,20 @@ private static async Task<DialogTurnResult> NameStepAsync(WaterfallStepContext s
{
stepContext.Values["transport"] = ((FoundChoice)stepContext.Result).Value;

return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("AskForName")) }, cancellationToken);
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("AskForName").ToString()) }, cancellationToken);
}

private async Task<DialogTurnResult> NameConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
stepContext.Values["name"] = (string)stepContext.Result;

// We can send messages to the user at any point in the WaterfallStep.
await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("AckName", new {
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("AckName", new {
Result = stepContext.Result
})), cancellationToken);
}).ToString()), cancellationToken);

// WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog.
return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("AgeConfirmPrompt")) }, cancellationToken);
return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("AgeConfirmPrompt").ToString()) }, cancellationToken);
}

private async Task<DialogTurnResult> AgeStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
Expand All @@ -88,8 +88,8 @@ private async Task<DialogTurnResult> AgeStepAsync(WaterfallStepContext stepConte
// WaterfallStep always finishes with the end of the Waterfall or with another dialog, here it is a Prompt Dialog.
var promptOptions = new PromptOptions
{
Prompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("AskForAge")),
RetryPrompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("AskForAge.reprompt")),
Prompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("AskForAge").ToString()),
RetryPrompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("AskForAge.reprompt").ToString()),
};

return await stepContext.PromptAsync(nameof(NumberPrompt<int>), promptOptions, cancellationToken);
Expand All @@ -111,10 +111,10 @@ private async Task<DialogTurnResult> ConfirmStepAsync(WaterfallStepContext stepC
});

// We can send messages to the user at any point in the WaterfallStep.
await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(msg), cancellationToken);
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(msg.ToString()), cancellationToken);

// WaterfallStep always finishes with the end of the Waterfall or with another dialog, here it is a Prompt Dialog.
return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("ConfirmPrompt")) }, cancellationToken);
return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("ConfirmPrompt").ToString()) }, cancellationToken);
}

private async Task<DialogTurnResult> SummaryStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
Expand All @@ -130,11 +130,11 @@ private async Task<DialogTurnResult> SummaryStepAsync(WaterfallStepContext stepC

var msg = _lgEngine.EvaluateTemplate("SummaryReadout", userProfile);

await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(msg), cancellationToken);
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(msg.ToString()), cancellationToken);
}
else
{
await stepContext.Context.SendActivityAsync(ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("NoProfileReadBack")), cancellationToken);
await stepContext.Context.SendActivityAsync(ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("NoProfileReadBack").ToString()), cancellationToken);
}

// WaterfallStep always finishes with the end of the Waterfall or with another dialog, here it is the end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.LanguageGeneration" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.6.0-preview2" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.Bot.Builder.LanguageGeneration" Version="4.7.0-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="4.7.0-preview" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.LanguageGeneration;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using ActivityBuilder = Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ActivityGenerator;

using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;
namespace Microsoft.BotBuilderSamples
{
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
Expand All @@ -29,7 +28,7 @@ public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger<B
logger.LogError($"Exception caught : {exception.Message}");

// Send a catch-all apology to the user.
await turnContext.SendActivityAsync(ActivityBuilder.GenerateFromLG(_lgEngine.EvaluateTemplate("SomethingWentWrong", exception)));
await turnContext.SendActivityAsync(ActivityFactory.CreateActivity(_lgEngine.EvaluateTemplate("SomethingWentWrong", exception).ToString()));

if (conversationState != null)
{
Expand Down
Loading

0 comments on commit 24ea48e

Please sign in to comment.