Skip to content

Commit b28b474

Browse files
authored
New LG components for manually evaluating an LG template (#394)
1 parent 754c595 commit b28b474

7 files changed

Lines changed: 243 additions & 8 deletions

Bot.Builder.Community.sln

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,13 @@ EndProject
148148
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Components.Dialogs.Input", "libraries\Bot.Builder.Community.Components.Dialogs.Input\Bot.Builder.Community.Components.Dialogs.Input.csproj", "{4999E3C2-0281-411E-9A5E-660832A5ABE7}"
149149
EndProject
150150
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Components.TokenExchangeSkillHandler", "libraries\Bot.Builder.Community.Components.TokenExchangeSkillHandler\Bot.Builder.Community.Components.TokenExchangeSkillHandler.csproj", "{97B74354-8D6B-482B-A779-2E20B38DF0DD}"
151+
EndProject
151152
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Components.Handoff.ServiceNow", "libraries\Bot.Builder.Community.Components.Handoff.ServiceNow\Bot.Builder.Community.Components.Handoff.ServiceNow.csproj", "{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}"
152153
EndProject
153154
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot.Builder.Community.Components.TokenExchangeSkillHandler.Tests", "tests\Bot.Builder.Community.Components.TokenExchangeSkillHandler.Tests\Bot.Builder.Community.Components.TokenExchangeSkillHandler.Tests.csproj", "{0EDBC769-26A4-4556-9D58-DF5416745187}"
154155
EndProject
156+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot.Builder.Community.Components.LanguageGeneration", "libraries\Bot.Builder.Community.Components.LanguageGeneration\Bot.Builder.Community.Components.LanguageGeneration.csproj", "{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}"
157+
EndProject
155158
Global
156159
GlobalSection(SolutionConfigurationPlatforms) = preSolution
157160
Debug - NuGet Packages|Any CPU = Debug - NuGet Packages|Any CPU
@@ -638,14 +641,6 @@ Global
638641
{97B74354-8D6B-482B-A779-2E20B38DF0DD}.Documentation|Any CPU.Build.0 = Debug|Any CPU
639642
{97B74354-8D6B-482B-A779-2E20B38DF0DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
640643
{97B74354-8D6B-482B-A779-2E20B38DF0DD}.Release|Any CPU.Build.0 = Release|Any CPU
641-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
642-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
643-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
644-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug|Any CPU.Build.0 = Debug|Any CPU
645-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
646-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Documentation|Any CPU.Build.0 = Debug|Any CPU
647-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Release|Any CPU.ActiveCfg = Release|Any CPU
648-
{0EDBC769-26A4-4556-9D58-DF5416745187}.Release|Any CPU.Build.0 = Release|Any CPU
649644
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
650645
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
651646
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -654,6 +649,22 @@ Global
654649
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Documentation|Any CPU.Build.0 = Debug|Any CPU
655650
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
656651
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4}.Release|Any CPU.Build.0 = Release|Any CPU
652+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
653+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
654+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
655+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Debug|Any CPU.Build.0 = Debug|Any CPU
656+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
657+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Documentation|Any CPU.Build.0 = Debug|Any CPU
658+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Release|Any CPU.ActiveCfg = Release|Any CPU
659+
{0EDBC769-26A4-4556-9D58-DF5416745187}.Release|Any CPU.Build.0 = Release|Any CPU
660+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
661+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
662+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
663+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
664+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
665+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Documentation|Any CPU.Build.0 = Debug|Any CPU
666+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
667+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4}.Release|Any CPU.Build.0 = Release|Any CPU
657668
EndGlobalSection
658669
GlobalSection(SolutionProperties) = preSolution
659670
HideSolutionNode = FALSE
@@ -727,6 +738,7 @@ Global
727738
{97B74354-8D6B-482B-A779-2E20B38DF0DD} = {1F7F4CAF-CF22-491F-840D-A63835726C12}
728739
{63A62728-74B0-4BA3-9ACA-87E583BBB9B4} = {1F7F4CAF-CF22-491F-840D-A63835726C12}
729740
{0EDBC769-26A4-4556-9D58-DF5416745187} = {840D4038-9AB8-4750-9FFE-365386CE47E2}
741+
{40D170FA-AC4D-43B6-AB2A-ACCF1B5EE0F4} = {1F7F4CAF-CF22-491F-840D-A63835726C12}
730742
EndGlobalSection
731743
GlobalSection(ExtensibilityGlobals) = postSolution
732744
SolutionGuid = {9FE3B75E-BA2B-45BC-BBF0-DDA8BA10C4F0}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildThisFileDirectory)../', 'Bot.Builder.Community.sln'))\CommonTargets\library.shared.targets" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<Description>Composer actions for working more directly with the bots Language Generation (LG) system.</Description>
7+
<Authors>Bot Builder Community</Authors>
8+
<Company>Bot Builder Community</Company>
9+
<PackageLicenseUrl>https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/blob/master/LICENSE</PackageLicenseUrl>
10+
<PackageProjectUrl>https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/master/libraries/Bot.Builder.Community.Components.LanguageGeneration</PackageProjectUrl>
11+
<Version>1.0.4-preview</Version>
12+
<PackageIcon>package-icon.png</PackageIcon>
13+
<RepositoryUrl>https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/</RepositoryUrl>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<ContentTargetFolders>content</ContentTargetFolders>
16+
<PackageTags>bots;ai;botframework;botbuilder;msbot-component;msbot-action</PackageTags>
17+
<NoWarn>$(NoWarn);NU5104</NoWarn>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.Bot.Builder" Version="$(Bot_Builder_Version)" />
22+
<PackageReference Include="Microsoft.Bot.Connector" Version="$(Bot_Builder_Version)" />
23+
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="$(Bot_Builder_Version)" />
24+
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive" Version="$(Bot_Builder_Version)" />
25+
<PackageReference Include="Microsoft.Bot.Builder.LanguageGeneration" Version="$(Bot_Builder_Version)" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<Content Include="**/*.dialog" />
30+
<Content Include="**/*.lg" />
31+
<Content Include="**/*.lu" />
32+
<Content Include="**/*.schema" />
33+
<Content Include="**/*.uischema" />
34+
<Content Include="**/*.qna" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<None Remove="Schemas\BotBuilderCommunity.EvaluateLGTemplate.schema" />
39+
<None Remove="Schemas\BotBuilderCommunity.EvaluateLGTemplate.uischema" />
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<None Include="..\..\LICENSE">
44+
<Pack>True</Pack>
45+
<PackagePath></PackagePath>
46+
</None>
47+
<None Include="..\..\package-icon.png">
48+
<Pack>True</Pack>
49+
<PackagePath></PackagePath>
50+
</None>
51+
</ItemGroup>
52+
53+
</Project>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using AdaptiveExpressions.Properties;
6+
using Microsoft.Bot.Builder;
7+
using Microsoft.Bot.Builder.Dialogs;
8+
using Microsoft.Bot.Builder.Dialogs.Adaptive;
9+
using Newtonsoft.Json;
10+
11+
namespace Bot.Builder.Community.Components.LanguageGeneration
12+
{
13+
public class EvaluateLGTemplate : Dialog
14+
{
15+
[JsonConstructor]
16+
public EvaluateLGTemplate([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
17+
: base()
18+
{
19+
// enable instances of this command as debug break point
20+
this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);
21+
}
22+
23+
[JsonProperty("$kind")]
24+
public const string Kind = "BotBuilderCommunity.EvaluateLGTemplate";
25+
26+
[JsonProperty("disabled")]
27+
public BoolExpression Disabled { get; set; }
28+
29+
[JsonProperty("property")]
30+
public StringExpression Property { get; set; }
31+
32+
[JsonProperty("template")]
33+
public string Template { get; set; }
34+
35+
public async override Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
36+
{
37+
if (options is CancellationToken)
38+
{
39+
throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
40+
}
41+
42+
if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
43+
{
44+
return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
45+
}
46+
47+
// Get property name
48+
var property = Property?.GetValue(dc.State);
49+
if (String.IsNullOrEmpty(property))
50+
{
51+
throw new Exception($"{this.Id}: property name not specified.");
52+
}
53+
54+
// Get LG template
55+
if (String.IsNullOrEmpty(Template))
56+
{
57+
throw new Exception($"{this.Id}: LG template not specified.");
58+
}
59+
60+
// Evaluate template
61+
var languageGenerator = dc.Services.Get<LanguageGenerator>() ?? throw new MissingMemberException(nameof(LanguageGeneration));
62+
var lgResult = await languageGenerator.GenerateAsync(dc, Template, dc.State).ConfigureAwait(false);
63+
64+
// Copy result to property
65+
dc.State.SetValue(property, lgResult);
66+
67+
return await dc.EndDialogAsync(lgResult, cancellationToken).ConfigureAwait(false);
68+
}
69+
70+
protected override string OnComputeId()
71+
{
72+
return $"{GetType().Name}[{Template?.ToString()}]";
73+
}
74+
}
75+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AdaptiveExpressions.Converters;
2+
using Microsoft.Bot.Builder;
3+
using Microsoft.Bot.Builder.Dialogs.Declarative;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
namespace Bot.Builder.Community.Components.LanguageGeneration
8+
{
9+
/// <summary>
10+
/// <see cref="BotComponent"/> implementation for the storage actions.
11+
/// </summary>
12+
public class LanguageGenerationBotComponent : BotComponent
13+
{
14+
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
15+
{
16+
services.AddSingleton<DeclarativeType>(new DeclarativeType<EvaluateLGTemplate>(EvaluateLGTemplate.Kind));
17+
}
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.Bot.Builder.Dialogs.Declarative.Obsolete;
2+
3+
namespace Bot.Builder.Community.Components.LanguageGeneration
4+
{
5+
/// <summary>
6+
/// <see cref="LanguageGenerationComponentRegistration"/> implementation for adaptive components.
7+
/// </summary>
8+
public class LanguageGenerationComponentRegistration : DeclarativeComponentRegistrationBridge<LanguageGenerationBotComponent>
9+
{
10+
}
11+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
3+
"$role": "implements(Microsoft.IDialog)",
4+
"title": "Evaluate Template",
5+
"description": "Evaluates an LG template and saves its result to a memory variable.",
6+
"type": "object",
7+
"properties": {
8+
"id": {
9+
"type": "string",
10+
"title": "Id",
11+
"description": "Optional id for the dialog"
12+
},
13+
"disabled": {
14+
"$ref": "schema:#/definitions/stringExpression",
15+
"title": "Disabled",
16+
"description": "Optional condition which if true will disable this action.",
17+
"examples": [
18+
"user.age > 3"
19+
]
20+
},
21+
"property": {
22+
"$ref": "schema:#/definitions/stringExpression",
23+
"title": "Property",
24+
"description": "Property (named location to store template results)."
25+
},
26+
"template": {
27+
"type": "string",
28+
"title": "Template",
29+
"description": "LG Template to evaluate.",
30+
"examples": [
31+
"${WelcomeUser()}",
32+
"Hello ${user.name}",
33+
"https://example.com/search?q=${turn.activity.text}"
34+
]
35+
}
36+
},
37+
"required": [ "property", "template" ]
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://schemas.botframework.com/schemas/ui/v1.0/ui.schema",
3+
"form": {
4+
"label": "Evaluate an LG Template",
5+
"subtitle": "Evaluate LG Template",
6+
"order": [
7+
"property",
8+
"template",
9+
"*"
10+
],
11+
"properties": {
12+
"property": {
13+
"intellisenseScopes": [
14+
"variable-scopes"
15+
]
16+
}
17+
}
18+
},
19+
"menu": {
20+
"label": "Evaluate an LG Template",
21+
"submenu": [ "Language Generation" ]
22+
},
23+
"flow": {
24+
"widget": "ActionCard",
25+
"body": "${coalesce(action.property, \"?\")} : ${coalesce(action.template, \"?\")}"
26+
}
27+
}

0 commit comments

Comments
 (0)