136 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 (4)
Functions\AIFunctionFactoryOptions.cs (4)
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
110
/// Gets or sets a delegate used with <see cref="
AIFunctionFactory
.Create(MethodInfo, Type, AIFunctionFactoryOptions?)"/> to create the receiver instance.
114
/// <see cref="
AIFunctionFactory
.Create(MethodInfo, Type, AIFunctionFactoryOptions?)"/> creates <see cref="AIFunction"/> instances that invoke an
Microsoft.Extensions.AI.Abstractions.Tests (14)
ChatCompletion\ChatOptionsTests.cs (4)
66
AIFunctionFactory
.Create(() => 42),
67
AIFunctionFactory
.Create(() => 43),
161
AIFunctionFactory
.Create(() => 42),
162
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);
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51
AIFunction func =
AIFunctionFactory
.Create((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (3)
297
AIFunction func =
AIFunctionFactory
.Create((int x, int y) => x + y, serializerOptions: options);
344
AIFunction func =
AIFunctionFactory
.Create((
369
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.");
428
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
517
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
592
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
1267
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
1354
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.Integration.Tests (25)
ChatClientIntegrationTests.cs (25)
230
Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")]
246
Tools = [
AIFunctionFactory
.Create((int a, int b) => a * b, "SecretComputation")]
261
Tools = [
AIFunctionFactory
.Create((int a, int b) => a * b, "SecretComputation")]
295
AIFunction func =
AIFunctionFactory
.Create((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById");
327
AIFunction func =
AIFunctionFactory
.Create((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson");
374
AIFunctionFactory
.Create((int? i) => i, "Method1"),
375
AIFunctionFactory
.Create((string? s) => s, "Method2"),
376
AIFunctionFactory
.Create((int? i = null) => i, "Method3"),
377
AIFunctionFactory
.Create((bool b) => b, "Method4"),
378
AIFunctionFactory
.Create((double d) => d, "Method5"),
379
AIFunctionFactory
.Create((decimal d) => d, "Method6"),
380
AIFunctionFactory
.Create((float f) => f, "Method7"),
381
AIFunctionFactory
.Create((long l) => l, "Method8"),
382
AIFunctionFactory
.Create((char c) => c, "Method9"),
383
AIFunctionFactory
.Create((DateTime dt) => dt, "Method10"),
384
AIFunctionFactory
.Create((DateTime? dt) => dt, "Method11"),
385
AIFunctionFactory
.Create((Guid guid) => guid, "Method12"),
386
AIFunctionFactory
.Create((List<int> list) => list, "Method13"),
387
AIFunctionFactory
.Create((int[] arr) => arr, "Method14"),
388
AIFunctionFactory
.Create((string p1 = "str", int p2 = 42, BindingFlags p3 = BindingFlags.IgnoreCase, char p4 = 'x') => p1, "Method15"),
389
AIFunctionFactory
.Create((string? p1 = "str", int? p2 = 42, BindingFlags? p3 = BindingFlags.IgnoreCase, char? p4 = 'x') => p1, "Method16"),
414
Tools = [
AIFunctionFactory
.Create((string personName) =>
436
var tool =
AIFunctionFactory
.Create(() =>
459
var getSecretNumberTool =
AIFunctionFactory
.Create(() => 123, "GetSecretNumber");
460
var shieldsUpTool =
AIFunctionFactory
.Create(() => shieldsUp = true, "ShieldsUp");
Microsoft.Extensions.AI.Ollama.Tests (5)
OllamaChatClientIntegrationTests.cs (3)
45
Tools = [
AIFunctionFactory
.Create(() => secretNumber, "GetSecretNumber")],
65
var stockPriceTool =
AIFunctionFactory
.Create([Description("Returns the stock price for a given ticker symbol")] (
75
var irrelevantTool =
AIFunctionFactory
.Create(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
OllamaChatClientTests.cs (2)
376
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
473
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.OpenAI.Tests (6)
OpenAIChatClientTests.cs (6)
320
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
399
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
484
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
560
AIFunction tool =
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
1085
Tools = [
AIFunctionFactory
.Create(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
1269
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.Tests (75)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51
AIFunction function =
AIFunctionFactory
.Create(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientTests.cs (23)
49
AIFunctionFactory
.Create(() => "Result 1", "Func1"),
50
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
51
AIFunctionFactory
.Create((int i) => { }, "VoidReturn"),
81
AIFunctionFactory
.Create((int? i = 42) => "Result 1", "Func1"),
82
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
132
AIFunctionFactory
.Create(async (string arg) =>
179
AIFunctionFactory
.Create(async (string arg) =>
226
AIFunctionFactory
.Create(() => { actualCallCount++; }, "VoidReturn"),
268
AIFunctionFactory
.Create((bool shouldThrow, int callIndex) =>
349
AIFunctionFactory
.Create(() =>
398
AIFunctionFactory
.Create(() => "Result 1", "Func1"),
399
AIFunctionFactory
.Create((int i) => $"Result 2: {i}", "Func2"),
400
AIFunctionFactory
.Create((int i) => { }, "VoidReturn"),
437
AIFunctionFactory
.Create(string () => throw new InvalidOperationException("Oh no!"), "Func1"),
473
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")]
529
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")]
577
Tools = [
AIFunctionFactory
.Create((string text) => $"Result for {text}", "Func1")]
635
Tools = [
AIFunctionFactory
.Create(() => "doesn't matter", "Func1")]
674
var function =
AIFunctionFactory
.Create(async (int i) =>
749
var function =
AIFunctionFactory
.Create((string? result = null) =>
804
Tools = [
AIFunctionFactory
.Create(() => "Result 1", "Func1")],
865
Tools = [
AIFunctionFactory
.Create((IServiceProvider actual) =>
898
Tools = [
AIFunctionFactory
.Create(async (string arg, CancellationToken cancellationToken) =>
Functions\AIFunctionFactoryTest.cs (51)
28
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!));
29
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!, target: new object()));
30
Assert.Throws<ArgumentNullException>("method", () =>
AIFunctionFactory
.Create(method: null!, target: new object(), name: "myAiFunk"));
31
Assert.Throws<ArgumentNullException>("target", () =>
AIFunctionFactory
.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (object?)null));
32
Assert.Throws<ArgumentNullException>("targetType", () =>
AIFunctionFactory
.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, (Type)null!));
33
Assert.Throws<ArgumentException>("method", () =>
AIFunctionFactory
.Create(typeof(List<>).GetMethod("Add")!, new List<int>()));
41
func =
AIFunctionFactory
.Create((string a) => a + " " + a);
44
func =
AIFunctionFactory
.Create((string a, string b) => b + " " + a);
47
func =
AIFunctionFactory
.Create((int a, long b) => a + b);
54
AIFunction func =
AIFunctionFactory
.Create((string a = "test") => a + " " + a);
64
AIFunctionFactory
.Create((string theParam) => theParam + " " + theParam),
65
AIFunctionFactory
.Create((string? theParam) => theParam + " " + theParam),
66
AIFunctionFactory
.Create((int theParam) => theParam * 2),
67
AIFunctionFactory
.Create((int? theParam) => theParam * 2),
85
AIFunction func =
AIFunctionFactory
.Create((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) =>
101
func =
AIFunctionFactory
.Create(Task<string> (string a) => Task.FromResult(a + " " + a));
104
func =
AIFunctionFactory
.Create(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a));
108
func =
AIFunctionFactory
.Create(async Task (int a, long b) => { result = a + b; await Task.Yield(); });
113
func =
AIFunctionFactory
.Create(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); });
117
func =
AIFunctionFactory
.Create((int count) => SimpleIAsyncEnumerable(count), serializerOptions: JsonContext.Default.Options);
129
func =
AIFunctionFactory
.Create(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable(), serializerOptions: JsonContext.Default.Options);
146
func =
AIFunctionFactory
.Create(dotnetFunc);
152
func =
AIFunctionFactory
.Create(dotnetFunc2);
158
func =
AIFunctionFactory
.Create(dotnetFunc3);
188
AIFunction func =
AIFunctionFactory
.Create(dotnetFunc, options);
212
AIFunction func =
AIFunctionFactory
.Create(
239
AIFunction func =
AIFunctionFactory
.Create((
281
AIFunction func =
AIFunctionFactory
.Create((
313
AIFunction func =
AIFunctionFactory
.Create(
335
AIFunction func =
AIFunctionFactory
.Create(
352
AIFunction func =
AIFunctionFactory
.Create(
363
Assert.Throws<ArgumentException>("method", () =>
AIFunctionFactory
.Create(
371
Assert.Throws<ArgumentException>("targetType", () =>
AIFunctionFactory
.Create(
379
AIFunction func =
AIFunctionFactory
.Create(
398
AIFunction func =
AIFunctionFactory
.Create(
417
AIFunction func =
AIFunctionFactory
.Create(
444
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices("key")] MyService service, int myInteger) => service.Value + myInteger,
465
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices(null!)] MyService service, int myInteger) => service.Value + myInteger,
486
AIFunction f =
AIFunctionFactory
.Create(([FromKeyedServices("key")] MyService? service = null, int myInteger = 0) =>
505
AIFunction f =
AIFunctionFactory
.Create(
557
AIFunction f =
AIFunctionFactory
.Create(
574
AIFunction f =
AIFunctionFactory
.Create(
590
AIFunction f =
AIFunctionFactory
.Create(
613
AIFunction f =
AIFunctionFactory
.Create(
636
AIFunction f =
AIFunctionFactory
.Create(
659
AIFunction f =
AIFunctionFactory
.Create(
682
AIFunction f =
AIFunctionFactory
.Create(
705
AIFunction f =
AIFunctionFactory
.Create(
728
AIFunction f =
AIFunctionFactory
.Create(
751
AIFunction f =
AIFunctionFactory
.Create(
774
AIFunction f =
AIFunctionFactory
.Create((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);