71 references to AIFunctionFactory
Microsoft.Extensions.AI (2)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (1)
204schemaName: AIFunctionFactory.SanitizeMemberName(typeof(T).Name),
ChatCompletion\FunctionInvocationContext.cs (1)
18private static readonly AIFunction _nopFunction = AIFunctionFactory.Create(() => { }, nameof(FunctionInvocationContext));
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)
279AIFunction func = AIFunctionFactory.Create((int x, int y) => x + y, serializerOptions: options); 291AIFunction 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)
799Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 886Tools = [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)
210Tools = [AIFunctionFactory.Create(() => secretNumber, "GetSecretNumber")] 235Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 250Tools = [AIFunctionFactory.Create((int a, int b) => a * b, "SecretComputation")] 278Tools = [AIFunctionFactory.Create((string personName) => 300var tool = AIFunctionFactory.Create(() => 323var getSecretNumberTool = AIFunctionFactory.Create(() => 123, "GetSecretNumber"); 324var 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)
374Tools = [AIFunctionFactory.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")], 471Tools = [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.")], 874Tools = [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 (38)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51AIFunction function = AIFunctionFactory.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientTests.cs (17)
48AIFunctionFactory.Create(() => "Result 1", "Func1"), 49AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 50AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 80AIFunctionFactory.Create((int i) => "Result 1", "Func1"), 81AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 130AIFunctionFactory.Create((string arg) => 171AIFunctionFactory.Create(async (string arg) => 210AIFunctionFactory.Create(() => "Result 1", "Func1"), 211AIFunctionFactory.Create((int i) => $"Result 2: {i}", "Func2"), 212AIFunctionFactory.Create((int i) => { }, "VoidReturn"), 249AIFunctionFactory.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"), 285Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 341Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")] 389Tools = [AIFunctionFactory.Create((string text) => $"Result for {text}", "Func1")] 447Tools = [AIFunctionFactory.Create(() => "doesn't matter", "Func1")] 486var function = AIFunctionFactory.Create(async (int i) => 563Tools = [AIFunctionFactory.Create(() => "Result 1", "Func1")],
Functions\AIFunctionFactoryTest.cs (20)
19Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!)); 20Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object())); 21Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk")); 22Assert.Throws<ArgumentNullException>("target", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, null)); 23Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>())); 31func = AIFunctionFactory.Create((string a) => a + " " + a); 34func = AIFunctionFactory.Create((string a, string b) => b + " " + a); 37func = AIFunctionFactory.Create((int a, long b) => a + b); 44AIFunction func = AIFunctionFactory.Create((string a = "test") => a + " " + a); 57AIFunction func = AIFunctionFactory.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) => 73func = AIFunctionFactory.Create(Task<string> (string a) => Task.FromResult(a + " " + a)); 76func = AIFunctionFactory.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a)); 80func = AIFunctionFactory.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); }); 85func = AIFunctionFactory.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); }); 89func = AIFunctionFactory.Create((int count) => SimpleIAsyncEnumerable(count)); 101func = AIFunctionFactory.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable()); 118func = AIFunctionFactory.Create(dotnetFunc); 124func = AIFunctionFactory.Create(dotnetFunc2); 130func = AIFunctionFactory.Create(dotnetFunc3); 156AIFunction func = AIFunctionFactory.Create(dotnetFunc, options);