158 references to AIFunctionFactory
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvocationContext.cs (1)
18private static readonly AIFunction _nopFunction = AIFunctionFactory.Create(() => { }, nameof(FunctionInvocationContext));
Microsoft.Extensions.AI.Abstractions (2)
Functions\AIFunctionFactoryOptions.cs (2)
79/// By default, the return value of invoking the method wrapped into an <see cref="AIFunction"/> by <see cref="AIFunctionFactory"/> 89/// method for <see cref="AIFunction"/> instances produced by <see cref="AIFunctionFactory"/> to wrap
Microsoft.Extensions.AI.Abstractions.Tests (16)
ChatCompletion\ChatOptionsTests.cs (4)
68AIFunctionFactory.Create(() => 42), 69AIFunctionFactory.Create(() => 43), 166AIFunctionFactory.Create(() => 42), 167AIFunctionFactory.Create(() => 43),
Contents\FunctionCallContentTests..cs (6)
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); 141var ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create((CustomType arg) => { }, serializerOptions: TestJsonSerializerContext.Default.Options)); 145ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create(() => new CustomType(), 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);
Functions\DelegatingAIFunctionTests.cs (2)
23AIFunction expected = AIFunctionFactory.Create(() => 42); 64AIFunction inner = AIFunctionFactory.Create(int () =>
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (3)
270AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 324AIFunction func = AIFunctionFactory.Create(( 345AIFunction func = AIFunctionFactory.Create((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options);
Microsoft.Extensions.AI.AzureAIInference.Tests (6)
AzureAIInferenceChatClientTests.cs (6)
328AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 412AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 501AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 576AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 1251Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 1338Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
Microsoft.Extensions.AI.Evaluation.Integration.Tests (2)
AgentQualityEvaluatorTests.cs (2)
43Tools = [AIFunctionFactory.Create(GetOrders), AIFunctionFactory.Create(GetOrderStatus)]
Microsoft.Extensions.AI.Integration.Tests (34)
ChatClientIntegrationTests.cs (34)
237Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] 253Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 268Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 302AIFunction func = AIFunctionFactory.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById"); 334AIFunction func = AIFunctionFactory.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson"); 366AIFunction func = AIFunctionFactory.Create((string[] items, string shopperId) => { shoppingCart.AddRange(items); shopperName = shopperId; }, "AddItemsToShoppingCart"); 450AIFunctionFactory.Create((int? i) => i, createOptions()), 451AIFunctionFactory.Create((string? s) => s, createOptions()), 452AIFunctionFactory.Create((int? i = null) => i, createOptions()), 453AIFunctionFactory.Create((bool b) => b, createOptions()), 454AIFunctionFactory.Create((double d) => d, createOptions()), 455AIFunctionFactory.Create((decimal d) => d, createOptions()), 456AIFunctionFactory.Create((float f) => f, createOptions()), 457AIFunctionFactory.Create((long l) => l, createOptions()), 458AIFunctionFactory.Create((char c) => c, createOptions()), 459AIFunctionFactory.Create((DateTime dt) => dt, createOptions()), 460AIFunctionFactory.Create((DateTimeOffset? dt) => dt, createOptions()), 461AIFunctionFactory.Create((TimeSpan ts) => ts, createOptions()), 466AIFunctionFactory.Create((Uri uri) => uri, createOptions()), 467AIFunctionFactory.Create((Guid guid) => guid, createOptions()), 468AIFunctionFactory.Create((List<int> list) => list, createOptions()), 469AIFunctionFactory.Create((int[] arr, ComplexObject? co) => arr, createOptions()), 470AIFunctionFactory.Create((string p1 = "str", int p2 = 42, BindingFlags p3 = BindingFlags.IgnoreCase, char p4 = 'x') => p1, createOptions()), 471AIFunctionFactory.Create((string? p1 = "str", int? p2 = 42, BindingFlags? p3 = BindingFlags.IgnoreCase, char? p4 = 'x') => p1, createOptions()), 575Tools = [AIFunctionFactory.Create((string personName) => 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")] () => 888new ChatOptions { Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] }); 914new ChatOptions { Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] })) 1068Tools = [AIFunctionFactory.Create((int personId) =>
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (3)
OllamaSharpChatClientIntegrationTests.cs (3)
46Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")], 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.Tests (10)
OpenAIChatClientTests.cs (7)
333Tools = [AIFunctionFactory.Create(() => 42, "GetPersonAge", "Gets the age of the specified person.")], 383AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 460AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 543AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 617AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 1126Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 1310Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
OpenAIConversionTests.cs (1)
19private static readonly AIFunction _testFunction = AIFunctionFactory.Create(
OpenAIResponseClientTests.cs (2)
352Tools = [AIFunctionFactory.Create(() => 42, "GetPersonAge", "Gets the age of the specified person.")], 444AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
Microsoft.Extensions.AI.Tests (84)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51AIFunction function = AIFunctionFactory.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientTests.cs (26)
79AIFunctionFactory.Create(() => "Result 1", "Func1"), 80AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 81AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 111AIFunctionFactory.Create((int? i = 42) => "Result 1", "Func1"), 112AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 162AIFunctionFactory.Create(async (string arg) => 209AIFunctionFactory.Create(async (string arg) => 248AIFunctionFactory.Create(() => "Result 1", "Func1"), 249AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 250AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 299AIFunctionFactory.Create(() => { actualCallCount++; }, "VoidReturn"), 341AIFunctionFactory.Create((bool shouldThrow, int callIndex) => 422AIFunctionFactory.Create(() => 471AIFunctionFactory.Create(() => "Result 1", "Func1"), 472AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 473AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 510AIFunctionFactory.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"), 546Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 602Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 650Tools = [AIFunctionFactory.Create((string text) => $"Result for {text}", "Func1")] 708Tools = [AIFunctionFactory.Create(() => "doesn't matter", "Func1")] 747var function = AIFunctionFactory.Create(async (int i) => 822var function = AIFunctionFactory.Create((string? result = null) => 877Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")], 938Tools = [AIFunctionFactory.Create((IServiceProvider actual) => 971Tools = [AIFunctionFactory.Create(async (string arg, CancellationToken cancellationToken) =>
Functions\AIFunctionFactoryTest.cs (57)
30Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!)); 31Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object())); 32Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk")); 33Assert.Throws<ArgumentNullException>("target", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (object?)null)); 35AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (Func<AIFunctionArguments, object>)null!)); 36Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>())); 44func = AIFunctionFactory.Create((string a) => a + " " + a); 47func = AIFunctionFactory.Create((string a, string b) => b + " " + a); 50func = AIFunctionFactory.Create((int a, long b) => a + b); 57AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 67AIFunctionFactory.Create((string theParam) => theParam + " " + theParam), 68AIFunctionFactory.Create((string? theParam) => theParam + " " + theParam), 69AIFunctionFactory.Create((int theParam) => theParam * 2), 70AIFunctionFactory.Create((int? theParam) => theParam * 2), 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) => 167func = AIFunctionFactory.Create(Task<string> (string a) => Task.FromResult(a + " " + a)); 171func = AIFunctionFactory.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a)); 176func = AIFunctionFactory.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); }); 182func = AIFunctionFactory.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); }); 187func = AIFunctionFactory.Create((int count) => SimpleIAsyncEnumerable(count), serializerOptions: JsonContext.Default.Options); 200func = AIFunctionFactory.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable(), serializerOptions: JsonContext.Default.Options); 217func = AIFunctionFactory.Create(dotnetFunc); 223func = AIFunctionFactory.Create(dotnetFunc2); 229func = AIFunctionFactory.Create(dotnetFunc3); 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( 444Assert.Throws<ArgumentException>("method", () => 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);