5 types derived from AIFunction
Microsoft.Extensions.AI.Abstractions (2)
Functions\AIFunctionFactory.cs (1)
531
private sealed class ReflectionAIFunction :
AIFunction
Functions\DelegatingAIFunction.cs (1)
17
public class DelegatingAIFunction :
AIFunction
Microsoft.Extensions.AI.Abstractions.Tests (2)
Contents\FunctionCallContentTests.cs (1)
331
private sealed class NetTypelessAIFunction :
AIFunction
Functions\AIFunctionTests.cs (1)
19
private sealed class DerivedAIFunction :
AIFunction
Microsoft.Extensions.AI.Integration.Tests (1)
ChatClientIntegrationTests.cs (1)
511
private sealed class CustomAIFunction(string name, string jsonSchema, IReadOnlyDictionary<string, object?> additionalProperties) :
AIFunction
333 references to AIFunction
Aspire.Dashboard (2)
Model\Assistant\AIHelpers.cs (1)
300
AIFunction
[] tools,
Model\Assistant\AssistantChatViewModel.cs (1)
194
private readonly
AIFunction
[] _aiTools;
Microsoft.AspNetCore.Components.AI (9)
Blocks\UIActionBlock.cs (3)
13
/// <see cref="UIAgentOptions.RegisterUIAction(
AIFunction
)"/>. Renderers can call
25
private readonly
AIFunction
_function;
31
internal UIActionBlock(
AIFunction
function, FunctionCallContent call)
Engine\UIAgent.cs (1)
176
foreach (
var
action in _options.UIActions.Values)
Pipeline\UIActionHandler.cs (3)
10
private readonly IReadOnlyDictionary<string,
AIFunction
> _actions;
12
internal UIActionHandler(IReadOnlyDictionary<string,
AIFunction
> actions)
28
_actions.TryGetValue(call.Name, out
var
function))
Pipeline\UIAgentOptions.cs (2)
28
internal Dictionary<string,
AIFunction
> UIActions { get; } =
55
public void RegisterUIAction(
AIFunction
function)
Microsoft.Extensions.AI (22)
ChatCompletion\FunctionInvocationContext.cs (2)
18
private static readonly
AIFunction
_nopFunction = AIFunctionFactory.Create(() => { }, nameof(FunctionInvocationContext));
26
public
AIFunction
Function
ChatCompletion\FunctionInvokingChatClient.cs (8)
31
/// <see cref="IChatClient"/>, it responds by invoking the corresponding <see cref="
AIFunction
"/> defined
37
/// If a requested function is an <see cref="AIFunctionDeclaration"/> but not an <see cref="
AIFunction
"/>, the
57
/// <see cref="
AIFunction
"/> instances employed as part of the supplied <see cref="ChatOptions"/> are also safe.
87
/// <param name="functionInvocationServices">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="
AIFunction
"/> instances being invoked.</param>
260
/// <see cref="ChatOptions.Tools"/> or <see cref="AdditionalTools"/>) but that aren't <see cref="
AIFunction
"/>s aren't considered
267
/// <summary>Gets or sets a delegate used to invoke <see cref="
AIFunction
"/> instances.</summary>
269
/// By default, the protected <see cref="InvokeFunctionAsync"/> method is called for each <see cref="
AIFunction
"/> to be invoked,
1123
if (tool is not
AIFunction
)
Common\FunctionInvocationProcessor.cs (3)
66
Func<FunctionCallContent,
AIFunction
, int, FunctionInvocationContext> createContext,
110
Func<FunctionCallContent,
AIFunction
, int, FunctionInvocationContext> createContext,
123
if (tool is not
AIFunction
aiFunction)
Realtime\FunctionInvokingRealtimeClient.cs (3)
22
/// <see cref="IRealtimeClientSession"/>, they respond by invoking the corresponding <see cref="
AIFunction
"/> defined
39
/// <param name="functionInvocationServices">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="
AIFunction
"/> instances being invoked.</param>
121
/// <summary>Gets or sets a delegate used to invoke <see cref="
AIFunction
"/> instances.</summary>
Realtime\FunctionInvokingRealtimeClientSession.cs (6)
30
/// <see cref="IRealtimeClientSession"/>, it responds by invoking the corresponding <see cref="
AIFunction
"/> defined
36
/// If a requested function is an <see cref="AIFunctionDeclaration"/> but not an <see cref="
AIFunction
"/>, the
43
/// <see cref="
AIFunction
"/> instances employed as part of the supplied <see cref="CreateResponseRealtimeClientMessage"/> are also safe.
82
/// <param name="functionInvocationServices">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="
AIFunction
"/> instances being invoked.</param>
272
/// If a function call references a non-invocable tool (a declaration but not an <see cref="
AIFunction
"/>),
299
if (tool is not
AIFunction
)
Microsoft.Extensions.AI.Abstractions (107)
Functions\AIFunction.cs (7)
14
/// <summary>Initializes a new instance of the <see cref="
AIFunction
"/> class.</summary>
20
/// Gets the underlying <see cref="MethodInfo"/> that this <see cref="
AIFunction
"/> might be wrapping.
30
/// <summary>Invokes the <see cref="
AIFunction
"/> and returns its result.</summary>
39
/// <summary>Invokes the <see cref="
AIFunction
"/> and returns its result.</summary>
47
/// <summary>Creates a <see cref="AIFunctionDeclaration"/> representation of this <see cref="
AIFunction
"/> that can't be invoked.</summary>
50
/// <see cref="
AIFunction
"/> derives from <see cref="AIFunctionDeclaration"/>, layering on the ability to invoke the function in addition
55
private sealed class NonInvocableAIFunction(
AIFunction
function) : DelegatingAIFunctionDeclaration(function);
Functions\AIFunctionArguments.cs (5)
18
/// <summary>Represents arguments to be used with <see cref="
AIFunction
.InvokeAsync"/>.</summary>
21
/// as inputs to an <see cref="
AIFunction
"/>. However, an instance carries additional non-nominal
23
/// an <see cref="
AIFunction
"/> if it needs to resolve any services from a dependency injection
92
/// information for use by an <see cref="
AIFunction
"/> implementation. The meaning of this
93
/// data is left up to the implementer of the <see cref="
AIFunction
"/>.
Functions\AIFunctionDeclaration.cs (4)
11
/// <see cref="AIFunctionDeclaration"/> is the base class for <see cref="
AIFunction
"/>, which
14
/// and can type test for <see cref="
AIFunction
"/> to determine whether they can be invoked.
43
/// When an <see cref="
AIFunction
"/> is created via <see cref="AIFunctionFactory"/>, this schema is automatically derived from the
55
/// When an <see cref="
AIFunction
"/> is created via <see cref="AIFunctionFactory"/>, this schema is automatically derived from the
Functions\AIFunctionFactory.cs (66)
30
/// <summary>Provides factory methods for creating commonly-used implementations of <see cref="
AIFunction
"/>.</summary>
33
/// The <see cref="AIFunctionFactory"/> class creates <see cref="
AIFunction
"/> instances that wrap .NET methods
54
/// <summary>Creates an <see cref="
AIFunction
"/> instance for a method, specified via a delegate.</summary>
55
/// <param name="method">The method to be represented via the created <see cref="
AIFunction
"/>.</param>
57
/// <returns>The created <see cref="
AIFunction
"/> for invoking <paramref name="method"/>.</returns>
61
/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="
AIFunction
"/>'s
66
/// the invocation via <see cref="
AIFunction
.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
78
/// passed into <see cref="
AIFunction
.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
79
/// instance passed to <see cref="
AIFunction
.InvokeAsync"/> is <see langword="null"/>, the <see cref="
AIFunction
"/> implementation
85
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="
AIFunction
.InvokeAsync"/>
90
/// into <see cref="
AIFunction
.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
118
/// returned <see cref="
AIFunction
"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning
127
public static
AIFunction
Create(Delegate method, AIFunctionFactoryOptions? options)
134
/// <summary>Creates an <see cref="
AIFunction
"/> instance for a method, specified via a delegate.</summary>
135
/// <param name="method">The method to be represented via the created <see cref="
AIFunction
"/>.</param>
137
/// The name to use for the <see cref="
AIFunction
"/>. If <see langword="null"/>, the name will be derived from
142
/// The description to use for the <see cref="
AIFunction
"/>. If <see langword="null"/>, a description will be derived from
146
/// <returns>The created <see cref="
AIFunction
"/> for invoking <paramref name="method"/>.</returns>
150
/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="
AIFunction
"/>'s
155
/// the invocation via <see cref="
AIFunction
.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
166
/// passed into <see cref="
AIFunction
.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
167
/// instance passed to <see cref="
AIFunction
.InvokeAsync"/> is <see langword="null"/>, the <see cref="
AIFunction
"/> implementation
172
/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="
AIFunction
.InvokeAsync"/>
202
public static
AIFunction
Create(Delegate method, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null)
219
/// Creates an <see cref="
AIFunction
"/> instance for a method, specified via an <see cref="MethodInfo"/> instance
222
/// <param name="method">The method to be represented via the created <see cref="
AIFunction
"/>.</param>
228
/// <returns>The created <see cref="
AIFunction
"/> for invoking <paramref name="method"/>.</returns>
232
/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="
AIFunction
"/>'s
237
/// the invocation via <see cref="
AIFunction
.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
249
/// passed into <see cref="
AIFunction
.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
250
/// instance passed to <see cref="
AIFunction
.InvokeAsync"/> is <see langword="null"/>, the <see cref="
AIFunction
"/> implementation
256
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="
AIFunction
.InvokeAsync"/>
261
/// into <see cref="
AIFunction
.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
287
/// returned <see cref="
AIFunction
"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning
299
public static
AIFunction
Create(MethodInfo method, object? target, AIFunctionFactoryOptions? options)
307
/// Creates an <see cref="
AIFunction
"/> instance for a method, specified via an <see cref="MethodInfo"/> instance
310
/// <param name="method">The method to be represented via the created <see cref="
AIFunction
"/>.</param>
316
/// The name to use for the <see cref="
AIFunction
"/>. If <see langword="null"/>, the name will be derived from
321
/// The description to use for the <see cref="
AIFunction
"/>. If <see langword="null"/>, a description will be derived from
325
/// <returns>The created <see cref="
AIFunction
"/> for invoking <paramref name="method"/>.</returns>
329
/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="
AIFunction
"/>'s
334
/// the invocation via <see cref="
AIFunction
.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
345
/// passed into <see cref="
AIFunction
.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
346
/// instance passed to <see cref="
AIFunction
.InvokeAsync"/> is <see langword="null"/>, the <see cref="
AIFunction
"/> implementation
351
/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="
AIFunction
.InvokeAsync"/>
384
public static
AIFunction
Create(MethodInfo method, object? target, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null)
401
/// Creates an <see cref="
AIFunction
"/> instance for a method, specified via a <see cref="MethodInfo"/> for
403
/// the receiver object each time the <see cref="
AIFunction
"/> is invoked.
405
/// <param name="method">The instance method to be represented via the created <see cref="
AIFunction
"/>.</param>
412
/// <returns>The created <see cref="
AIFunction
"/> for invoking <paramref name="method"/>.</returns>
424
/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="
AIFunction
"/>'s
429
/// the invocation via <see cref="
AIFunction
.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
441
/// passed into <see cref="
AIFunction
.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
442
/// instance passed to <see cref="
AIFunction
.InvokeAsync"/> is <see langword="null"/>, the <see cref="
AIFunction
"/> implementation
448
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="
AIFunction
.InvokeAsync"/>
453
/// into <see cref="
AIFunction
.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
479
/// returned <see cref="
AIFunction
"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning
492
public static
AIFunction
Create(
507
/// but not invoke it. To create an invocable <see cref="
AIFunction
"/>, use Create. A non-invocable <see cref="AIFunctionDeclaration"/>
508
/// can also be created from an invocable <see cref="
AIFunction
"/> using that function's <see cref="
AIFunction
.AsDeclarationOnly"/> method.
Functions\AIFunctionFactoryOptions.cs (12)
15
/// Represents options that can be provided when creating an <see cref="
AIFunction
"/> from a method.
34
/// the produced <see cref="
AIFunction
"/> throws if the supplied <see cref="AIFunctionArguments"/> contains keys
76
/// this delegate will be invoked once for each parameter in the function as part of creating the <see cref="
AIFunction
"/> instance.
78
/// provided to the <see cref="
AIFunction
.InvokeAsync"/> invocation.
87
/// <summary>Gets or sets a delegate used to determine the <see cref="object"/> returned by <see cref="
AIFunction
.InvokeAsync"/>.</summary>
90
/// By default, the return value of invoking the method wrapped into an <see cref="
AIFunction
"/> by <see cref="AIFunctionFactory"/>
91
/// is then JSON serialized, with the resulting <see cref="JsonElement"/> returned from the <see cref="
AIFunction
.InvokeAsync"/> method.
95
/// and its return value is then returned from the <see cref="
AIFunction
.InvokeAsync"/> method.
99
/// a <see langword="null"/> argument. By default, <see langword="null"/> is returned from the <see cref="
AIFunction
.InvokeAsync"/>
100
/// method for <see cref="
AIFunction
"/> instances produced by <see cref="AIFunctionFactory"/> to wrap
145
/// If non- <see langword="null"/>, each time the <see cref="
AIFunction
"/> is invoked, this delegate will be invoked
162
/// It, however, is permissible for cases where invocation of the <see cref="
AIFunction
"/> is tightly controlled, and the caller
Functions\AIFunctionNameAttribute.cs (1)
11
/// <summary>Specifies the name to use for an <see cref="
AIFunction
"/>.</summary>
Functions\AIParameterNameAttribute.cs (1)
11
/// <summary>Specifies the schema name to use for an <see cref="
AIFunction
"/> parameter.</summary>
Functions\ApprovalRequiredAIFunction.cs (4)
9
/// Represents an <see cref="
AIFunction
"/> that can be described to an AI service and invoked, but for which
13
/// This class simply augments an <see cref="
AIFunction
"/> with an indication that approval is required before invocation.
21
/// <param name="innerFunction">The <see cref="
AIFunction
"/> represented by this instance.</param>
23
public ApprovalRequiredAIFunction(
AIFunction
innerFunction)
Functions\DelegatingAIFunction.cs (4)
15
/// Provides an optional base class for an <see cref="
AIFunction
"/> that passes through calls to another instance.
24
protected DelegatingAIFunction(
AIFunction
innerFunction)
29
/// <summary>Gets the inner <see cref="
AIFunction
" />.</summary>
30
protected
AIFunction
InnerFunction { get; }
Utilities\AIJsonSchemaTransformCache.cs (3)
16
/// This cache stores weak references from AI abstractions that declare JSON schemas such as <see cref="
AIFunction
"/> or <see cref="ChatResponseFormatJson"/>
56
/// Gets or creates a transformed JSON schema for the specified <see cref="
AIFunction
"/> instance.
61
public JsonElement GetOrCreateTransformedSchema(
AIFunction
function) =>
Microsoft.Extensions.AI.Abstractions.Tests (17)
Contents\FunctionCallContentTests.cs (4)
194
AIFunction
function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
216
AIFunction
function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
249
AIFunction
function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
270
AIFunction
function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Functions\ApprovalRequiredAIFunctionTests.cs (2)
21
var
inner = AIFunctionFactory.Create(() => 42);
37
var
inner = AIFunctionFactory.Create(() => "result");
Functions\DelegatingAIFunctionTests.cs (6)
23
AIFunction
expected = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => 42));
38
private sealed class DerivedFunction(
AIFunction
innerFunction) : DelegatingAIFunction(innerFunction)
40
public new
AIFunction
InnerFunction => base.InnerFunction;
65
AIFunction
inner = AIFunctionFactory.Create(int () =>
71
AIFunction
actual = new OverridesInvocation(inner, (args, ct) => new ValueTask<object?>(84));
88
private sealed class OverridesInvocation(
AIFunction
innerFunction, Func<AIFunctionArguments, CancellationToken, ValueTask<object?>> invokeAsync) : DelegatingAIFunction(innerFunction)
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51
AIFunction
func = AIFunctionFactory.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (4)
291
AIFunction
func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options);
345
AIFunction
func = AIFunctionFactory.Create((
366
AIFunction
func = AIFunctionFactory.Create((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options);
414
AIFunction
func = AIFunctionFactory.Create(([Range(1, 10)] int num, [StringLength(100, MinimumLength = 1)] string str) => num + str.Length, serializerOptions: options);
Microsoft.Extensions.AI.Integration.Tests (12)
ChatClientIntegrationTests.cs (11)
301
AIFunction
func = AIFunctionFactory.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById");
333
AIFunction
func = AIFunctionFactory.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson");
365
AIFunction
func = AIFunctionFactory.Create((string[] items, string shopperId) => { shoppingCart.AddRange(items); shopperName = shopperId; }, "AddItemsToShoppingCart");
431
Func<string,
AIFunction
> createWithSchema = schema =>
597
var
tool = AIFunctionFactory.Create(() =>
620
var
getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber");
621
var
shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp");
717
var
getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () =>
756
var
getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () =>
798
var
getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () =>
1220
var
getWeather = AIFunctionFactory.Create(([Description("Gets weather for a city")] string city) =>
PromptBasedFunctionCallingChatClient.cs (1)
169
var toolDescriptorsJson = JsonSerializer.Serialize(tools.OfType<
AIFunction
>().Select(t => t.JsonSchema), _jsonOptions);
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (2)
OllamaSharpChatClientIntegrationTests.cs (2)
67
var
stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] (
77
var
irrelevantTool = AIFunctionFactory.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
Microsoft.Extensions.AI.OpenAI (2)
MicrosoftExtensionsAIResponsesExtensions.cs (1)
150
/// such as <see cref="
AIFunction
"/>, <see cref="HostedWebSearchTool"/>, <see cref="HostedMcpServerTool"/>, or
OpenAIRealtimeClientSession.cs (1)
537
if (tool is
AIFunction
aiFunction && !string.IsNullOrEmpty(aiFunction.Name))
Microsoft.Extensions.AI.OpenAI.Tests (39)
OpenAIChatClientTests.cs (4)
384
AIFunction
tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
461
AIFunction
tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
544
AIFunction
tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
618
AIFunction
tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
OpenAIConversionTests.cs (1)
24
private static readonly
AIFunction
_testFunction = AIFunctionFactory.Create(
OpenAIResponseClientIntegrationTests.cs (8)
858
AIFunction
getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
859
AIFunction
getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time.");
914
AIFunction
getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
962
AIFunction
getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
963
AIFunction
getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time.");
1004
AIFunction
getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
1005
AIFunction
getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time.");
1006
AIFunction
getCustomer = AIFunctionFactory.Create((string id) => $"Customer {id}", "GetCustomer", "Gets a customer by id.");
OpenAIResponseClientTests.cs (26)
1232
AIFunction
tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
7448
var
getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather.");
7449
var
getForecast = AIFunctionFactory.Create(() => 42, "GetForecast", "Gets the forecast.");
7540
var
getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather.");
7541
var
importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool.");
7716
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
7717
var
listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
7718
var
importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool.");
7817
var
getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather.");
7818
var
getTime = AIFunctionFactory.Create(() => 42, "GetTime", "Gets the time.");
7922
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
7923
var
getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather.");
8022
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
8023
var
listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
8109
var
sharedTool = AIFunctionFactory.Create(() => 42, "SharedTool", "A shared tool.");
8201
var
localFunc = AIFunctionFactory.Create(() => 42, "LocalFunc", "A local function.");
8286
var
localFunc = AIFunctionFactory.Create(() => 42, "LocalFunc", "A local function.");
8398
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
8399
var
listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
8400
var
importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool.");
8497
var
getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather.");
8498
var
importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool.");
8602
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
8603
var
listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
8715
var
getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer.");
8716
var
listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
Microsoft.Extensions.AI.Tests (121)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51
AIFunction
function = AIFunctionFactory.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (3)
102
AIFunction
func1 = AIFunctionFactory.Create(() => "Result 1", "Func1");
103
AIFunction
func2 = AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2");
149
private sealed class PassThroughDelegatingAIFunction(
AIFunction
inner) : DelegatingAIFunction(inner);
ChatCompletion\FunctionInvokingChatClientTests.cs (25)
814
var
originalTool = AIFunctionFactory.Create(() => "Result", "Func1");
1269
var
function = AIFunctionFactory.Create(async (int i) =>
1344
var
function = AIFunctionFactory.Create((string? result = null) =>
1598
var
known = AIFunctionFactory.Create(() => { invoked++; return "OK"; }, "Known");
2359
AIFunction
functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB");
2362
AIFunction
functionA = AIFunctionFactory.Create(
2453
AIFunction
functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB");
2456
AIFunction
functionA = AIFunctionFactory.Create(
2554
AIFunction
originalFunctionB = AIFunctionFactory.Create(() => "Original FunctionB result", "FunctionB");
2555
AIFunction
replacementFunctionB = AIFunctionFactory.Create(() => "Replacement FunctionB result", "FunctionB");
2558
AIFunction
functionA = AIFunctionFactory.Create(
2659
AIFunction
additionalTool = AIFunctionFactory.Create(() => "AdditionalTool result", "AdditionalTool");
2660
AIFunction
functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB");
2663
AIFunction
functionA = AIFunctionFactory.Create(
2762
AIFunction
additionalToolSameName = AIFunctionFactory.Create(() => "AdditionalTool version", "SharedName");
2763
AIFunction
addedToolSameName = AIFunctionFactory.Create(() => "Added version", "SharedName");
2766
AIFunction
functionA = AIFunctionFactory.Create(
2866
AIFunction
functionA = AIFunctionFactory.Create(
2939
AIFunction
functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB");
2942
AIFunction
functionA = AIFunctionFactory.Create(
3040
AIFunction
functionB = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => "FunctionB result", "FunctionB"));
3043
AIFunction
functionA = AIFunctionFactory.Create(
3142
AIFunction
originalFunctionB = AIFunctionFactory.Create(() => "Original FunctionB result", "FunctionB");
3143
AIFunction
replacementFunctionB = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => "Replacement FunctionB result", "FunctionB"));
3146
AIFunction
functionA = AIFunctionFactory.Create(
ChatCompletion\ImageGeneratingChatClientTests.cs (10)
60
Assert.IsAssignableFrom<
AIFunction
>(chatOptions.Tools[0]);
98
var
generateImageFunction = capturedOptions.Tools[0] as
AIFunction
;
99
var
editImageFunction = capturedOptions.Tools[1] as
AIFunction
;
100
var
getImagesForEditImageFunction = capturedOptions.Tools[2] as
AIFunction
;
130
var
dummyFunction = AIFunctionFactory.Create(() => "dummy", name: "DummyFunction");
146
Assert.IsAssignableFrom<
AIFunction
>(capturedOptions.Tools[1]); // GenerateImage function
147
Assert.IsAssignableFrom<
AIFunction
>(capturedOptions.Tools[2]); // EditImage function
Functions\AIFunctionFactoryTest.cs (74)
46
AIFunction
func;
61
AIFunction
func = AIFunctionFactory.Create((string a = "test") => a + " " + a);
70
AIFunction
funcNull = AIFunctionFactory.Create(([DefaultValue(null)] string? text) => text ?? "was null");
85
AIFunction
funcValue = AIFunctionFactory.Create(([DefaultValue("default")] string text) => text);
94
AIFunction
funcInt = AIFunctionFactory.Create(([DefaultValue(42)] int x) => x * 2);
103
AIFunction
funcBoth = AIFunctionFactory.Create(([DefaultValue(100)] int y = 50) => y);
114
AIFunction
[] funcs =
123
foreach (
AIFunction
f in funcs)
133
AIFunction
func = AIFunctionFactory.Create((int x, int y, int z, int w, int u) => x + y + z + w + u);
162
AIFunction
func = AIFunctionFactory.Create((JsonElement param) => param, serializerOptions: options);
182
AIFunction
func = AIFunctionFactory.Create((JsonElement param) => param);
201
AIFunction
func = AIFunctionFactory.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) =>
215
AIFunction
func;
264
AIFunction
func;
293
AIFunction
func = AIFunctionFactory.Create(funcWithDisplayName);
325
AIFunction
func = AIFunctionFactory.Create(funcWithAttribute);
342
AIFunction
func = AIFunctionFactory.Create([AIFunctionName("my_tool")] ([AIParameterName("my_param")] string myParam) => myParam);
349
Assert.IsNotAssignableFrom<
AIFunction
>(declaration);
355
AIFunction
func = AIFunctionFactory.Create(([AIParameterName("$select")] string select, int top) => select + top);
363
AIFunction
func = AIFunctionFactory.Create(
388
AIFunction
func = AIFunctionFactory.Create(
405
AIFunction
func = AIFunctionFactory.Create(overrideMethod, new MyDerivedType());
418
AIFunction
func = AIFunctionFactory.Create(
469
AIFunction
f = AIFunctionFactory.Create(overrideMethod, new DerivedDescribed());
508
AIFunction
func = AIFunctionFactory.Create(dotnetFunc, options);
533
AIFunction
func = AIFunctionFactory.Create(
618
AIFunction
func = AIFunctionFactory.Create(
638
AIFunction
func = AIFunctionFactory.Create((
682
AIFunction
func = AIFunctionFactory.Create((
714
AIFunction
func = AIFunctionFactory.Create(
732
AIFunction
func = AIFunctionFactory.Create(
743
AIFunction
func = AIFunctionFactory.Create(
762
AIFunction
func = AIFunctionFactory.Create(
781
AIFunction
func = AIFunctionFactory.Create(
800
AIFunction
func = AIFunctionFactory.Create(
827
AIFunction
f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger,
850
AIFunction
f = AIFunctionFactory.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger,
873
AIFunction
f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) =>
892
AIFunction
f = AIFunctionFactory.Create(
944
AIFunction
f = AIFunctionFactory.Create(
961
AIFunction
f = AIFunctionFactory.Create(
977
AIFunction
f = AIFunctionFactory.Create(
1000
AIFunction
f = AIFunctionFactory.Create(
1023
AIFunction
f = AIFunctionFactory.Create(
1046
AIFunction
f = AIFunctionFactory.Create(
1069
AIFunction
f = AIFunctionFactory.Create(
1092
AIFunction
f = AIFunctionFactory.Create(
1115
AIFunction
f = AIFunctionFactory.Create(
1138
AIFunction
f = AIFunctionFactory.Create(
1205
static async Task ValidateAsync<T>(IEnumerable<
AIFunction
> functions)
1207
foreach (
var
f in functions)
1219
AIFunction
f = AIFunctionFactory.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);
1230
AIFunction
f = AIFunctionFactory.Create(
1263
AIFunction
f = AIFunctionFactory.Create(
1293
AIFunction
f = AIFunctionFactory.Create(Add, serializerOptions: JsonContext.Default.Options);
1419
var
tool = AIFunctionFactory.Create(DoSomething);
1438
var
tool1 = AIFunctionFactory.Create(FirstLocal);
1439
var
tool2 = AIFunctionFactory.Create(SecondLocal);
1455
var
tool = AIFunctionFactory.Create(lambda);
1474
var
tool1 = AIFunctionFactory.Create(lambda1);
1475
var
tool2 = AIFunctionFactory.Create(lambda2);
1489
var
tool = AIFunctionFactory.Create(Add);
1505
var
tool = AIFunctionFactory.Create(FetchDataAsync);
1522
var
tool = AIFunctionFactory.Create(DoSomething, name: "CustomName");
1531
var
tool = AIFunctionFactory.Create(Add, serializerOptions: JsonContext.Default.Options);
1543
var
tool = AIFunctionFactory.Create(TestStaticMethod, null, serializerOptions: JsonContext.Default.Options);
1553
AIFunction
func = AIFunctionFactory.Create(
1593
AIFunction
func = AIFunctionFactory.Create(
1672
AIFunction
func = AIFunctionFactory.Create(testDelegate.GetMethodInfo(), testDelegate.Target);
1696
AIFunction
func = AIFunctionFactory.Create(
1723
AIFunction
func = AIFunctionFactory.Create(
1742
AIFunction
func = AIFunctionFactory.Create(
1774
AIFunction
func = AIFunctionFactory.Create(
1797
AIFunction
func = AIFunctionFactory.Create(
Realtime\FunctionInvokingRealtimeClientTests.cs (8)
91
AIFunction
getWeather = AIFunctionFactory.Create(
141
AIFunction
getWeather = AIFunctionFactory.Create(
179
AIFunction
countFunc = AIFunctionFactory.Create(
219
AIFunction
myFunc = AIFunctionFactory.Create(
285
AIFunction
failFunc = AIFunctionFactory.Create(
323
AIFunction
failFunc = AIFunctionFactory.Create(
448
AIFunction
slowFunc = AIFunctionFactory.Create(
515
AIFunction
failFunc = AIFunctionFactory.Create(