77 references to AIFunctionFactory
Microsoft.Extensions.AI (3)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (1)
207schemaName: AIFunctionFactory.SanitizeMemberName(typeof(T).Name),
Functions\AIFunctionContext.cs (2)
9/// <summary>Provides additional context to the invocation of an <see cref="AIFunction"/> created by <see cref="AIFunctionFactory"/>.</summary> 11/// A delegate or <see cref="MethodInfo"/> passed to <see cref="AIFunctionFactory"/> methods can represent a method that has a parameter
Microsoft.Extensions.AI.Abstractions.Tests (12)
ChatCompletion\ChatOptionsTests.cs (4)
61AIFunctionFactory.Create(() => 42), 62AIFunctionFactory.Create(() => 43), 147AIFunctionFactory.Create(() => 42), 148AIFunctionFactory.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\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.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
771Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 859Tools = [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 (7)
ChatClientIntegrationTests.cs (7)
182Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] 208Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 224Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 252Tools = [AIFunctionFactory.Create((string personName) => 274var tool = AIFunctionFactory.Create(() => 298var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 299var shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp");
Microsoft.Extensions.AI.Ollama.Tests (5)
OllamaChatClientIntegrationTests.cs (3)
45Tools = [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");
OllamaChatClientTests.cs (2)
369Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 467Tools = [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 (5)
OpenAIChatClientTests.cs (2)
770Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 875Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
OpenAIRealtimeIntegrationTests.cs (1)
31var roomCapacityTool = AIFunctionFactory.Create(GetRoomCapacity);
OpenAIRealtimeTests.cs (2)
22var input = AIFunctionFactory.Create(() => { }, "MyFunction", "MyDescription"); 32var input = AIFunctionFactory.Create(MyFunction);
Microsoft.Extensions.AI.Tests (43)
ChatCompletion\FunctionInvokingChatClientTests.cs (21)
52AIFunctionFactory.Create(() => "Result 1", "Func1"), 53AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 54AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 84AIFunctionFactory.Create((int i) => "Result 1", "Func1"), 85AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 134AIFunctionFactory.Create((string arg) => 175AIFunctionFactory.Create(async (string arg) => 216AIFunctionFactory.Create(() => "Result 1", "Func1"), 217AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 218AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 269AIFunctionFactory.Create(() => "Result 1", "Func1"), 270AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 271AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 338AIFunctionFactory.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"), 361var func1 = AIFunctionFactory.Create(() => "Some result 1", "Func1"); 362var func2 = AIFunctionFactory.Create(() => "Some result 2", "Func2"); 412Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 471Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 522Tools = [AIFunctionFactory.Create((string text) => $"Result for {text}", "Func1")] 573var function = AIFunctionFactory.Create(async (int i) => 661Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")],
Functions\AIFunctionFactoryTest.cs (22)
18Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!)); 19Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object())); 20Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk")); 21Assert.Throws<ArgumentNullException>("target", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, null)); 22Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>())); 30func = AIFunctionFactory.Create((string a) => a + " " + a); 33func = AIFunctionFactory.Create((string a, string b) => b + " " + a); 36func = AIFunctionFactory.Create((int a, long b) => a + b); 43AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 57func = AIFunctionFactory.Create((AIFunctionContext ctx) => 67func = AIFunctionFactory.Create((int somethingFirst, AIFunctionContext ctx) => 77func = AIFunctionFactory.Create((AIFunctionContext ctx, int somethingAfter = 0) => 91func = AIFunctionFactory.Create(Task<string> (string a) => Task.FromResult(a + " " + a)); 94func = AIFunctionFactory.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a)); 98func = AIFunctionFactory.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); }); 103func = AIFunctionFactory.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); }); 107func = AIFunctionFactory.Create((int count) => SimpleIAsyncEnumerable(count)); 119func = AIFunctionFactory.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable()); 135func = AIFunctionFactory.Create(() => "test"); 141func = AIFunctionFactory.Create((string a) => a + " " + a); 146func = AIFunctionFactory.Create( 177AIFunction func = AIFunctionFactory.Create(() => { }, options);