3 types derived from AIFunction
Microsoft.Extensions.AI (1)
Functions\AIFunctionFactory.cs (1)
170private sealed class ReflectionAIFunction : AIFunction
Microsoft.Extensions.AI.Abstractions.Tests (2)
Contents\FunctionCallContentTests..cs (1)
250private sealed class NetTypelessAIFunction : AIFunction
Functions\AIFunctionTests.cs (1)
36private sealed class DerivedAIFunction : AIFunction
85 references to AIFunction
Microsoft.Extensions.AI (40)
ChatCompletion\FunctionInvokingChatClient.cs (6)
26/// by calling the corresponding <see cref="AIFunction"/> defined in <see cref="ChatOptions"/>, 31/// <see cref="AIFunction"/> instances employed as part of the supplied <see cref="ChatOptions"/> are also safe. 539AIFunction? function = options.Tools!.OfType<AIFunction>().FirstOrDefault(t => t.Metadata.Name == functionCallContent.Name); 740AIFunction function) 748public AIFunction Function { get; set; }
Functions\AIFunctionContext.cs (3)
9/// <summary>Provides additional context to the invocation of an <see cref="AIFunction"/> created by <see cref="AIFunctionFactory"/>.</summary> 13/// an <see cref="AIFunctionContext"/> parameter is passed specially by the <see cref="AIFunction"/> implementation to pass relevant 14/// context into the method's invocation. For example, any <see cref="CancellationToken"/> passed to the <see cref="AIFunction.InvokeAsync"/>
Functions\AIFunctionFactory.cs (30)
21/// <summary>Provides factory methods for creating commonly used implementations of <see cref="AIFunction"/>.</summary> 27/// <summary>Creates an <see cref="AIFunction"/> instance for a method, specified via a delegate.</summary> 28/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 30/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 33/// The resulting <see cref="AIFunction"/> exposes metadata about the function via <see cref="AIFunction.Metadata"/>. 47public static AIFunction Create(Delegate method, AIFunctionFactoryCreateOptions? options) 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> 56/// <param name="name">The name to use for the <see cref="AIFunction"/>.</param> 57/// <param name="description">The description to use for the <see cref="AIFunction"/>.</param> 59/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 62/// The resulting <see cref="AIFunction"/> exposes metadata about the function via <see cref="AIFunction.Metadata"/>. 76public static AIFunction Create(Delegate method, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null) 93/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance 96/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 102/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 105/// The resulting <see cref="AIFunction"/> exposes metadata about the function via <see cref="AIFunction.Metadata"/>. 119public static AIFunction Create(MethodInfo method, object? target, AIFunctionFactoryCreateOptions? options) 126/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance 129/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 134/// <param name="name">The name to use for the <see cref="AIFunction"/>.</param> 135/// <param name="description">The description to use for the <see cref="AIFunction"/>.</param> 137/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 140/// The resulting <see cref="AIFunction"/> exposes metadata about the function via <see cref="AIFunction.Metadata"/>. 154public static AIFunction Create(MethodInfo method, object? target, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null) 183/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
Functions\AIFunctionFactoryCreateOptions.cs (1)
14/// Represents options that can be provided when creating an <see cref="AIFunction"/> from a method.
Microsoft.Extensions.AI.Abstractions (7)
ChatCompletion\ChatToolMode.cs (1)
45/// and that the specified <see cref="AIFunction"/> must be selected. The function name
ChatCompletion\RequiredChatToolMode.cs (1)
18/// Gets the name of a specific <see cref="AIFunction"/> that must be called.
Functions\AIFunction.cs (2)
19/// <summary>Invokes the <see cref="AIFunction"/> and returns its result.</summary> 35/// <summary>Invokes the <see cref="AIFunction"/> and returns its result.</summary>
Functions\AIFunctionMetadata.cs (1)
15/// Provides read-only metadata for an <see cref="AIFunction"/>.
Functions\AIFunctionParameterMetadata.cs (1)
10/// Provides read-only metadata for an <see cref="AIFunction"/> parameter.
Functions\AIFunctionReturnParameterMetadata.cs (1)
10/// Provides read-only metadata for an <see cref="AIFunction"/>'s return parameter.
Microsoft.Extensions.AI.Abstractions.Tests (6)
Contents\FunctionCallContentTests..cs (4)
113AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 135AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 168AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 189AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Utilities\AIJsonUtilitiesTests.cs (2)
216AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 237AIFunction func = AIFunctionFactory.Create((int a, int? b, long c, short d) => { }, serializerOptions: options);
Microsoft.Extensions.AI.AzureAIInference (2)
AzureAIInferenceChatClient.cs (2)
343if (tool is AIFunction af) 377private static ChatCompletionsToolDefinition ToAzureAIChatTool(AIFunction aiFunction)
Microsoft.Extensions.AI.Integration.Tests (5)
ChatClientIntegrationTests.cs (3)
274var tool = AIFunctionFactory.Create(() => 298var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 299var shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp");
PromptBasedFunctionCallingChatClient.cs (2)
161var toolDescriptorsJson = JsonSerializer.Serialize(tools.OfType<AIFunction>().Select(ToToolDescriptor), _jsonOptions); 180private static ToolDescriptor ToToolDescriptor(AIFunction tool) => new()
Microsoft.Extensions.AI.Ollama (2)
OllamaChatClient.cs (2)
286Tools = options?.Tools is { Count: > 0 } tools ? tools.OfType<AIFunction>().Select(ToOllamaTool) : null, 455private static OllamaTool ToOllamaTool(AIFunction function) => new()
Microsoft.Extensions.AI.Ollama.Tests (2)
OllamaChatClientIntegrationTests.cs (2)
66var stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] ( 76var irrelevantTool = AIFunctionFactory.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
Microsoft.Extensions.AI.OpenAI (8)
OpenAIModelMapper.ChatCompletion.cs (3)
306if (tool is AIFunction af) 379private sealed class MetadataOnlyAIFunction(AIFunctionMetadata metadata) : AIFunction 387private static ChatTool ToOpenAIChatTool(AIFunction aiFunction)
OpenAIRealtimeExtensions.cs (5)
24/// Converts a <see cref="AIFunction"/> into a <see cref="ConversationFunctionTool"/> so that 28public static ConversationFunctionTool ToConversationFunctionTool(this AIFunction aiFunction) 70IReadOnlyList<AIFunction> tools, 109IReadOnlyList<AIFunction> tools, 115&& tools.FirstOrDefault(t => t.Metadata.Name == update.FunctionName) is AIFunction aiFunction)
Microsoft.Extensions.AI.OpenAI.Tests (5)
OpenAIRealtimeIntegrationTests.cs (1)
31var roomCapacityTool = AIFunctionFactory.Create(GetRoomCapacity);
OpenAIRealtimeTests.cs (2)
22var input = AIFunctionFactory.Create(() => { }, "MyFunction", "MyDescription"); 32var input = AIFunctionFactory.Create(MyFunction);
OpenAISerializationTests.cs (2)
339AIFunction function = Assert.IsAssignableFrom<AIFunction>(Assert.Single(request.Options.Tools));
Microsoft.Extensions.AI.Tests (8)
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
353var func1 = AIFunctionFactory.Create(() => "Some result 1", "Func1"); 354var func2 = AIFunctionFactory.Create(() => "Some result 2", "Func2");
Functions\AIFunctionFactoryTest.cs (6)
28AIFunction func; 43AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 53AIFunction func; 89AIFunction func; 133AIFunction func; 177AIFunction func = AIFunctionFactory.Create(() => { }, options);