158 references to AIFunctionFactory
Microsoft.Extensions.AI (1)
ChatCompletion\FunctionInvocationContext.cs (1)
18
private 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)
68
AIFunctionFactory
.Create(() => 42),
69
AIFunctionFactory
.Create(() => 43),
166
AIFunctionFactory
.Create(() => 42),
167
AIFunctionFactory
.Create(() => 43),
Contents\FunctionCallContentTests..cs (6)
111
AIFunction function =
AIFunctionFactory
.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
133
AIFunction function =
AIFunctionFactory
.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
141
var ex = Assert.Throws<NotSupportedException>(() =>
AIFunctionFactory
.Create((CustomType arg) => { }, serializerOptions: TestJsonSerializerContext.Default.Options));
145
ex = Assert.Throws<NotSupportedException>(() =>
AIFunctionFactory
.Create(() => new CustomType(), serializerOptions: TestJsonSerializerContext.Default.Options));
166
AIFunction function =
AIFunctionFactory
.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
187
AIFunction function =
AIFunctionFactory
.Create((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Functions\DelegatingAIFunctionTests.cs (2)
23
AIFunction expected =
AIFunctionFactory
.Create(() => 42);
64
AIFunction inner =
AIFunctionFactory
.Create(int () =>
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51
AIFunction func =
AIFunctionFactory
.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (3)
270
AIFunction func =
AIFunctionFactory
.Create((int x, int y) => x + y, serializerOptions: options);
324
AIFunction func =
AIFunctionFactory
.Create((
345
AIFunction 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)
328
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
412
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
501
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
576
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
1251
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
1338
Tools = [
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)
43
Tools = [
AIFunctionFactory
.Create(GetOrders),
AIFunctionFactory
.Create(GetOrderStatus)]
Microsoft.Extensions.AI.Integration.Tests (34)
ChatClientIntegrationTests.cs (34)
237
Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")]
253
Tools = [
AIFunctionFactory
.Create((int a, int b) => a * b, "SecretComputation")]
268
Tools = [
AIFunctionFactory
.Create((int a, int b) => a * b, "SecretComputation")]
302
AIFunction func =
AIFunctionFactory
.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById");
334
AIFunction func =
AIFunctionFactory
.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson");
366
AIFunction func =
AIFunctionFactory
.Create((string[] items, string shopperId) => { shoppingCart.AddRange(items); shopperName = shopperId; }, "AddItemsToShoppingCart");
450
AIFunctionFactory
.Create((int? i) => i, createOptions()),
451
AIFunctionFactory
.Create((string? s) => s, createOptions()),
452
AIFunctionFactory
.Create((int? i = null) => i, createOptions()),
453
AIFunctionFactory
.Create((bool b) => b, createOptions()),
454
AIFunctionFactory
.Create((double d) => d, createOptions()),
455
AIFunctionFactory
.Create((decimal d) => d, createOptions()),
456
AIFunctionFactory
.Create((float f) => f, createOptions()),
457
AIFunctionFactory
.Create((long l) => l, createOptions()),
458
AIFunctionFactory
.Create((char c) => c, createOptions()),
459
AIFunctionFactory
.Create((DateTime dt) => dt, createOptions()),
460
AIFunctionFactory
.Create((DateTimeOffset? dt) => dt, createOptions()),
461
AIFunctionFactory
.Create((TimeSpan ts) => ts, createOptions()),
466
AIFunctionFactory
.Create((Uri uri) => uri, createOptions()),
467
AIFunctionFactory
.Create((Guid guid) => guid, createOptions()),
468
AIFunctionFactory
.Create((List<int> list) => list, createOptions()),
469
AIFunctionFactory
.Create((int[] arr, ComplexObject? co) => arr, createOptions()),
470
AIFunctionFactory
.Create((string p1 = "str", int p2 = 42, BindingFlags p3 = BindingFlags.IgnoreCase, char p4 = 'x') => p1, createOptions()),
471
AIFunctionFactory
.Create((string? p1 = "str", int? p2 = 42, BindingFlags? p3 = BindingFlags.IgnoreCase, char? p4 = 'x') => p1, createOptions()),
575
Tools = [
AIFunctionFactory
.Create((string personName) =>
597
var tool =
AIFunctionFactory
.Create(() =>
620
var getSecretNumberTool =
AIFunctionFactory
.Create(() => 123, "GetSecretNumber");
621
var shieldsUpTool =
AIFunctionFactory
.Create(() => shieldsUp = true, "ShieldsUp");
717
var getTemperature =
AIFunctionFactory
.Create([Description("Gets the current temperature")] () =>
756
var getTemperature =
AIFunctionFactory
.Create([Description("Gets the current temperature")] () =>
798
var getTemperature =
AIFunctionFactory
.Create([Description("Gets the current temperature")] () =>
888
new ChatOptions { Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")] });
914
new ChatOptions { Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")] }))
1068
Tools = [
AIFunctionFactory
.Create((int personId) =>
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (3)
OllamaSharpChatClientIntegrationTests.cs (3)
46
Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")],
66
var stockPriceTool =
AIFunctionFactory
.Create([Description("Returns the stock price for a given ticker symbol")] (
76
var irrelevantTool =
AIFunctionFactory
.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIChatClientTests.cs (7)
333
Tools = [
AIFunctionFactory
.Create(() => 42, "GetPersonAge", "Gets the age of the specified person.")],
383
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
460
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
543
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
617
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
1126
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
1310
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
OpenAIConversionTests.cs (1)
19
private static readonly AIFunction _testFunction =
AIFunctionFactory
.Create(
OpenAIResponseClientTests.cs (2)
352
Tools = [
AIFunctionFactory
.Create(() => 42, "GetPersonAge", "Gets the age of the specified person.")],
444
AIFunction 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)
51
AIFunction function =
AIFunctionFactory
.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientTests.cs (26)
79
AIFunctionFactory
.Create(() => "Result 1", "Func1"),
80
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
81
AIFunctionFactory
.Create((int i) => { }, "VoidReturn"),
111
AIFunctionFactory
.Create((int? i = 42) => "Result 1", "Func1"),
112
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
162
AIFunctionFactory
.Create(async (string arg) =>
209
AIFunctionFactory
.Create(async (string arg) =>
248
AIFunctionFactory
.Create(() => "Result 1", "Func1"),
249
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
250
AIFunctionFactory
.Create((int i) => { }, "VoidReturn"),
299
AIFunctionFactory
.Create(() => { actualCallCount++; }, "VoidReturn"),
341
AIFunctionFactory
.Create((bool shouldThrow, int callIndex) =>
422
AIFunctionFactory
.Create(() =>
471
AIFunctionFactory
.Create(() => "Result 1", "Func1"),
472
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
473
AIFunctionFactory
.Create((int i) => { }, "VoidReturn"),
510
AIFunctionFactory
.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"),
546
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")]
602
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")]
650
Tools = [
AIFunctionFactory
.Create((string text) => $"Result for {text}", "Func1")]
708
Tools = [
AIFunctionFactory
.Create(() => "doesn't matter", "Func1")]
747
var function =
AIFunctionFactory
.Create(async (int i) =>
822
var function =
AIFunctionFactory
.Create((string? result = null) =>
877
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")],
938
Tools = [
AIFunctionFactory
.Create((IServiceProvider actual) =>
971
Tools = [
AIFunctionFactory
.Create(async (string arg, CancellationToken cancellationToken) =>
Functions\AIFunctionFactoryTest.cs (57)
30
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!));
31
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!, target: new object()));
32
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!, target: new object(), name: "myAiFunk"));
33
Assert.Throws<ArgumentNullException>("target", () =>
AIFunctionFactory
.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (object?)null));
35
AIFunctionFactory
.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (Func<AIFunctionArguments, object>)null!));
36
Assert.Throws<ArgumentException>("method", () =>
AIFunctionFactory
.Create(typeof(List<>).GetMethod("Add")!, new List<int>()));
44
func =
AIFunctionFactory
.Create((string a) => a + " " + a);
47
func =
AIFunctionFactory
.Create((string a, string b) => b + " " + a);
50
func =
AIFunctionFactory
.Create((int a, long b) => a + b);
57
AIFunction func =
AIFunctionFactory
.Create((string a = "test") => a + " " + a);
67
AIFunctionFactory
.Create((string theParam) => theParam + " " + theParam),
68
AIFunctionFactory
.Create((string? theParam) => theParam + " " + theParam),
69
AIFunctionFactory
.Create((int theParam) => theParam * 2),
70
AIFunctionFactory
.Create((int? theParam) => theParam * 2),
83
AIFunction func =
AIFunctionFactory
.Create((int x, int y, int z, int w, int u) => x + y + z + w + u);
112
AIFunction func =
AIFunctionFactory
.Create((JsonElement param) => param, serializerOptions: options);
132
AIFunction func =
AIFunctionFactory
.Create((JsonElement param) => param);
151
AIFunction func =
AIFunctionFactory
.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) =>
167
func =
AIFunctionFactory
.Create(Task<string> (string a) => Task.FromResult(a + " " + a));
171
func =
AIFunctionFactory
.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a));
176
func =
AIFunctionFactory
.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); });
182
func =
AIFunctionFactory
.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); });
187
func =
AIFunctionFactory
.Create((int count) => SimpleIAsyncEnumerable(count), serializerOptions: JsonContext.Default.Options);
200
func =
AIFunctionFactory
.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable(), serializerOptions: JsonContext.Default.Options);
217
func =
AIFunctionFactory
.Create(dotnetFunc);
223
func =
AIFunctionFactory
.Create(dotnetFunc2);
229
func =
AIFunctionFactory
.Create(dotnetFunc3);
259
AIFunction func =
AIFunctionFactory
.Create(dotnetFunc, options);
284
AIFunction func =
AIFunctionFactory
.Create(
308
AIFunction func =
AIFunctionFactory
.Create(
328
AIFunction func =
AIFunctionFactory
.Create((
372
AIFunction func =
AIFunctionFactory
.Create((
404
AIFunction func =
AIFunctionFactory
.Create(
422
AIFunction func =
AIFunctionFactory
.Create(
433
AIFunction func =
AIFunctionFactory
.Create(
444
Assert.Throws<ArgumentException>("method", () =>
AIFunctionFactory
.Create(
452
AIFunction func =
AIFunctionFactory
.Create(
471
AIFunction func =
AIFunctionFactory
.Create(
490
AIFunction func =
AIFunctionFactory
.Create(
517
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger,
540
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger,
563
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) =>
582
AIFunction f =
AIFunctionFactory
.Create(
634
AIFunction f =
AIFunctionFactory
.Create(
651
AIFunction f =
AIFunctionFactory
.Create(
667
AIFunction f =
AIFunctionFactory
.Create(
690
AIFunction f =
AIFunctionFactory
.Create(
713
AIFunction f =
AIFunctionFactory
.Create(
736
AIFunction f =
AIFunctionFactory
.Create(
759
AIFunction f =
AIFunctionFactory
.Create(
782
AIFunction f =
AIFunctionFactory
.Create(
805
AIFunction f =
AIFunctionFactory
.Create(
828
AIFunction f =
AIFunctionFactory
.Create(
852
AIFunction f =
AIFunctionFactory
.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);
863
AIFunction f =
AIFunctionFactory
.Create(
896
AIFunction f =
AIFunctionFactory
.Create(
926
AIFunction f =
AIFunctionFactory
.Create(Add, serializerOptions: JsonContext.Default.Options);