68 references to AIFunctionFactory
Microsoft.Extensions.AI (3)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (1)
146schemaName: 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 may represent a method that has a parameter
Microsoft.Extensions.AI.Abstractions.Tests (11)
AIJsonUtilitiesTests.cs (1)
121AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options);
ChatCompletion\ChatOptionsTests.cs (4)
55AIFunctionFactory.Create(() => 42), 56AIFunctionFactory.Create(() => 43), 129AIFunctionFactory.Create(() => 42), 130AIFunctionFactory.Create(() => 43),
Contents\FunctionCallContentTests..cs (6)
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); 149var ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create((CustomType arg) => { }, serializerOptions: TestJsonSerializerContext.Default.Options)); 153ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.Create(() => new CustomType(), 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.Tests (2)
AzureAIInferenceChatClientTests.cs (2)
413Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 505Tools = [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)
139Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] 155Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 171Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 199Tools = [AIFunctionFactory.Create((string personName) => 221var tool = AIFunctionFactory.Create(() => 245var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 246var shieldsUpTool = AIFunctionFactory.Create(() => shieldsUp = true, "ShieldsUp");
Microsoft.Extensions.AI.Ollama.Tests (5)
OllamaChatClientIntegrationTests.cs (3)
48Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")], 68var stockPriceTool = AIFunctionFactory.Create([Description("Returns the stock price for a given ticker symbol")] ( 78var irrelevantTool = AIFunctionFactory.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
OllamaChatClientTests.cs (2)
352Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 450Tools = [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 (2)
OpenAIChatClientTests.cs (2)
459Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 554Tools = [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 (38)
ChatCompletion\FunctionInvokingChatClientTests.cs (16)
34AIFunctionFactory.Create(() => "Result 1", "Func1"), 35AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 36AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 60AIFunctionFactory.Create((int i) => "Result 1", "Func1"), 61AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 94AIFunctionFactory.Create((string arg) => 124AIFunctionFactory.Create(async (string arg) => 158AIFunctionFactory.Create(() => "Result 1", "Func1"), 159AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 160AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 206AIFunctionFactory.Create(() => "Result 1", "Func1"), 207AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 208AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 255AIFunctionFactory.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"), 270var func1 = AIFunctionFactory.Create(() => "Some result 1", "Func1"); 271var func2 = AIFunctionFactory.Create(() => "Some result 2", "Func2");
Functions\AIFunctionFactoryTest.cs (22)
18Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!)); 19Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!, target: new object())); 20Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk")); 21Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, null)); 22Assert.Throws<ArgumentException>(() => 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);