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)
248private sealed class NetTypelessAIFunction : AIFunction
Functions\AIFunctionTests.cs (1)
36private sealed class DerivedAIFunction : AIFunction
87 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. 558AIFunction? function = options.Tools!.OfType<AIFunction>().FirstOrDefault(t => t.Metadata.Name == functionCallContent.Name); 760AIFunction function) 768public 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)
58/// 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)
11/// Provides read-only metadata for an <see cref="AIFunction"/>'s return parameter.
Microsoft.Extensions.AI.Abstractions.Tests (6)
Contents\FunctionCallContentTests..cs (4)
111AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 133AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 166AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 187AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Utilities\AIJsonUtilitiesTests.cs (2)
231AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 244AIFunction func = AIFunctionFactory.Create((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options);
Microsoft.Extensions.AI.AzureAIInference (2)
AzureAIInferenceChatClient.cs (2)
341if (tool is AIFunction af) 380private 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)
301Tools = options?.ToolMode is not NoneChatToolMode && options?.Tools is { Count: > 0 } tools ? tools.OfType<AIFunction>().Select(ToOllamaTool) : null, 472private static OllamaTool ToOllamaTool(AIFunction function)
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 (9)
OpenAIAssistantClient.cs (1)
215if (tool is AIFunction aiFunction)
OpenAIModelMapper.ChatCompletion.cs (3)
368if (tool is AIFunction af) 446private sealed class MetadataOnlyAIFunction(AIFunctionMetadata metadata) : AIFunction 454private static ChatTool ToOpenAIChatTool(AIFunction aiFunction)
OpenAIRealtimeExtensions.cs (5)
22/// Converts a <see cref="AIFunction"/> into a <see cref="ConversationFunctionTool"/> so that 26public static ConversationFunctionTool ToConversationFunctionTool(this AIFunction aiFunction) 59IReadOnlyList<AIFunction> tools, 89IReadOnlyList<AIFunction> tools, 95&& 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)
372AIFunction function = Assert.IsAssignableFrom<AIFunction>(Assert.Single(request.Options.Tools));
Microsoft.Extensions.AI.Tests (9)
ChatCompletion\FunctionInvokingChatClientTests.cs (3)
361var func1 = AIFunctionFactory.Create(() => "Some result 1", "Func1"); 362var func2 = AIFunctionFactory.Create(() => "Some result 2", "Func2"); 573var function = AIFunctionFactory.Create(async (int i) =>
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);