141 references to AIFunctionFactory
Microsoft.Extensions.AI (4)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (1)
200schemaName: AIFunctionFactory.SanitizeMemberName(typeof(T).Name),
ChatCompletion\FunctionInvocationContext.cs (1)
18private static readonly AIFunction _nopFunction = AIFunctionFactory.Create(() => { }, nameof(FunctionInvocationContext));
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 (14)
ChatCompletion\ChatOptionsTests.cs (4)
66AIFunctionFactory.Create(() => 42), 67AIFunctionFactory.Create(() => 43), 161AIFunctionFactory.Create(() => 42), 162AIFunctionFactory.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);
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (3)
297AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 344AIFunction func = AIFunctionFactory.Create(( 369AIFunction 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."); 428AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 517AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 592AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 1267Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 1354Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
Microsoft.Extensions.AI.Integration.Tests (25)
ChatClientIntegrationTests.cs (25)
228Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] 244Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 259Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 293AIFunction func = AIFunctionFactory.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById"); 325AIFunction func = AIFunctionFactory.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson"); 372AIFunctionFactory.Create((int? i) => i, "Method1"), 373AIFunctionFactory.Create((string? s) => s, "Method2"), 374AIFunctionFactory.Create((int? i = null) => i, "Method3"), 375AIFunctionFactory.Create((bool b) => b, "Method4"), 376AIFunctionFactory.Create((double d) => d, "Method5"), 377AIFunctionFactory.Create((decimal d) => d, "Method6"), 378AIFunctionFactory.Create((float f) => f, "Method7"), 379AIFunctionFactory.Create((long l) => l, "Method8"), 380AIFunctionFactory.Create((char c) => c, "Method9"), 381AIFunctionFactory.Create((DateTime dt) => dt, "Method10"), 382AIFunctionFactory.Create((DateTime? dt) => dt, "Method11"), 383AIFunctionFactory.Create((Guid guid) => guid, "Method12"), 384AIFunctionFactory.Create((List<int> list) => list, "Method13"), 385AIFunctionFactory.Create((int[] arr) => arr, "Method14"), 386AIFunctionFactory.Create((string p1 = "str", int p2 = 42, BindingFlags p3 = BindingFlags.IgnoreCase, char p4 = 'x') => p1, "Method15"), 387AIFunctionFactory.Create((string? p1 = "str", int? p2 = 42, BindingFlags? p3 = BindingFlags.IgnoreCase, char? p4 = 'x') => p1, "Method16"), 412Tools = [AIFunctionFactory.Create((string personName) => 434var tool = AIFunctionFactory.Create(() => 457var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 458var shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp");
Microsoft.Extensions.AI.Ollama.Tests (5)
OllamaChatClientIntegrationTests.cs (3)
45Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")], 65var stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] ( 75var irrelevantTool = AIFunctionFactory.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
OllamaChatClientTests.cs (2)
376Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 473Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
Microsoft.Extensions.AI.OpenAI.Tests (6)
OpenAIChatClientTests.cs (6)
320AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 399AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 484AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 560AIFunction tool = AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person."); 1085Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 1269Tools = [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 (81)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51AIFunction function = AIFunctionFactory.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientTests.cs (23)
49AIFunctionFactory.Create(() => "Result 1", "Func1"), 50AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 51AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 81AIFunctionFactory.Create((int? i = 42) => "Result 1", "Func1"), 82AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 132AIFunctionFactory.Create(async (string arg) => 179AIFunctionFactory.Create(async (string arg) => 226AIFunctionFactory.Create(() => { actualCallCount++; }, "VoidReturn"), 268AIFunctionFactory.Create((bool shouldThrow, int callIndex) => 349AIFunctionFactory.Create(() => 398AIFunctionFactory.Create(() => "Result 1", "Func1"), 399AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 400AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 437AIFunctionFactory.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"), 473Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 529Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 577Tools = [AIFunctionFactory.Create((string text) => $"Result for {text}", "Func1")] 635Tools = [AIFunctionFactory.Create(() => "doesn't matter", "Func1")] 674var function = AIFunctionFactory.Create(async (int i) => 749var function = AIFunctionFactory.Create((string? result = null) => 804Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")], 865Tools = [AIFunctionFactory.Create((IServiceProvider actual) => 898Tools = [AIFunctionFactory.Create(async (string arg, CancellationToken cancellationToken) =>
Functions\AIFunctionFactoryTest.cs (57)
28Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!)); 29Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object())); 30Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk")); 31Assert.Throws<ArgumentNullException>("target", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (object?)null)); 32Assert.Throws<ArgumentNullException>("targetType", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (Type)null!)); 33Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>())); 41func = AIFunctionFactory.Create((string a) => a + " " + a); 44func = AIFunctionFactory.Create((string a, string b) => b + " " + a); 47func = AIFunctionFactory.Create((int a, long b) => a + b); 54AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 64AIFunctionFactory.Create((string theParam) => theParam + " " + theParam), 65AIFunctionFactory.Create((string? theParam) => theParam + " " + theParam), 66AIFunctionFactory.Create((int theParam) => theParam * 2), 67AIFunctionFactory.Create((int? theParam) => theParam * 2), 85AIFunction func = AIFunctionFactory.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) => 101func = AIFunctionFactory.Create(Task<string> (string a) => Task.FromResult(a + " " + a)); 104func = AIFunctionFactory.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a)); 108func = AIFunctionFactory.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); }); 113func = AIFunctionFactory.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); }); 117func = AIFunctionFactory.Create((int count) => SimpleIAsyncEnumerable(count), serializerOptions: JsonContext.Default.Options); 129func = AIFunctionFactory.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable(), serializerOptions: JsonContext.Default.Options); 146func = AIFunctionFactory.Create(dotnetFunc); 152func = AIFunctionFactory.Create(dotnetFunc2); 158func = AIFunctionFactory.Create(dotnetFunc3); 188AIFunction func = AIFunctionFactory.Create(dotnetFunc, options); 212AIFunction func = AIFunctionFactory.Create( 239AIFunction func = AIFunctionFactory.Create(( 281AIFunction func = AIFunctionFactory.Create(( 314func = AIFunctionFactory.Create((MyService myService) => myService.Value); 321Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create((MyService myService) => myService.Value)); 327func = AIFunctionFactory.Create((MyService? myService = null) => myService?.Value ?? 456); 334Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create((MyService myService) => myService.Value)); 338func = AIFunctionFactory.Create((MyService myService) => myService.Value, new() { Services = sp }); 345func = AIFunctionFactory.Create((MyService? myService = null) => myService?.Value ?? 456, new() { Services = sp }); 362AIFunction func = AIFunctionFactory.Create( 379AIFunction func = AIFunctionFactory.Create( 396AIFunction func = AIFunctionFactory.Create( 407Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create( 415Assert.Throws<ArgumentException>("targetType", () => AIFunctionFactory.Create( 423AIFunction func = AIFunctionFactory.Create( 442AIFunction func = AIFunctionFactory.Create( 461AIFunction func = AIFunctionFactory.Create( 488AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger); 509AIFunction f = AIFunctionFactory.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger); 530AIFunction f = AIFunctionFactory.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) => 548AIFunction f = AIFunctionFactory.Create( 600AIFunction f = AIFunctionFactory.Create( 617AIFunction f = AIFunctionFactory.Create( 633AIFunction f = AIFunctionFactory.Create( 656AIFunction f = AIFunctionFactory.Create( 679AIFunction f = AIFunctionFactory.Create( 702AIFunction f = AIFunctionFactory.Create( 725AIFunction f = AIFunctionFactory.Create( 748AIFunction f = AIFunctionFactory.Create( 771AIFunction f = AIFunctionFactory.Create( 794AIFunction f = AIFunctionFactory.Create( 817AIFunction f = AIFunctionFactory.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);