3 types derived from AIFunction
Microsoft.Extensions.AI (1)
Functions\AIFunctionFactory.cs (1)
106private sealed class ReflectionAIFunction : AIFunction
Microsoft.Extensions.AI.Abstractions.Tests (2)
Contents\FunctionCallContentTests..cs (1)
256private sealed class NetTypelessAIFunction : AIFunction
Functions\AIFunctionTests.cs (1)
36private sealed class DerivedAIFunction : AIFunction
65 references to AIFunction
Microsoft.Extensions.AI (32)
ChatCompletion\FunctionInvokingChatClient.cs (6)
22/// by calling the corresponding <see cref="AIFunction"/> defined in <see cref="ChatOptions"/>, 27/// <see cref="AIFunction"/> instances employed as part of the supplied <see cref="ChatOptions"/> are also safe. 463AIFunction? function = options.Tools!.OfType<AIFunction>().FirstOrDefault(t => t.Metadata.Name == functionCallContent.Name); 582AIFunction function) 590public 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/// a <see cref="AIFunctionContext"/> parameter is passed specially by the <see cref="AIFunction"/> implementation, in order 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 (22)
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> 31public static AIFunction Create(Delegate method, AIFunctionFactoryCreateOptions? options) 38/// <summary>Creates an <see cref="AIFunction"/> instance for a method, specified via a delegate.</summary> 39/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 40/// <param name="name">The name to use for the <see cref="AIFunction"/>.</param> 41/// <param name="description">The description to use for the <see cref="AIFunction"/>.</param> 43/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 44public static AIFunction Create(Delegate method, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null) 61/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance 64/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 70/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 71public static AIFunction Create(MethodInfo method, object? target, AIFunctionFactoryCreateOptions? options) 78/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance 81/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param> 86/// <param name="name">The name to use for the <see cref="AIFunction"/>.</param> 87/// <param name="description">The description to use for the <see cref="AIFunction"/>.</param> 89/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns> 90public static AIFunction Create(MethodInfo method, object? target, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null) 119/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
Functions\AIFunctionFactoryCreateOptions.cs (1)
14/// 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 a <see cref="AIFunction"/> parameter.
Functions\AIFunctionReturnParameterMetadata.cs (1)
10/// Provides read-only metadata for a <see cref="AIFunction"/>'s return parameter.
Microsoft.Extensions.AI.Abstractions.Tests (5)
AIJsonUtilitiesTests.cs (1)
121AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options);
Contents\FunctionCallContentTests..cs (4)
119AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 141AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 174AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options); 195AIFunction function = AIFunctionFactory.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Microsoft.Extensions.AI.AzureAIInference (2)
AzureAIInferenceChatClient.cs (2)
332if (tool is AIFunction af) 366private static ChatCompletionsFunctionToolDefinition ToAzureAIChatTool(AIFunction aiFunction)
Microsoft.Extensions.AI.Integration.Tests (5)
ChatClientIntegrationTests.cs (3)
221var tool = AIFunctionFactory.Create(() => 245var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 246var 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)
237Tools = options?.Tools is { Count: > 0 } tools ? tools.OfType<AIFunction>().Select(ToOllamaTool) : null, 404private static OllamaTool ToOllamaTool(AIFunction function) => new()
Microsoft.Extensions.AI.Ollama.Tests (2)
OllamaChatClientIntegrationTests.cs (2)
68var stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] ( 78var irrelevantTool = AIFunctionFactory.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
Microsoft.Extensions.AI.OpenAI (2)
OpenAIChatClient.cs (2)
449if (tool is AIFunction af) 485private static ChatTool ToOpenAIChatTool(AIFunction aiFunction)
Microsoft.Extensions.AI.Tests (8)
ChatCompletion\FunctionInvokingChatClientTests.cs (2)
270var func1 = AIFunctionFactory.Create(() => "Some result 1", "Func1"); 271var 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);