mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Declarative Agents (#2476)
* Update the declarative agent samples * Add the Microsoft.Agents.AI.Declarative project * Make the package non packable * Use the RecalcEngine when creating the ChatOptions * Ignore VSTHRD200 * Add geting started samples * Address code review feedback
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Globalization;
|
||||
using Microsoft.PowerFx;
|
||||
using Microsoft.PowerFx.Types;
|
||||
|
||||
namespace Microsoft.Bot.ObjectModel;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IntExpression"/>.
|
||||
/// </summary>
|
||||
internal static class IntExpressionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Evaluates the given <see cref="IntExpression"/> using the provided <see cref="RecalcEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="expression">Expression to evaluate.</param>
|
||||
/// <param name="engine">Recalc engine to use for evaluation.</param>
|
||||
/// <returns>The evaluated integer value, or null if the expression is null or cannot be evaluated.</returns>
|
||||
internal static long? Eval(this IntExpression? expression, RecalcEngine? engine)
|
||||
{
|
||||
if (expression is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (expression.IsLiteral)
|
||||
{
|
||||
return expression.LiteralValue;
|
||||
}
|
||||
|
||||
if (engine is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (expression.IsExpression)
|
||||
{
|
||||
return (long)engine.Eval(expression.ExpressionText!).AsDouble();
|
||||
}
|
||||
else if (expression.IsVariableReference)
|
||||
{
|
||||
var formulaValue = engine.Eval(expression.VariableReference!.VariableName);
|
||||
if (formulaValue is NumberValue numberValue)
|
||||
{
|
||||
return (long)numberValue.Value;
|
||||
}
|
||||
|
||||
if (formulaValue is StringValue stringValue && int.TryParse(stringValue.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user