99 references to InvokeAsync
Microsoft.Extensions.AI (35)
ChatCompletion\FunctionInvokingChatClient.cs (1)
875
return context.Function.
InvokeAsync
(context.Arguments, cancellationToken);
Functions\AIFunctionFactory.cs (28)
51
/// the invocation via <see cref="AIFunction.
InvokeAsync
"/>'s <see cref="CancellationToken"/> parameter. The parameter is
67
/// passed into <see cref="AIFunction.
InvokeAsync
"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
68
/// instance passed to <see cref="AIFunction.
InvokeAsync
"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
88
/// from the <see cref="IServiceProvider"/> provided to <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>,
94
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.
InvokeAsync
"/>
99
/// into <see cref="AIFunction.
InvokeAsync
"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
152
/// the invocation via <see cref="AIFunction.
InvokeAsync
"/>'s <see cref="CancellationToken"/> parameter. The parameter is
167
/// passed into <see cref="AIFunction.
InvokeAsync
"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
168
/// instance passed to <see cref="AIFunction.
InvokeAsync
"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
186
/// from the <see cref="IServiceProvider"/> provided to <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>,
191
/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.
InvokeAsync
"/>
250
/// the invocation via <see cref="AIFunction.
InvokeAsync
"/>'s <see cref="CancellationToken"/> parameter. The parameter is
266
/// passed into <see cref="AIFunction.
InvokeAsync
"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
267
/// instance passed to <see cref="AIFunction.
InvokeAsync
"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
287
/// from the <see cref="IServiceProvider"/> provided to <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>,
293
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.
InvokeAsync
"/>
298
/// into <see cref="AIFunction.
InvokeAsync
"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
361
/// the invocation via <see cref="AIFunction.
InvokeAsync
"/>'s <see cref="CancellationToken"/> parameter. The parameter is
376
/// passed into <see cref="AIFunction.
InvokeAsync
"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
377
/// instance passed to <see cref="AIFunction.
InvokeAsync
"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
394
/// from the <see cref="IServiceProvider"/> provided to <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>,
400
/// All other parameter types are bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.
InvokeAsync
"/>
474
/// the invocation via <see cref="AIFunction.
InvokeAsync
"/>'s <see cref="CancellationToken"/> parameter. The parameter is
490
/// passed into <see cref="AIFunction.
InvokeAsync
"/> and are not included in the JSON schema. If the <see cref="AIFunctionArguments"/>
491
/// instance passed to <see cref="AIFunction.
InvokeAsync
"/> is <see langword="null"/>, the <see cref="AIFunction"/> implementation
511
/// from the <see cref="IServiceProvider"/> provided to <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>,
517
/// All other parameter types are, by default, bound from the <see cref="AIFunctionArguments"/> dictionary passed into <see cref="AIFunction.
InvokeAsync
"/>
522
/// into <see cref="AIFunction.
InvokeAsync
"/> via the <see cref="AIFunctionArguments"/>'s <see cref="AIFunctionArguments.Context"/> dictionary; the default
Functions\AIFunctionFactoryOptions.cs (6)
67
/// provided to the <see cref="AIFunction.
InvokeAsync
"/> invocation.
76
/// <summary>Gets or sets a delegate used to determine the <see cref="object"/> returned by <see cref="AIFunction.
InvokeAsync
"/>.</summary>
80
/// is then JSON serialized, with the resulting <see cref="JsonElement"/> returned from the <see cref="AIFunction.
InvokeAsync
"/> method.
84
/// and its return value is then returned from the <see cref="AIFunction.
InvokeAsync
"/> method.
88
/// a <see langword="null"/> argument. By default, <see langword="null"/> is returned from the <see cref="AIFunction.
InvokeAsync
"/>
115
/// <see cref="AIFunction.
InvokeAsync
"/> via <see cref="AIFunctionArguments.Services"/>.
Microsoft.Extensions.AI.Abstractions (1)
Functions\AIFunctionArguments.cs (1)
19
/// <summary>Represents arguments to be used with <see cref="AIFunction.
InvokeAsync
"/>.</summary>
Microsoft.Extensions.AI.Abstractions.Tests (7)
Contents\FunctionCallContentTests..cs (7)
112
var result = await function.
InvokeAsync
(arguments);
134
var result = await function.
InvokeAsync
(arguments);
167
var result = await function.
InvokeAsync
(new(arguments));
188
var result = await function.
InvokeAsync
(new(arguments));
206
var result = await NetTypelessAIFunction.Instance.
InvokeAsync
(arguments);
224
var result = await NetTypelessAIFunction.Instance.
InvokeAsync
(arguments);
242
var result = await NetTypelessAIFunction.Instance.
InvokeAsync
(arguments);
Microsoft.Extensions.AI.Tests (56)
Functions\AIFunctionFactoryTest.cs (56)
42
AssertExtensions.EqualFunctionCallResults("test test", await func.
InvokeAsync
(new() { ["a"] = "test" }));
45
AssertExtensions.EqualFunctionCallResults("hello world", await func.
InvokeAsync
(new() { ["b"] = "hello", ["a"] = "world" }));
48
AssertExtensions.EqualFunctionCallResults(3L, await func.
InvokeAsync
(new() { ["a"] = 1, ["b"] = 2L }));
55
AssertExtensions.EqualFunctionCallResults("test test", await func.
InvokeAsync
());
56
AssertExtensions.EqualFunctionCallResults("hello hello", await func.
InvokeAsync
(new() { ["a"] = "hello" }));
72
Exception e = await Assert.ThrowsAsync<ArgumentException>(() => f.
InvokeAsync
().AsTask());
90
AssertExtensions.EqualFunctionCallResults(42, await func.
InvokeAsync
(cancellationToken: ctArg));
102
AssertExtensions.EqualFunctionCallResults("test test", await func.
InvokeAsync
(new() { ["a"] = "test" }));
105
AssertExtensions.EqualFunctionCallResults("hello world", await func.
InvokeAsync
(new() { ["b"] = "hello", ["a"] = "world" }));
109
AssertExtensions.EqualFunctionCallResults(null, await func.
InvokeAsync
(new() { ["a"] = 1, ["b"] = 2L }));
114
AssertExtensions.EqualFunctionCallResults(null, await func.
InvokeAsync
(new() { ["a"] = 1, ["b"] = 2L }));
118
AssertExtensions.EqualFunctionCallResults(new int[] { 0, 1, 2, 3, 4 }, await func.
InvokeAsync
(new() { ["count"] = 5 }), JsonContext.Default.Options);
130
await Assert.ThrowsAsync<NotImplementedException>(() => func.
InvokeAsync
().AsTask());
222
var result = (JsonElement?)await func.
InvokeAsync
(new()
267
await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => func.
InvokeAsync
(arguments).AsTask());
270
var result = await func.
InvokeAsync
(arguments);
295
var result = await func.
InvokeAsync
(new() { ["myInteger"] = 42 });
298
result = await func.
InvokeAsync
();
316
await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.
InvokeAsync
(new()).AsTask());
317
await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.
InvokeAsync
(new() { Services = sp }).AsTask());
329
Assert.Contains("456", (await func.
InvokeAsync
(new()))?.ToString());
330
Assert.Contains("456", (await func.
InvokeAsync
(new() { Services = sp }))?.ToString());
340
await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => func.
InvokeAsync
(new()).AsTask());
341
await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.
InvokeAsync
(new() { Services = new ServiceCollection().BuildServiceProvider() }).AsTask());
342
Assert.Contains("123", (await func.
InvokeAsync
(new() { Services = sp }))?.ToString());
347
Assert.Contains("456", (await func.
InvokeAsync
(new()))?.ToString());
348
Assert.Contains("123", (await func.
InvokeAsync
(new() { Services = sp }))?.ToString());
371
var result = (Tuple<MyFunctionTypeWithOneArg, MyArgumentType>?)await func.
InvokeAsync
(new() { Services = sp });
388
Assert.Equal("42", await func.
InvokeAsync
());
401
await Assert.ThrowsAsync<InvalidOperationException>(async () => await func.
InvokeAsync
(new() { Services = sp }));
431
var d1 = Assert.IsType<DisposableService>(await func.
InvokeAsync
());
432
var d2 = Assert.IsType<DisposableService>(await func.
InvokeAsync
());
450
var d1 = Assert.IsType<AsyncDisposableService>(await func.
InvokeAsync
());
451
var d2 = Assert.IsType<AsyncDisposableService>(await func.
InvokeAsync
());
469
var d1 = Assert.IsType<DisposableAndAsyncDisposableService>(await func.
InvokeAsync
());
470
var d2 = Assert.IsType<DisposableAndAsyncDisposableService>(await func.
InvokeAsync
());
493
Exception e = await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => f.
InvokeAsync
(new() { ["myInteger"] = 1 }).AsTask());
496
var result = await f.
InvokeAsync
(new() { ["myInteger"] = 1, Services = sp });
514
Exception e = await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => f.
InvokeAsync
(new() { ["myInteger"] = 1 }).AsTask());
517
var result = await f.
InvokeAsync
(new() { ["myInteger"] = 1, Services = sp });
536
var result = await f.
InvokeAsync
(new() { ["myInteger"] = 1 });
539
result = await f.
InvokeAsync
(new() { ["myInteger"] = 1, Services = sp });
573
Exception e = await Assert.ThrowsAsync<ArgumentException>(() => f.
InvokeAsync
(new() { ["myInteger"] = 1 }).AsTask());
576
e = await Assert.ThrowsAsync<ArgumentException>(() => f.
InvokeAsync
(new()
583
var result = await f.
InvokeAsync
(new()
607
var result = await f.
InvokeAsync
(new() { Services = sp1 });
624
var result = await f.
InvokeAsync
(args1);
647
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
670
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
693
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
716
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
739
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
762
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
785
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
808
object? result = await f.
InvokeAsync
(new() { ["i"] = 42 }, cts.Token);
819
object? result = await f.
InvokeAsync
();