Merge branch 'master' into v-bruhal/functestfixes8-13
This commit is contained in:
Коммит
7aec78ccec
|
@ -1,7 +1,9 @@
|
|||
---
|
||||
name: ".NET SDK Bug"
|
||||
about: Create a bug report for a bug you found in the Bot Builder .NET SDK
|
||||
|
||||
title: ""
|
||||
labels: "needs-triage, bug"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
### [Github issues](https://github.com/Microsoft/botbuilder-dotnet/issues) should be used for bugs and feature requests. Use [Stack Overflow](https://stackoverflow.com/questions/tagged/botframework) for general "how-to" questions.
|
||||
|
@ -26,6 +28,4 @@ Give a clear and concise description of what you expected to happen.
|
|||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
## Additional context
|
||||
Add any other context about the problem here.
|
||||
|
||||
[bug]
|
||||
Add any other context about the problem here.
|
|
@ -1,10 +1,12 @@
|
|||
---
|
||||
name: ".NET SDK Feature request"
|
||||
about: Suggest a feature for the Bot Builder .NET SDK
|
||||
|
||||
title: ""
|
||||
labels: "needs-triage, feature-request"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
### Use this [query](https://github.com/Microsoft/botbuilder-dotnet/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen++label%3Aenhancement) to search for the most popular feature requests.
|
||||
### Use this [query](https://github.com/Microsoft/botbuilder-dotnet/issues?q=is%3Aissue+is%3Aopen++label%3Afeature-request+) to search for the most popular feature requests.
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
@ -17,5 +19,3 @@ A clear and concise description of any alternative solutions or features you've
|
|||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
[enhancement]
|
||||
|
|
|
@ -287,7 +287,7 @@ namespace Microsoft.Bot.Builder.LanguageGeneration
|
|||
}
|
||||
|
||||
var parameters = TemplateMap[templateName].Parameters;
|
||||
var currentScope = _evaluationTargetStack.Count > 0 ? CurrentTarget().Scope : new CustomizedMemory(null);
|
||||
var currentScope = CurrentTarget().Scope;
|
||||
|
||||
if (args.Count == 0)
|
||||
{
|
||||
|
|
|
@ -427,7 +427,34 @@ namespace Microsoft.Bot.Builder.LanguageGeneration
|
|||
if (curTemplates.Any(u => u.Name == templateName))
|
||||
{
|
||||
var newGlobalName = $"{curTemplates.Namespace}.{templateName}";
|
||||
Expression.Functions.Add(newGlobalName, new ExpressionEvaluator(newGlobalName, FunctionUtils.Apply(GlobalTemplateFunction(templateName)), ReturnType.Object));
|
||||
Expression.Functions.Add(newGlobalName, new ExpressionEvaluator(
|
||||
newGlobalName,
|
||||
(expression, state, options) =>
|
||||
{
|
||||
object result = null;
|
||||
var evaluator = new Evaluator(AllTemplates.ToList(), ExpressionParser, LgOptions);
|
||||
var (args, error) = FunctionUtils.EvaluateChildren(expression, state, options);
|
||||
if (error == null)
|
||||
{
|
||||
var parameters = evaluator.TemplateMap[templateName].Parameters;
|
||||
var newScope = parameters.Zip(args, (k, v) => new { k, v })
|
||||
.ToDictionary(x => x.k, x => x.v);
|
||||
var scope = new CustomizedMemory(state, new SimpleObjectMemory(newScope));
|
||||
try
|
||||
{
|
||||
result = evaluator.EvaluateTemplate(templateName, scope);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception err)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
error = err.Message;
|
||||
}
|
||||
}
|
||||
|
||||
return (result, error);
|
||||
},
|
||||
ReturnType.Object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -622,13 +649,5 @@ namespace Microsoft.Bot.Builder.LanguageGeneration
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Func<IReadOnlyList<object>, object> GlobalTemplateFunction(string templateName)
|
||||
=> (IReadOnlyList<object> args) =>
|
||||
{
|
||||
var evaluator = new Evaluator(AllTemplates.ToList(), ExpressionParser, LgOptions);
|
||||
var newScope = evaluator.ConstructScope(templateName, args.ToList());
|
||||
return evaluator.EvaluateTemplate(templateName, newScope);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -857,22 +857,22 @@ namespace AdaptiveExpressions.Tests
|
|||
Test("ticksToDays(2193385800000000)", 2538.64097222),
|
||||
Test("ticksToHours(2193385800000000)", 60927.383333333331),
|
||||
Test("ticksToMinutes(2193385811100000)", 3655643.0185),
|
||||
Test("isMatch(getPreviousViableDate('XXXX-07-10'), '20[0-9]{2}-07-10')", true),
|
||||
Test("isMatch(getPreviousViableDate('XXXX-07-10', 'Asia/Shanghai'), '20[0-9]{2}-07-10')", true),
|
||||
Test("getPreviousViableDate('XXXX-02-29')", "2020-02-29"),
|
||||
Test("getPreviousViableDate('XXXX-02-29', 'Pacific Standard Time')", "2020-02-29"),
|
||||
Test("isMatch(getNextViableDate('XXXX-07-10'), '202[0-9]-07-10')", true),
|
||||
Test("isMatch(getNextViableDate('XXXX-07-10', 'Europe/London'), '202[0-9]-07-10')", true),
|
||||
Test("getNextViableDate('XXXX-02-29')", "2024-02-29"),
|
||||
Test("getNextViableDate('XXXX-02-29', 'America/Los_Angeles')", "2024-02-29"),
|
||||
Test("isMatch(getNextViableTime('TXX:40:20'), 'T[0-2][0-9]:40:20')", true),
|
||||
Test("isMatch(getNextViableTime('TXX:40:20', 'Asia/Tokyo'), 'T[0-2][0-9]:40:20')", true),
|
||||
Test("isMatch(getNextViableTime('TXX:05:10'), 'T[0-2][0-9]:05:10')", true),
|
||||
Test("isMatch(getNextViableTime('TXX:05:10', 'Europe/Paris'), 'T[0-2][0-9]:05:10')", true),
|
||||
Test("isMatch(getPreviousViableTime('TXX:40:20'), 'T[0-2][0-9]:40:20')", true),
|
||||
Test("isMatch(getPreviousViableTime('TXX:40:20', 'Eastern Standard Time'), 'T[0-2][0-9]:40:20')", true),
|
||||
Test("isMatch(getPreviousViableTime('TXX:05:10'), 'T[0-2][0-9]:05:10')", true),
|
||||
Test("isMatch(getPreviousViableTime('TXX:05:10', 'Central Standard Time'), 'T[0-2][0-9]:05:10')", true),
|
||||
Test("endsWith(getPreviousViableDate('XXXX-07-10'), '-07-10')", true),
|
||||
Test("endsWith(getPreviousViableDate('XXXX-07-10', 'Asia/Shanghai'), '-07-10')", true),
|
||||
Test("endsWith(getPreviousViableDate('XXXX-02-29'), '-02-29')", true),
|
||||
Test("endsWith(getPreviousViableDate('XXXX-02-29', 'Pacific Standard Time'), '-02-29')", true),
|
||||
Test("endsWith(getNextViableDate('XXXX-07-10'), '-07-10')", true),
|
||||
Test("endsWith(getNextViableDate('XXXX-07-10', 'Europe/London'), '-07-10')", true),
|
||||
Test("endsWith(getNextViableDate('XXXX-02-29'), '-02-29')", true),
|
||||
Test("endsWith(getNextViableDate('XXXX-02-29', 'America/Los_Angeles'), '-02-29')", true),
|
||||
Test("endsWith(getNextViableTime('TXX:40:20'), ':40:20')", true),
|
||||
Test("endsWith(getNextViableTime('TXX:40:20', 'Asia/Tokyo'), ':40:20')", true),
|
||||
Test("endsWith(getNextViableTime('TXX:05:10'), ':05:10')", true),
|
||||
Test("endsWith(getNextViableTime('TXX:05:10', 'Europe/Paris'), ':05:10')", true),
|
||||
Test("endsWith(getPreviousViableTime('TXX:40:20'), ':40:20')", true),
|
||||
Test("endsWith(getPreviousViableTime('TXX:40:20', 'Eastern Standard Time'), ':40:20')", true),
|
||||
Test("endsWith(getPreviousViableTime('TXX:05:10'), ':05:10')", true),
|
||||
Test("endsWith(getPreviousViableTime('TXX:05:10', 'Central Standard Time'), ':05:10')", true),
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -11,6 +11,17 @@
|
|||
"property": "user.message",
|
||||
"value": "=foo.GetMessage()"
|
||||
},
|
||||
{
|
||||
"$kind": "Microsoft.SetProperty",
|
||||
"property": "user.name",
|
||||
"value": "jonathan"
|
||||
},
|
||||
{
|
||||
"$kind": "Microsoft.SetProperty",
|
||||
"property": "user.date",
|
||||
"value": "2003-03-20"
|
||||
},
|
||||
|
||||
{
|
||||
"$kind": "Microsoft.SetProperty",
|
||||
"property": "user.tasks",
|
||||
|
@ -28,8 +39,19 @@
|
|||
{
|
||||
"$kind": "Microsoft.SendActivity",
|
||||
"activity": "${user.message}"
|
||||
},
|
||||
{
|
||||
"$kind": "Microsoft.SendActivity",
|
||||
"activity": "${foo.WelcomeUser()}"
|
||||
},
|
||||
{
|
||||
"$kind": "Microsoft.SendActivity",
|
||||
"activity": "${foo.UserDataConcat(user.date)}"
|
||||
},
|
||||
{
|
||||
"$kind": "Microsoft.SendActivity",
|
||||
"activity": "${foo.ShowTasks(foo.GetList(user.tasks))}"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -420,6 +420,9 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration.Tests
|
|||
.Send("hello")
|
||||
.AssertReply("[{\"Id\":0,\"Topic\":\"car\"},{\"Id\":1,\"Topic\":\"washing\"},{\"Id\":2,\"Topic\":\"food\"},{\"Id\":3,\"Topic\":\"laundry\"}]")
|
||||
.AssertReply("This is an injected message")
|
||||
.AssertReply("Hi Jonathan")
|
||||
.AssertReply("Jonathan : 2003-03-20")
|
||||
.AssertReply("Jonathan, your tasks: car, washing, food and laundry")
|
||||
.StartTestAsync();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
> !# @strict = false
|
||||
> !# @namespace = foo
|
||||
> !# @Exports = GetList, Convert, GetProperty, GetMessage
|
||||
> !# @Exports = GetList, Convert, GetProperty, GetMessage, UserDataConcat, WelcomeUser, ShowTasks
|
||||
|
||||
|
||||
# Convert(index, value)
|
||||
|
@ -13,4 +13,15 @@
|
|||
-user.tasks
|
||||
|
||||
#GetMessage
|
||||
- This is an injected message
|
||||
- This is an injected message
|
||||
|
||||
> Use both global and local memory
|
||||
#UserDataConcat(date)
|
||||
- ${sentenceCase(user.name)} : ${date}
|
||||
|
||||
> Use global memory
|
||||
#WelcomeUser
|
||||
- Hi ${sentenceCase(user.name)}
|
||||
|
||||
# ShowTasks(tasks)
|
||||
- ${sentenceCase(user.name)}, your tasks: ${join(foreach(tasks, task, task.value), ', ', ' and ')}
|
|
@ -92,6 +92,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Tests
|
|||
|
||||
[DataTestMethod]
|
||||
[DynamicData(nameof(Dialogs))]
|
||||
[TestCategory("IgnoreInAutomatedBuild")]
|
||||
public async Task TestDialogResourcesAreValidForSchema(Resource resource)
|
||||
{
|
||||
if (Schema == null)
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
> !# @strict = false
|
||||
> !# @Namespace = foo
|
||||
> !# @Exports = bar, cool
|
||||
> !# @Namespace = general
|
||||
> !# @Exports = sumAll, cool, greeting, addTwoNum, yolo
|
||||
|
||||
[import](common.lg)
|
||||
|
||||
#bar()
|
||||
#sumAll()
|
||||
- ${add(1,2)}
|
||||
|
||||
#cool(a)
|
||||
- ${add(1,a)}
|
||||
- ${add(1,a)}
|
||||
|
||||
#greeting
|
||||
- hi ${name}
|
||||
|
||||
#addTwoNum(a,b)
|
||||
- ${a + b}
|
||||
|
||||
# yolo(a, b)
|
||||
- ${name} have ${a + b} cookies!
|
|
@ -1481,12 +1481,33 @@ namespace Microsoft.Bot.Builder.AI.LanguageGeneration.Tests
|
|||
public void TestInjectLG()
|
||||
{
|
||||
var templates = Templates.ParseFile(GetExampleFilePath("./InjectionTest/inject.lg"));
|
||||
|
||||
var (evaled, error) = Expression.Parse("foo.bar()").TryEvaluate(null);
|
||||
|
||||
|
||||
var (evaled, error) = Expression.Parse("general.greeting()").TryEvaluate(new { name = "Alice" });
|
||||
Assert.Equal("hi Alice", evaled.ToString());
|
||||
|
||||
var memory1 = new StackedMemory();
|
||||
memory1.Push(new SimpleObjectMemory(new { name = "Alice" }));
|
||||
memory1.Push(new CustomizedMemory(new { name = "Bob" }));
|
||||
(evaled, error) = Expression.Parse("general.greeting()").TryEvaluate(memory1);
|
||||
Assert.Equal("hi Bob", evaled.ToString());
|
||||
|
||||
(evaled, error) = Expression.Parse("general.yolo(8, 7)").TryEvaluate(new { name = "Alice" });
|
||||
Assert.Equal("Alice have 15 cookies!", evaled.ToString());
|
||||
|
||||
var memory2 = new StackedMemory();
|
||||
memory2.Push(new SimpleObjectMemory(new { name = "Alice" }));
|
||||
memory2.Push(new CustomizedMemory(new { name = "Bob" }));
|
||||
(evaled, error) = Expression.Parse("general.yolo(12, 12)").TryEvaluate(memory2);
|
||||
Assert.Equal("Bob have 24 cookies!", evaled.ToString());
|
||||
|
||||
(evaled, error) = Expression.Parse("general.addTwoNum(5,6)").TryEvaluate(new { a = 3, b = 1 });
|
||||
Assert.Equal("11", evaled.ToString());
|
||||
|
||||
(evaled, error) = Expression.Parse("general.sumAll()").TryEvaluate(null);
|
||||
|
||||
Assert.Equal("3", evaled.ToString());
|
||||
|
||||
(evaled, error) = Expression.Parse("foo.cool(2)").TryEvaluate(null);
|
||||
(evaled, error) = Expression.Parse("general.cool(2)").TryEvaluate(null);
|
||||
Assert.Equal("3", evaled.ToString());
|
||||
|
||||
(evaled, error) = Expression.Parse("common.looking()").TryEvaluate(null);
|
||||
|
|
Загрузка…
Ссылка в новой задаче