333 references to Create
DotNetHostedAgent (1)
Program.cs (1)
67
tools: [AIFunctionFactory.
Create
(GetWeatherForecast), searchAgent.AsAIFunction()]);
Microsoft.Extensions.AI (4)
ChatCompletion\FunctionInvocationContext.cs (1)
18
private static readonly AIFunction _nopFunction = AIFunctionFactory.
Create
(() => { }, nameof(FunctionInvocationContext));
ChatCompletion\ImageGeneratingChatClient.cs (3)
290
AIFunctionFactory.
Create
(GenerateImageAsync),
291
AIFunctionFactory.
Create
(EditImageAsync),
292
AIFunctionFactory.
Create
(GetImagesForEdit)
Microsoft.Extensions.AI.Abstractions.Tests (20)
ChatCompletion\ChatOptionsTests.cs (4)
72
AIFunctionFactory.
Create
(() => 42),
73
AIFunctionFactory.
Create
(() => 43),
189
AIFunctionFactory.
Create
(() => 42),
190
AIFunctionFactory.
Create
(() => 43),
Contents\FunctionCallContentTests.cs (6)
194
AIFunction function = AIFunctionFactory.
Create
((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
216
AIFunction function = AIFunctionFactory.
Create
((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
224
var ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.
Create
((CustomType arg) => { }, serializerOptions: TestJsonSerializerContext.Default.Options));
228
ex = Assert.Throws<NotSupportedException>(() => AIFunctionFactory.
Create
(() => new CustomType(), serializerOptions: TestJsonSerializerContext.Default.Options));
249
AIFunction function = AIFunctionFactory.
Create
((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
270
AIFunction function = AIFunctionFactory.
Create
((DayOfWeek[] a, double b, Guid c, Dictionary<string, string> d) => b, serializerOptions: TestJsonSerializerContext.Default.Options);
Functions\ApprovalRequiredAIFunctionTests.cs (2)
21
var inner = AIFunctionFactory.
Create
(() => 42);
37
var inner = AIFunctionFactory.
Create
(() => "result");
Functions\DelegatingAIFunctionTests.cs (2)
23
AIFunction expected = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => 42));
65
AIFunction inner = AIFunctionFactory.
Create
(int () =>
Realtime\RealtimeClientMessageTests.cs (1)
144
var tools = new List<AITool> { AIFunctionFactory.
Create
(() => 42) };
Realtime\RealtimeSessionOptionsTests.cs (1)
38
List<AITool> tools = [AIFunctionFactory.
Create
(() => 42)];
Utilities\AIJsonSchemaTransformCacheTests.cs (1)
51
AIFunction func = AIFunctionFactory.
Create
((int x, int y) => x + y);
Utilities\AIJsonUtilitiesTests.cs (3)
291
AIFunction func = AIFunctionFactory.
Create
((int x, int y) => x + y, serializerOptions: options);
366
AIFunction func = AIFunctionFactory.
Create
((int a, int? b, long c, short d, float e, double f, decimal g) => { }, serializerOptions: options);
414
AIFunction func = AIFunctionFactory.
Create
(([Range(1, 10)] int num, [StringLength(100, MinimumLength = 1)] string str) => num + str.Length, serializerOptions: options);
Microsoft.Extensions.AI.Evaluation.Integration.Tests (2)
AgentQualityEvaluatorTests.cs (2)
42
Tools = [AIFunctionFactory.
Create
(GetOrders), AIFunctionFactory.
Create
(GetOrderStatus)]
Microsoft.Extensions.AI.Integration.Tests (17)
ChatClientIntegrationTests.cs (17)
236
Tools = [AIFunctionFactory.
Create
(() => secretNumber, "GetSecretNumber")]
252
Tools = [AIFunctionFactory.
Create
((int a, int b) => a * b, "SecretComputation")]
267
Tools = [AIFunctionFactory.
Create
((int a, int b) => a * b, "SecretComputation")]
301
AIFunction func = AIFunctionFactory.
Create
((string id = "defaultId") => id is "foo" ? secretNumber : -1, "GetSecretNumberById");
333
AIFunction func = AIFunctionFactory.
Create
((PersonRecord person) => person.Name is "John" ? secretNumber + person.Age : -1, "GetSecretNumberByPerson");
365
AIFunction func = AIFunctionFactory.
Create
((string[] items, string shopperId) => { shoppingCart.AddRange(items); shopperName = shopperId; }, "AddItemsToShoppingCart");
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) =>
1220
var getWeather = AIFunctionFactory.
Create
(([Description("Gets weather for a city")] string city) =>
Microsoft.Extensions.AI.OllamaSharp.Integration.Tests (3)
OllamaSharpChatClientIntegrationTests.cs (3)
47
Tools = [AIFunctionFactory.
Create
(() => secretNumber, "GetSecretNumber")],
67
var stockPriceTool = AIFunctionFactory.
Create
([Description("Returns the stock price for a given ticker symbol")] (
77
var irrelevantTool = AIFunctionFactory.
Create
(() => { didCallIrrelevantTool = true; return 123; }, "GetSecretNumber");
Microsoft.Extensions.AI.OpenAI.Tests (49)
OpenAIChatClientTests.cs (8)
334
Tools = [AIFunctionFactory.
Create
(() => 42, "GetPersonAge", "Gets the age of the specified person.")],
384
AIFunction tool = AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
461
AIFunction tool = AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
544
AIFunction tool = AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
618
AIFunction tool = AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
731
Tools = [AIFunctionFactory.
Create
((string name) => 42, "GetPersonAge")],
1143
Tools = [AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.")],
1328
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)
24
private static readonly AIFunction _testFunction = AIFunctionFactory.
Create
(
OpenAIResponseClientIntegrationTests.cs (13)
567
Tools = [AIFunctionFactory.
Create
((int a, int b) => new TextContent($"The sum is {a + b}"), "AddNumbers", "Adds two numbers together")]
587
Tools = [AIFunctionFactory.
Create
((string city) => new List<AIContent>
615
Tools = [AIFunctionFactory.
Create
(() => new DataContent(ImageDataUri.GetImageDataUri(), "image/png"), "GetDotnetLogo", "Returns the .NET logo image")]
640
Tools = [AIFunctionFactory.
Create
(() => new DataContent(ImageDataUri.GetPdfDataUri(), "application/pdf") { Name = "document.pdf" }, "GetDocument", "Returns a PDF document")]
663
Tools = [AIFunctionFactory.
Create
(() => new List<AIContent>
858
AIFunction getWeather = AIFunctionFactory.
Create
(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
859
AIFunction getTime = AIFunctionFactory.
Create
(() => "3:00 PM", "GetTime", "Gets the current time.");
914
AIFunction getWeather = AIFunctionFactory.
Create
(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
962
AIFunction getWeather = AIFunctionFactory.
Create
(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
963
AIFunction getTime = AIFunctionFactory.
Create
(() => "3:00 PM", "GetTime", "Gets the current time.");
1004
AIFunction getWeather = AIFunctionFactory.
Create
(() => "Sunny, 72°F", "GetWeather", "Gets the current weather.");
1005
AIFunction getTime = AIFunctionFactory.
Create
(() => "3:00 PM", "GetTime", "Gets the current time.");
1006
AIFunction getCustomer = AIFunctionFactory.
Create
((string id) => $"Customer {id}", "GetCustomer", "Gets a customer by id.");
OpenAIResponseClientTests.cs (27)
1090
Tools = [AIFunctionFactory.
Create
(() => 42, "GetPersonAge", "Gets the age of the specified person.")],
1232
AIFunction tool = AIFunctionFactory.
Create
(([Description("The person whose age is being requested")] string personName) => 42, "GetPersonAge", "Gets the age of the specified person.");
7448
var getWeather = AIFunctionFactory.
Create
(() => 42, "GetWeather", "Gets the weather.");
7449
var getForecast = AIFunctionFactory.
Create
(() => 42, "GetForecast", "Gets the forecast.");
7540
var getWeather = AIFunctionFactory.
Create
(() => 42, "GetWeather", "Gets the weather.");
7541
var importantTool = AIFunctionFactory.
Create
(() => 42, "ImportantTool", "An important tool.");
7716
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
7717
var listOrders = AIFunctionFactory.
Create
(() => 42, "ListOrders", "Lists orders.");
7718
var importantTool = AIFunctionFactory.
Create
(() => 42, "ImportantTool", "An important tool.");
7817
var getWeather = AIFunctionFactory.
Create
(() => 42, "GetWeather", "Gets the weather.");
7818
var getTime = AIFunctionFactory.
Create
(() => 42, "GetTime", "Gets the time.");
7922
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
7923
var getWeather = AIFunctionFactory.
Create
(() => 42, "GetWeather", "Gets the weather.");
8022
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
8023
var listOrders = AIFunctionFactory.
Create
(() => 42, "ListOrders", "Lists orders.");
8109
var sharedTool = AIFunctionFactory.
Create
(() => 42, "SharedTool", "A shared tool.");
8201
var localFunc = AIFunctionFactory.
Create
(() => 42, "LocalFunc", "A local function.");
8286
var localFunc = AIFunctionFactory.
Create
(() => 42, "LocalFunc", "A local function.");
8398
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
8399
var listOrders = AIFunctionFactory.
Create
(() => 42, "ListOrders", "Lists orders.");
8400
var importantTool = AIFunctionFactory.
Create
(() => 42, "ImportantTool", "An important tool.");
8497
var getWeather = AIFunctionFactory.
Create
(() => 42, "GetWeather", "Gets the weather.");
8498
var importantTool = AIFunctionFactory.
Create
(() => 42, "ImportantTool", "An important tool.");
8602
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
8603
var listOrders = AIFunctionFactory.
Create
(() => 42, "ListOrders", "Lists orders.");
8715
var getCustomer = AIFunctionFactory.
Create
(() => 42, "GetCustomer", "Gets a customer.");
8716
var listOrders = AIFunctionFactory.
Create
(() => 42, "ListOrders", "Lists orders.");
Microsoft.Extensions.AI.Tests (237)
ChatCompletion\FunctionInvocationContextTests.cs (1)
51
AIFunction function = AIFunctionFactory.
Create
(() => { }, nameof(Properties_Roundtrip));
ChatCompletion\FunctionInvokingChatClientApprovalsTests.cs (54)
24
AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
26
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2")),
65
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
66
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
102
AIFunction func1 = AIFunctionFactory.
Create
(() => "Result 1", "Func1");
103
AIFunction func2 = AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2");
161
AIFunctionFactory.
Create
(() => "Result 1", "Func1"))),
162
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
208
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
249
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
250
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
300
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
301
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2")),
353
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
354
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
412
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
413
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
471
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
472
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
535
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
536
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
600
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
601
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
602
AIFunctionFactory.
Create
((string s) => $"Result 3: {s}", "Func3"),
694
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
751
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
752
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2")),
805
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
806
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2")),
885
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
957
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1021
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1022
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
1076
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1077
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
1106
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1107
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
1152
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1153
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
1198
Tools = [new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"))],
1248
Tools = [new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"))],
1294
Tools = [new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"))],
1349
Tools = [new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"))],
1402
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() =>
1462
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
1463
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
1537
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
1538
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2")),
1539
AIFunctionFactory.
Create
(() => "Result 3", "Func3"),
1637
AIFunctionFactory.
Create
(() => { functionInvokedCount++; return "Result 1"; }, "Func1")),
1676
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1")),
1725
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func")),
1768
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func")),
1852
new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func")),
ChatCompletion\FunctionInvokingChatClientTests.cs (89)
73
IList<AITool> additionalTools = [AIFunctionFactory.
Create
(() => "Additional Tool")];
85
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
86
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
87
AIFunctionFactory.
Create
((int i) => { }, "VoidReturn"),
114
new() { Tools = [AIFunctionFactory.
Create
(() => "Shouldn't be invoked", "ChatOptionsFunc")] } :
120
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
121
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
122
AIFunctionFactory.
Create
((int i) => { }, "VoidReturn"),
147
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
153
AIFunctionFactory.
Create
(() => "Should never be invoked", "Func1"),
154
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
155
AIFunctionFactory.
Create
((int i) => { }, "VoidReturn"),
184
AIFunctionFactory.
Create
((int? i = 42) => "Result 1", "Func1"),
185
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
235
AIFunctionFactory.
Create
(async (string arg) =>
282
AIFunctionFactory.
Create
(async (string arg) =>
321
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
322
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
323
AIFunctionFactory.
Create
((int i) => { }, "VoidReturn"),
368
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
449
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
530
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
630
AIFunctionFactory.
Create
(() => { actualCallCount++; }, "VoidReturn"),
680
Tools = [AIFunctionFactory.
Create
(() => "Result", "Func1")],
724
Tools = [AIFunctionFactory.
Create
(() => "Result", "Func1")],
777
Tools = [AIFunctionFactory.
Create
(() => "Result", "Func1"), hostedTool],
814
var originalTool = AIFunctionFactory.
Create
(() => "Result", "Func1");
845
AIFunctionFactory.
Create
((bool shouldThrow, int callIndex) =>
926
AIFunctionFactory.
Create
(() =>
975
AIFunctionFactory.
Create
(() => "Result 1", "Func1"),
976
AIFunctionFactory.
Create
((int i) => $"Result 2: {i}", "Func2"),
977
AIFunctionFactory.
Create
((int i) => { }, "VoidReturn"),
1014
AIFunctionFactory.
Create
(string () => throw new InvalidOperationException("Oh no!"), "Func1"),
1050
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1107
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1172
Tools = [AIFunctionFactory.
Create
((string text) => $"Result for {text}", "Func1")]
1230
Tools = [AIFunctionFactory.
Create
(() => "doesn't matter", "Func1")]
1269
var function = AIFunctionFactory.
Create
(async (int i) =>
1344
var function = AIFunctionFactory.
Create
((string? result = null) =>
1399
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")],
1460
Tools = [AIFunctionFactory.
Create
((IServiceProvider actual) =>
1493
Tools = [AIFunctionFactory.
Create
(async (string arg, CancellationToken cancellationToken) =>
1521
Tools = [AIFunctionFactory.
Create
((int i) => $"Known: {i}", "KnownFunc")]
1573
var declarationOnly = AIFunctionFactory.
Create
(() => "unused", "DefOnly").AsDeclarationOnly();
1598
var known = AIFunctionFactory.
Create
(() => { invoked++; return "OK"; }, "Known");
1599
var defOnly = AIFunctionFactory.
Create
(() => "unused", "DefOnly").AsDeclarationOnly();
1656
Tools = [AIFunctionFactory.
Create
(() => { }, "Func1")],
1689
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1754
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1800
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1842
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1892
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
1964
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
2000
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
2029
Tools = [AIFunctionFactory.
Create
(() => { functionInvokedCount++; return "Result 1"; }, "Func1")]
2079
AIFunctionFactory.
Create
(() => { func1InvokedCount++; return "Result 1"; }, "Func1"),
2080
AIFunctionFactory.
Create
(() => { func2InvokedCount++; return "Result 2"; }, "Func2"),
2147
Tools = [AIFunctionFactory.
Create
(() => { functionInvokedCount++; return "Result 1"; }, "Func1")]
2359
AIFunction functionB = AIFunctionFactory.
Create
(() => "FunctionB result", "FunctionB");
2362
AIFunction functionA = AIFunctionFactory.
Create
(
2453
AIFunction functionB = AIFunctionFactory.
Create
(() => "FunctionB result", "FunctionB");
2456
AIFunction functionA = AIFunctionFactory.
Create
(
2554
AIFunction originalFunctionB = AIFunctionFactory.
Create
(() => "Original FunctionB result", "FunctionB");
2555
AIFunction replacementFunctionB = AIFunctionFactory.
Create
(() => "Replacement FunctionB result", "FunctionB");
2558
AIFunction functionA = AIFunctionFactory.
Create
(
2659
AIFunction additionalTool = AIFunctionFactory.
Create
(() => "AdditionalTool result", "AdditionalTool");
2660
AIFunction functionB = AIFunctionFactory.
Create
(() => "FunctionB result", "FunctionB");
2663
AIFunction functionA = AIFunctionFactory.
Create
(
2762
AIFunction additionalToolSameName = AIFunctionFactory.
Create
(() => "AdditionalTool version", "SharedName");
2763
AIFunction addedToolSameName = AIFunctionFactory.
Create
(() => "Added version", "SharedName");
2766
AIFunction functionA = AIFunctionFactory.
Create
(
2866
AIFunction functionA = AIFunctionFactory.
Create
(
2939
AIFunction functionB = AIFunctionFactory.
Create
(() => "FunctionB result", "FunctionB");
2942
AIFunction functionA = AIFunctionFactory.
Create
(
3040
AIFunction functionB = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "FunctionB result", "FunctionB"));
3043
AIFunction functionA = AIFunctionFactory.
Create
(
3142
AIFunction originalFunctionB = AIFunctionFactory.
Create
(() => "Original FunctionB result", "FunctionB");
3143
AIFunction replacementFunctionB = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Replacement FunctionB result", "FunctionB"));
3146
AIFunction functionA = AIFunctionFactory.
Create
(
3252
Tools = [AIFunctionFactory.
Create
(() => "Result 1", "Func1")]
3279
var declarationOnly = AIFunctionFactory.
Create
(() => "Result 1", "Func1").AsDeclarationOnly();
3313
Tools = [AIFunctionFactory.
Create
(() =>
3344
var approvalFunc = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"));
3381
var approvalFunc = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"));
3418
var approvalFunc = new ApprovalRequiredAIFunction(AIFunctionFactory.
Create
(() => "Result 1", "Func1"));
3464
Tools = [AIFunctionFactory.
Create
(() => { functionInvokedCount++; return "Result 1"; }, "Func1")]
3521
AIFunctionFactory.
Create
(() => { func1InvokedCount++; return "Local Result 1"; }, "Func1"),
3522
AIFunctionFactory.
Create
(() => { func2InvokedCount++; return "Local Result 2"; }, "Func2"),
3595
Tools = [AIFunctionFactory.
Create
(() => { functionInvokedCount++; return "Local Result"; }, "Func1")]
ChatCompletion\ImageGeneratingChatClientTests.cs (2)
48
Tools = [AIFunctionFactory.
Create
(() => "dummy function", name: "DummyFunction")]
130
var dummyFunction = AIFunctionFactory.
Create
(() => "dummy", name: "DummyFunction");
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
142
AIFunctionFactory.
Create
((string personName) => personName, "GetPersonAge", "Gets the age of a person by name."),
147
AIFunctionFactory.
Create
((string location) => "", "GetCurrentWeather", "Gets the current weather for a location.").AsDeclarationOnly(),
Functions\AIFunctionFactoryTest.cs (80)
34
Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.
Create
(method: null!));
48
func = AIFunctionFactory.
Create
((string a) => a + " " + a);
51
func = AIFunctionFactory.
Create
((string a, string b) => b + " " + a);
54
func = AIFunctionFactory.
Create
((int a, long b) => a + b);
61
AIFunction func = AIFunctionFactory.
Create
((string a = "test") => a + " " + a);
70
AIFunction funcNull = AIFunctionFactory.
Create
(([DefaultValue(null)] string? text) => text ?? "was null");
85
AIFunction funcValue = AIFunctionFactory.
Create
(([DefaultValue("default")] string text) => text);
94
AIFunction funcInt = AIFunctionFactory.
Create
(([DefaultValue(42)] int x) => x * 2);
103
AIFunction funcBoth = AIFunctionFactory.
Create
(([DefaultValue(100)] int y = 50) => y);
116
AIFunctionFactory.
Create
((string theParam) => theParam + " " + theParam),
117
AIFunctionFactory.
Create
((string? theParam) => theParam + " " + theParam),
118
AIFunctionFactory.
Create
((int theParam) => theParam * 2),
119
AIFunctionFactory.
Create
((int? theParam) => theParam * 2),
120
AIFunctionFactory.
Create
(([AIParameterName("theParam")] string otherName) => otherName),
133
AIFunction func = AIFunctionFactory.
Create
((int x, int y, int z, int w, int u) => x + y + z + w + u);
162
AIFunction func = AIFunctionFactory.
Create
((JsonElement param) => param, serializerOptions: options);
182
AIFunction func = AIFunctionFactory.
Create
((JsonElement param) => param);
201
AIFunction func = AIFunctionFactory.
Create
((int value1 = 1, string value2 = "2", CancellationToken cancellationToken = default) =>
217
func = AIFunctionFactory.
Create
(Task<string> (string a) => Task.FromResult(a + " " + a));
221
func = AIFunctionFactory.
Create
(ValueTask<string> (string a, string b) => new ValueTask<string>(b + " " + a));
226
func = AIFunctionFactory.
Create
(async Task (int a, long b) => { result = a + b; await Task.Yield(); });
232
func = AIFunctionFactory.
Create
(async ValueTask (int a, long b) => { result = a + b; await Task.Yield(); });
237
func = AIFunctionFactory.
Create
((int count) => SimpleIAsyncEnumerable(count), serializerOptions: JsonContext.Default.Options);
250
func = AIFunctionFactory.
Create
(() => (IAsyncEnumerable<int>)new ThrowingAsyncEnumerable(), serializerOptions: JsonContext.Default.Options);
267
func = AIFunctionFactory.
Create
(dotnetFunc);
273
func = AIFunctionFactory.
Create
(dotnetFunc2);
279
func = AIFunctionFactory.
Create
(dotnetFunc3);
293
AIFunction func = AIFunctionFactory.
Create
(funcWithDisplayName);
299
func = AIFunctionFactory.
Create
(funcWithBoth);
304
func = AIFunctionFactory.
Create
(funcWithDisplayName, name: "explicit_name");
317
func = AIFunctionFactory.
Create
(funcWithoutDisplayName);
325
AIFunction func = AIFunctionFactory.
Create
(funcWithAttribute);
329
func = AIFunctionFactory.
Create
(funcWithBoth);
332
func = AIFunctionFactory.
Create
(funcWithAttribute, name: "explicit_name");
342
AIFunction func = AIFunctionFactory.
Create
([AIFunctionName("my_tool")] ([AIParameterName("my_param")] string myParam) => myParam);
355
AIFunction func = AIFunctionFactory.
Create
(([AIParameterName("$select")] string select, int top) => select + top);
363
AIFunction func = AIFunctionFactory.
Create
(
431
ArgumentException ex = Assert.Throws<ArgumentException>(() => AIFunctionFactory.
Create
(
436
ArgumentException ex2 = Assert.Throws<ArgumentException>(() => AIFunctionFactory.
Create
(
638
AIFunction func = AIFunctionFactory.
Create
((
682
AIFunction func = AIFunctionFactory.
Create
((
1162
AIFunctionFactory.
Create
(() => (AIContent)new TextContent("text")),
1163
AIFunctionFactory.
Create
(async () => (AIContent)new TextContent("text")),
1164
AIFunctionFactory.
Create
(async ValueTask<AIContent> () => (AIContent)new TextContent("text")),
1165
AIFunctionFactory.
Create
(() => new TextContent("text")),
1166
AIFunctionFactory.
Create
(async () => new TextContent("text")),
1167
AIFunctionFactory.
Create
(async ValueTask<AIContent> () => new TextContent("text")),
1172
AIFunctionFactory.
Create
(() => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
1173
AIFunctionFactory.
Create
(async () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
1174
AIFunctionFactory.
Create
(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
1179
AIFunctionFactory.
Create
(() => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1180
AIFunctionFactory.
Create
(async () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1181
AIFunctionFactory.
Create
(async ValueTask<IEnumerable<AIContent>> () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1186
AIFunctionFactory.
Create
(() => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1187
AIFunctionFactory.
Create
(async () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1188
AIFunctionFactory.
Create
(async ValueTask<AIContent[]> () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1193
AIFunctionFactory.
Create
(() => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1194
AIFunctionFactory.
Create
(async () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1195
AIFunctionFactory.
Create
(async ValueTask<List<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1200
AIFunctionFactory.
Create
(() => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1201
AIFunctionFactory.
Create
(async () => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1202
AIFunctionFactory.
Create
(async ValueTask<IList<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
1219
AIFunction f = AIFunctionFactory.
Create
((Guid g = default, StructWithDefaultCtor s = default) => g.ToString() + "," + s.Value.ToString(), serializerOptions: JsonContext.Default.Options);
1230
AIFunction f = AIFunctionFactory.
Create
(
1263
AIFunction f = AIFunctionFactory.
Create
(
1293
AIFunction f = AIFunctionFactory.
Create
(Add, serializerOptions: JsonContext.Default.Options);
1419
var tool = AIFunctionFactory.
Create
(DoSomething);
1438
var tool1 = AIFunctionFactory.
Create
(FirstLocal);
1439
var tool2 = AIFunctionFactory.
Create
(SecondLocal);
1455
var tool = AIFunctionFactory.
Create
(lambda);
1474
var tool1 = AIFunctionFactory.
Create
(lambda1);
1475
var tool2 = AIFunctionFactory.
Create
(lambda2);
1489
var tool = AIFunctionFactory.
Create
(Add);
1505
var tool = AIFunctionFactory.
Create
(FetchDataAsync);
1522
var tool = AIFunctionFactory.
Create
(DoSomething, name: "CustomName");
1531
var tool = AIFunctionFactory.
Create
(Add, serializerOptions: JsonContext.Default.Options);
1543
var tool = AIFunctionFactory.
Create
(TestStaticMethod, null, serializerOptions: JsonContext.Default.Options);
1553
AIFunction func = AIFunctionFactory.
Create
(
1593
AIFunction func = AIFunctionFactory.
Create
(
1723
AIFunction func = AIFunctionFactory.
Create
(
Realtime\FunctionInvokingRealtimeClientTests.cs (8)
91
AIFunction getWeather = AIFunctionFactory.
Create
(
141
AIFunction getWeather = AIFunctionFactory.
Create
(
179
AIFunction countFunc = AIFunctionFactory.
Create
(
219
AIFunction myFunc = AIFunctionFactory.
Create
(
285
AIFunction failFunc = AIFunctionFactory.
Create
(
323
AIFunction failFunc = AIFunctionFactory.
Create
(
448
AIFunction slowFunc = AIFunctionFactory.
Create
(
515
AIFunction failFunc = AIFunctionFactory.
Create
(
Realtime\OpenTelemetryRealtimeClientTests.cs (1)
43
Tools = [AIFunctionFactory.
Create
((string query) => query, "Search", "Search for information.")],