5 types derived from AIFunction
Microsoft.Extensions.AI.Abstractions (2)
Microsoft.Extensions.AI.Abstractions.Tests (2)
Microsoft.Extensions.AI.Integration.Tests (1)
225 references to AIFunction
Microsoft.Extensions.AI (11)
Microsoft.Extensions.AI.Abstractions (96)
Functions\AIFunctionFactory.cs (64)
33/// <summary>Provides factory methods for creating commonly-used implementations of <see cref="AIFunction"/>.</summary>
44/// <summary>Creates an <see cref="AIFunction"/> instance for a method, specified via a delegate.</summary>
45/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
47/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns>
51/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="AIFunction"/>'s
52/// <see cref="AIFunction.JsonSchema"/>. There are a few exceptions to this:
57/// the invocation via <see cref="AIFunction.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
73/// passed into <see cref="AIFunction.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
74/// instance passed to <see cref="AIFunction.InvokeAsync"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
81/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.InvokeAsync"/>
86/// into <see cref="AIFunction.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
111public static AIFunction Create(Delegate method, AIFunctionFactoryOptions? options)
118/// <summary>Creates an <see cref="AIFunction"/> instance for a method, specified via a delegate.</summary>
119/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
121/// The name to use for the <see cref="AIFunction"/>. If <see langword="null"/>, the name will be derived from
125/// The description to use for the <see cref="AIFunction"/>. If <see langword="null"/>, a description will be derived from
129/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns>
133/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="AIFunction"/>'s
134/// <see cref="AIFunction.JsonSchema"/>. There are a few exceptions to this:
139/// the invocation via <see cref="AIFunction.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
154/// passed into <see cref="AIFunction.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
155/// instance passed to <see cref="AIFunction.InvokeAsync"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
161/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.InvokeAsync"/>
184public static AIFunction Create(Delegate method, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null)
201/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance
204/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
210/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns>
214/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="AIFunction"/>'s
215/// <see cref="AIFunction.JsonSchema"/>. There are a few exceptions to this:
220/// the invocation via <see cref="AIFunction.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
236/// passed into <see cref="AIFunction.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
237/// instance passed to <see cref="AIFunction.InvokeAsync"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
244/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.InvokeAsync"/>
249/// into <see cref="AIFunction.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
277public static AIFunction Create(MethodInfo method, object? target, AIFunctionFactoryOptions? options)
285/// Creates an <see cref="AIFunction"/> instance for a method, specified via an <see cref="MethodInfo"/> instance
288/// <param name="method">The method to be represented via the created <see cref="AIFunction"/>.</param>
294/// The name to use for the <see cref="AIFunction"/>. If <see langword="null"/>, the name will be derived from
298/// The description to use for the <see cref="AIFunction"/>. If <see langword="null"/>, a description will be derived from
302/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns>
306/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="AIFunction"/>'s
307/// <see cref="AIFunction.JsonSchema"/>. There are a few exceptions to this:
312/// the invocation via <see cref="AIFunction.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
327/// passed into <see cref="AIFunction.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
328/// instance passed to <see cref="AIFunction.InvokeAsync"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
334/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.InvokeAsync"/>
360public static AIFunction Create(MethodInfo method, object? target, string? name = null, string? description = null, JsonSerializerOptions? serializerOptions = null)
377/// Creates an <see cref="AIFunction"/> instance for a method, specified via a <see cref="MethodInfo"/> for
379/// the receiver object each time the <see cref="AIFunction"/> is invoked.
381/// <param name="method">The instance method to be represented via the created <see cref="AIFunction"/>.</param>
388/// <returns>The created <see cref="AIFunction"/> for invoking <paramref name="method"/>.</returns>
400/// of key/value pairs and are represented in the JSON schema for the function, as exposed in the returned <see cref="AIFunction"/>'s
401/// <see cref="AIFunction.JsonSchema"/>. There are a few exceptions to this:
406/// the invocation via <see cref="AIFunction.InvokeAsync"/>'s <see cref="CancellationToken"/> parameter. The parameter is
422/// passed into <see cref="AIFunction.InvokeAsync"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
423/// instance passed to <see cref="AIFunction.InvokeAsync"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
430/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.InvokeAsync"/>
435/// into <see cref="AIFunction.InvokeAsync"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
464public static AIFunction Create(
Functions\AIFunctionFactoryOptions.cs (13)
15/// Represents options that can be provided when creating an <see cref="AIFunction"/> from a method.
65/// this delegate will be invoked once for each parameter in the function as part of creating the <see cref="AIFunction"/> instance.
67/// provided to the <see cref="AIFunction.InvokeAsync"/> invocation.
76/// <summary>Gets or sets a delegate used to determine the <see cref="object"/> returned by <see cref="AIFunction.InvokeAsync"/>.</summary>
79/// By default, the return value of invoking the method wrapped into an <see cref="AIFunction"/> by <see cref="AIFunctionFactory"/>
80/// is then JSON serialized, with the resulting <see cref="JsonElement"/> returned from the <see cref="AIFunction.InvokeAsync"/> method.
84/// and its return value is then returned from the <see cref="AIFunction.InvokeAsync"/> method.
88/// a <see langword="null"/> argument. By default, <see langword="null"/> is returned from the <see cref="AIFunction.InvokeAsync"/>
89/// method for <see cref="AIFunction"/> instances produced by <see cref="AIFunctionFactory"/> to wrap
110/// Gets or sets a value indicating whether a schema should be created for the function's result type, if possible, and included as <see cref="AIFunction.ReturnJsonSchema" />.
117/// When set to <see langword="true"/>, results in the produced <see cref="AIFunction.ReturnJsonSchema"/> to always be <see langword="null"/>.
132/// If non- <see langword="null"/>, each time the <see cref="AIFunction"/> is invoked, this delegate will be invoked
149/// It, however, is permissible for cases where invocation of the <see cref="AIFunction"/> is tightly controlled, and the caller
Microsoft.Extensions.AI.Abstractions.Tests (15)
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 (4)
285AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options);
339AIFunction func = AIFunctionFactory.Create((
360AIFunction func = AIFunctionFactory.Create((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options);
410AIFunction func = AIFunctionFactory.Create(([Range(1, 10)] int num, [StringLength(100, MinimumLength = 1)] string str) => num + str.Length, serializerOptions: options);
Microsoft.Extensions.AI.AzureAIInference (2)
Microsoft.Extensions.AI.AzureAIInference.Tests (5)
Microsoft.Extensions.AI.Evaluation.Quality (17)
Microsoft.Extensions.AI.Integration.Tests (11)
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (2)
Microsoft.Extensions.AI.OpenAI (17)
Microsoft.Extensions.AI.OpenAI.Tests (7)
Microsoft.Extensions.AI.Tests (42)
Functions\AIFunctionFactoryTest.cs (39)
42AIFunction func;
57AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a);
65AIFunction[] funcs =
73foreach (AIFunction f in funcs)
83AIFunction func = AIFunctionFactory.Create((int x, int y, int z, int w, int u) => x + y + z + w + u);
112AIFunction func = AIFunctionFactory.Create((JsonElement param) => param, serializerOptions: options);
132AIFunction func = AIFunctionFactory.Create((JsonElement param) => param);
151AIFunction func = AIFunctionFactory.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) =>
165AIFunction func;
214AIFunction func;
259AIFunction func = AIFunctionFactory.Create(dotnetFunc, options);
284AIFunction func = AIFunctionFactory.Create(
308AIFunction func = AIFunctionFactory.Create(
328AIFunction func = AIFunctionFactory.Create((
372AIFunction func = AIFunctionFactory.Create((
404AIFunction func = AIFunctionFactory.Create(
422AIFunction func = AIFunctionFactory.Create(
433AIFunction func = AIFunctionFactory.Create(
452AIFunction func = AIFunctionFactory.Create(
471AIFunction func = AIFunctionFactory.Create(
490AIFunction func = AIFunctionFactory.Create(
517AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger,
540AIFunction f = AIFunctionFactory.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger,
563AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) =>
582AIFunction f = AIFunctionFactory.Create(
634AIFunction f = AIFunctionFactory.Create(
651AIFunction f = AIFunctionFactory.Create(
667AIFunction f = AIFunctionFactory.Create(
690AIFunction f = AIFunctionFactory.Create(
713AIFunction f = AIFunctionFactory.Create(
736AIFunction f = AIFunctionFactory.Create(
759AIFunction f = AIFunctionFactory.Create(
782AIFunction f = AIFunctionFactory.Create(
805AIFunction f = AIFunctionFactory.Create(
828AIFunction f = AIFunctionFactory.Create(
852AIFunction f = AIFunctionFactory.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);
863AIFunction f = AIFunctionFactory.Create(
896AIFunction f = AIFunctionFactory.Create(
926AIFunction f = AIFunctionFactory.Create(Add, serializerOptions: JsonContext.Default.Options);