5 types derived from AIFunction
Microsoft.Extensions.AI.Abstractions (2)
Functions\AIFunctionFactory.cs (1)
531private sealed class ReflectionAIFunction : AIFunction
Functions\DelegatingAIFunction.cs (1)
17public class DelegatingAIFunction : AIFunction
Microsoft.Extensions.AI.Abstractions.Tests (2)
Contents\FunctionCallContentTests.cs (1)
331private sealed class NetTypelessAIFunction : AIFunction
Functions\AIFunctionTests.cs (1)
19private sealed class DerivedAIFunction : AIFunction
Microsoft.Extensions.AI.Integration.Tests (1)
ChatClientIntegrationTests.cs (1)
511private sealed class CustomAIFunction(string name, string jsonSchema, IReadOnlyDictionary<string, object?> additionalProperties) : AIFunction
333 references to AIFunction
Aspire.Dashboard (2)
Model\Assistant\AIHelpers.cs (1)
300AIFunction[] tools,
Model\Assistant\AssistantChatViewModel.cs (1)
194private readonly AIFunction[] _aiTools;
Microsoft.AspNetCore.Components.AI (9)
Blocks\UIActionBlock.cs (3)
13/// <see cref="UIAgentOptions.RegisterUIAction(AIFunction)"/>. Renderers can call 25private readonly AIFunction _function; 31internal UIActionBlock(AIFunction function, FunctionCallContent call)
Engine\UIAgent.cs (1)
176foreach (var action in _options.UIActions.Values)
Pipeline\UIActionHandler.cs (3)
10private readonly IReadOnlyDictionary<string, AIFunction> _actions; 12internal UIActionHandler(IReadOnlyDictionary<string, AIFunction> actions) 28_actions.TryGetValue(call.Name, out var function))
Pipeline\UIAgentOptions.cs (2)
28internal Dictionary<string, AIFunction> UIActions { get; } = 55public void RegisterUIAction(AIFunction function)
Microsoft.Extensions.AI (22)
ChatCompletion\FunctionInvocationContext.cs (2)
18private static readonly AIFunction _nopFunction = AIFunctionFactory.Create(() => { }, nameof(FunctionInvocationContext)); 26public 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, 1123if (tool is not AIFunction)
Common\FunctionInvocationProcessor.cs (3)
66Func<FunctionCallContent, AIFunction, int, FunctionInvocationContext> createContext, 110Func<FunctionCallContent, AIFunction, int, FunctionInvocationContext> createContext, 123if (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"/>), 299if (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 55private 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 127public 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"/> 202public 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 299public 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"/> 384public 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 492public 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> 23public 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. 24protected DelegatingAIFunction(AIFunction innerFunction) 29/// <summary>Gets the inner <see cref="AIFunction" />.</summary> 30protected 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. 61public JsonElement GetOrCreateTransformedSchema(AIFunction function) =>
Microsoft.Extensions.AI.Abstractions.Tests (17)
Contents\FunctionCallContentTests.cs (4)
194AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 216AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 249AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 270AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Functions\ApprovalRequiredAIFunctionTests.cs (2)
21var inner = AIFunctionFactory.Create(() => 42); 37var inner = AIFunctionFactory.Create(() => "result");
Functions\DelegatingAIFunctionTests.cs (6)
23AIFunction expected = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => 42)); 38private sealed class DerivedFunction(AIFunction innerFunction) : DelegatingAIFunction(innerFunction) 40public new AIFunction InnerFunction => base.InnerFunction; 65AIFunction inner = AIFunctionFactory.Create(int () => 71AIFunction actual = new OverridesInvocation(inner, (args, ct) => new ValueTask<object?>(84)); 88private sealed class OverridesInvocation(AIFunction innerFunction, Func<AIFunctionArguments, CancellationToken, ValueTask<object?>> invokeAsync) : DelegatingAIFunction(innerFunction)
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (4)
291AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 345AIFunction func = AIFunctionFactory.Create(( 366AIFunction func = AIFunctionFactory.Create((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options); 414AIFunction 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)
301AIFunction func = AIFunctionFactory.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById"); 333AIFunction func = AIFunctionFactory.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson"); 365AIFunction func = AIFunctionFactory.Create((string[] items, string shopperId) => { shoppingCart.AddRange(items); shopperName = shopperId; }, "AddItemsToShoppingCart"); 431Func<string, AIFunction> createWithSchema = schema => 597var tool = AIFunctionFactory.Create(() => 620var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 621var shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp"); 717var getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () => 756var getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () => 798var getTemperature = AIFunctionFactory.Create([Description("Gets the current temperature")] () => 1220var getWeather = AIFunctionFactory.Create(([Description("Gets weather for a city")] string city) =>
PromptBasedFunctionCallingChatClient.cs (1)
169var toolDescriptorsJson = JsonSerializer.Serialize(tools.OfType<AIFunction>().Select(t => t.JsonSchema), _jsonOptions);
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (2)
OllamaSharpChatClientIntegrationTests.cs (2)
67var stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] ( 77var 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)
537if (tool is AIFunction aiFunction && !string.IsNullOrEmpty(aiFunction.Name))
Microsoft.Extensions.AI.OpenAI.Tests (39)
OpenAIChatClientTests.cs (4)
384AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 461AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 544AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 618AIFunction 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)
24private static readonly AIFunction _testFunction = AIFunctionFactory.Create(
OpenAIResponseClientIntegrationTests.cs (8)
858AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); 859AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); 914AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); 962AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); 963AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); 1004AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); 1005AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); 1006AIFunction getCustomer = AIFunctionFactory.Create((string id) => $"Customer {id}", "GetCustomer", "Gets a customer by id.");
OpenAIResponseClientTests.cs (26)
1232AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 7448var getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather."); 7449var getForecast = AIFunctionFactory.Create(() => 42, "GetForecast", "Gets the forecast."); 7540var getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather."); 7541var importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool."); 7716var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 7717var listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders."); 7718var importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool."); 7817var getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather."); 7818var getTime = AIFunctionFactory.Create(() => 42, "GetTime", "Gets the time."); 7922var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 7923var getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather."); 8022var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 8023var listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders."); 8109var sharedTool = AIFunctionFactory.Create(() => 42, "SharedTool", "A shared tool."); 8201var localFunc = AIFunctionFactory.Create(() => 42, "LocalFunc", "A local function."); 8286var localFunc = AIFunctionFactory.Create(() => 42, "LocalFunc", "A local function."); 8398var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 8399var listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders."); 8400var importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool."); 8497var getWeather = AIFunctionFactory.Create(() => 42, "GetWeather", "Gets the weather."); 8498var importantTool = AIFunctionFactory.Create(() => 42, "ImportantTool", "An important tool."); 8602var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 8603var listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders."); 8715var getCustomer = AIFunctionFactory.Create(() => 42, "GetCustomer", "Gets a customer."); 8716var listOrders = AIFunctionFactory.Create(() => 42, "ListOrders", "Lists orders.");
Microsoft.Extensions.AI.Tests (121)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51AIFunction function = AIFunctionFactory.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (3)
102AIFunction func1 = AIFunctionFactory.Create(() => "Result 1", "Func1"); 103AIFunction func2 = AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"); 149private sealed class PassThroughDelegatingAIFunction(AIFunction inner) : DelegatingAIFunction(inner);
ChatCompletion\FunctionInvokingChatClientTests.cs (25)
814var originalTool = AIFunctionFactory.Create(() => "Result", "Func1"); 1269var function = AIFunctionFactory.Create(async (int i) => 1344var function = AIFunctionFactory.Create((string? result = null) => 1598var known = AIFunctionFactory.Create(() => { invoked++; return "OK"; }, "Known"); 2359AIFunction functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB"); 2362AIFunction functionA = AIFunctionFactory.Create( 2453AIFunction functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB"); 2456AIFunction functionA = AIFunctionFactory.Create( 2554AIFunction originalFunctionB = AIFunctionFactory.Create(() => "Original FunctionB result", "FunctionB"); 2555AIFunction replacementFunctionB = AIFunctionFactory.Create(() => "Replacement FunctionB result", "FunctionB"); 2558AIFunction functionA = AIFunctionFactory.Create( 2659AIFunction additionalTool = AIFunctionFactory.Create(() => "AdditionalTool result", "AdditionalTool"); 2660AIFunction functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB"); 2663AIFunction functionA = AIFunctionFactory.Create( 2762AIFunction additionalToolSameName = AIFunctionFactory.Create(() => "AdditionalTool version", "SharedName"); 2763AIFunction addedToolSameName = AIFunctionFactory.Create(() => "Added version", "SharedName"); 2766AIFunction functionA = AIFunctionFactory.Create( 2866AIFunction functionA = AIFunctionFactory.Create( 2939AIFunction functionB = AIFunctionFactory.Create(() => "FunctionB result", "FunctionB"); 2942AIFunction functionA = AIFunctionFactory.Create( 3040AIFunction functionB = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => "FunctionB result", "FunctionB")); 3043AIFunction functionA = AIFunctionFactory.Create( 3142AIFunction originalFunctionB = AIFunctionFactory.Create(() => "Original FunctionB result", "FunctionB"); 3143AIFunction replacementFunctionB = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(() => "Replacement FunctionB result", "FunctionB")); 3146AIFunction functionA = AIFunctionFactory.Create(
ChatCompletion\ImageGeneratingChatClientTests.cs (10)
60Assert.IsAssignableFrom<AIFunction>(chatOptions.Tools[0]); 98var generateImageFunction = capturedOptions.Tools[0] as AIFunction; 99var editImageFunction = capturedOptions.Tools[1] as AIFunction; 100var getImagesForEditImageFunction = capturedOptions.Tools[2] as AIFunction; 130var dummyFunction = AIFunctionFactory.Create(() => "dummy", name: "DummyFunction"); 146Assert.IsAssignableFrom<AIFunction>(capturedOptions.Tools[1]); // GenerateImage function 147Assert.IsAssignableFrom<AIFunction>(capturedOptions.Tools[2]); // EditImage function
Functions\AIFunctionFactoryTest.cs (74)
46AIFunction func; 61AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 70AIFunction funcNull = AIFunctionFactory.Create(([DefaultValue(null)] string? text) => text ?? "was null"); 85AIFunction funcValue = AIFunctionFactory.Create(([DefaultValue("default")] string text) => text); 94AIFunction funcInt = AIFunctionFactory.Create(([DefaultValue(42)] int x) => x * 2); 103AIFunction funcBoth = AIFunctionFactory.Create(([DefaultValue(100)] int y = 50) => y); 114AIFunction[] funcs = 123foreach (AIFunction f in funcs) 133AIFunction func = AIFunctionFactory.Create((int x, int y, int z, int w, int u) => x + y + z + w + u); 162AIFunction func = AIFunctionFactory.Create((JsonElement param) => param, serializerOptions: options); 182AIFunction func = AIFunctionFactory.Create((JsonElement param) => param); 201AIFunction func = AIFunctionFactory.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) => 215AIFunction func; 264AIFunction func; 293AIFunction func = AIFunctionFactory.Create(funcWithDisplayName); 325AIFunction func = AIFunctionFactory.Create(funcWithAttribute); 342AIFunction func = AIFunctionFactory.Create([AIFunctionName("my_tool")] ([AIParameterName("my_param")] string myParam) => myParam); 349Assert.IsNotAssignableFrom<AIFunction>(declaration); 355AIFunction func = AIFunctionFactory.Create(([AIParameterName("$select")] string select, int top) => select + top); 363AIFunction func = AIFunctionFactory.Create( 388AIFunction func = AIFunctionFactory.Create( 405AIFunction func = AIFunctionFactory.Create(overrideMethod, new MyDerivedType()); 418AIFunction func = AIFunctionFactory.Create( 469AIFunction f = AIFunctionFactory.Create(overrideMethod, new DerivedDescribed()); 508AIFunction func = AIFunctionFactory.Create(dotnetFunc, options); 533AIFunction func = AIFunctionFactory.Create( 618AIFunction func = AIFunctionFactory.Create( 638AIFunction func = AIFunctionFactory.Create(( 682AIFunction func = AIFunctionFactory.Create(( 714AIFunction func = AIFunctionFactory.Create( 732AIFunction func = AIFunctionFactory.Create( 743AIFunction func = AIFunctionFactory.Create( 762AIFunction func = AIFunctionFactory.Create( 781AIFunction func = AIFunctionFactory.Create( 800AIFunction func = AIFunctionFactory.Create( 827AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger, 850AIFunction f = AIFunctionFactory.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger, 873AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) => 892AIFunction f = AIFunctionFactory.Create( 944AIFunction f = AIFunctionFactory.Create( 961AIFunction f = AIFunctionFactory.Create( 977AIFunction f = AIFunctionFactory.Create( 1000AIFunction f = AIFunctionFactory.Create( 1023AIFunction f = AIFunctionFactory.Create( 1046AIFunction f = AIFunctionFactory.Create( 1069AIFunction f = AIFunctionFactory.Create( 1092AIFunction f = AIFunctionFactory.Create( 1115AIFunction f = AIFunctionFactory.Create( 1138AIFunction f = AIFunctionFactory.Create( 1205static async Task ValidateAsync<T>(IEnumerable<AIFunction> functions) 1207foreach (var f in functions) 1219AIFunction f = AIFunctionFactory.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options); 1230AIFunction f = AIFunctionFactory.Create( 1263AIFunction f = AIFunctionFactory.Create( 1293AIFunction f = AIFunctionFactory.Create(Add, serializerOptions: JsonContext.Default.Options); 1419var tool = AIFunctionFactory.Create(DoSomething); 1438var tool1 = AIFunctionFactory.Create(FirstLocal); 1439var tool2 = AIFunctionFactory.Create(SecondLocal); 1455var tool = AIFunctionFactory.Create(lambda); 1474var tool1 = AIFunctionFactory.Create(lambda1); 1475var tool2 = AIFunctionFactory.Create(lambda2); 1489var tool = AIFunctionFactory.Create(Add); 1505var tool = AIFunctionFactory.Create(FetchDataAsync); 1522var tool = AIFunctionFactory.Create(DoSomething, name: "CustomName"); 1531var tool = AIFunctionFactory.Create(Add, serializerOptions: JsonContext.Default.Options); 1543var tool = AIFunctionFactory.Create(TestStaticMethod, null, serializerOptions: JsonContext.Default.Options); 1553AIFunction func = AIFunctionFactory.Create( 1593AIFunction func = AIFunctionFactory.Create( 1672AIFunction func = AIFunctionFactory.Create(testDelegate.GetMethodInfo(), testDelegate.Target); 1696AIFunction func = AIFunctionFactory.Create( 1723AIFunction func = AIFunctionFactory.Create( 1742AIFunction func = AIFunctionFactory.Create( 1774AIFunction func = AIFunctionFactory.Create( 1797AIFunction func = AIFunctionFactory.Create(
Realtime\FunctionInvokingRealtimeClientTests.cs (8)
91AIFunction getWeather = AIFunctionFactory.Create( 141AIFunction getWeather = AIFunctionFactory.Create( 179AIFunction countFunc = AIFunctionFactory.Create( 219AIFunction myFunc = AIFunctionFactory.Create( 285AIFunction failFunc = AIFunctionFactory.Create( 323AIFunction failFunc = AIFunctionFactory.Create( 448AIFunction slowFunc = AIFunctionFactory.Create( 515AIFunction failFunc = AIFunctionFactory.Create(