99 references to InvokeAsync
Microsoft.Extensions.AI (35)
ChatCompletion\FunctionInvokingChatClient.cs (1)
875return 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)
112var result = await function.InvokeAsync(arguments); 134var result = await function.InvokeAsync(arguments); 167var result = await function.InvokeAsync(new(arguments)); 188var result = await function.InvokeAsync(new(arguments)); 206var result = await NetTypelessAIFunction.Instance.InvokeAsync(arguments); 224var result = await NetTypelessAIFunction.Instance.InvokeAsync(arguments); 242var result = await NetTypelessAIFunction.Instance.InvokeAsync(arguments);
Microsoft.Extensions.AI.Tests (56)
Functions\AIFunctionFactoryTest.cs (56)
42AssertExtensions.EqualFunctionCallResults("test test", await func.InvokeAsync(new() { ["a"] = "test" })); 45AssertExtensions.EqualFunctionCallResults("hello world", await func.InvokeAsync(new() { ["b"] = "hello", ["a"] = "world" })); 48AssertExtensions.EqualFunctionCallResults(3L, await func.InvokeAsync(new() { ["a"] = 1, ["b"] = 2L })); 55AssertExtensions.EqualFunctionCallResults("test test", await func.InvokeAsync()); 56AssertExtensions.EqualFunctionCallResults("hello hello", await func.InvokeAsync(new() { ["a"] = "hello" })); 72Exception e = await Assert.ThrowsAsync<ArgumentException>(() => f.InvokeAsync().AsTask()); 90AssertExtensions.EqualFunctionCallResults(42, await func.InvokeAsync(cancellationToken: ctArg)); 102AssertExtensions.EqualFunctionCallResults("test test", await func.InvokeAsync(new() { ["a"] = "test" })); 105AssertExtensions.EqualFunctionCallResults("hello world", await func.InvokeAsync(new() { ["b"] = "hello", ["a"] = "world" })); 109AssertExtensions.EqualFunctionCallResults(null, await func.InvokeAsync(new() { ["a"] = 1, ["b"] = 2L })); 114AssertExtensions.EqualFunctionCallResults(null, await func.InvokeAsync(new() { ["a"] = 1, ["b"] = 2L })); 118AssertExtensions.EqualFunctionCallResults(new int[] { 0, 1, 2, 3, 4 }, await func.InvokeAsync(new() { ["count"] = 5 }), JsonContext.Default.Options); 130await Assert.ThrowsAsync<NotImplementedException>(() => func.InvokeAsync().AsTask()); 222var result = (JsonElement?)await func.InvokeAsync(new() 267await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => func.InvokeAsync(arguments).AsTask()); 270var result = await func.InvokeAsync(arguments); 295var result = await func.InvokeAsync(new() { ["myInteger"] = 42 }); 298result = await func.InvokeAsync(); 316await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.InvokeAsync(new()).AsTask()); 317await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.InvokeAsync(new() { Services = sp }).AsTask()); 329Assert.Contains("456", (await func.InvokeAsync(new()))?.ToString()); 330Assert.Contains("456", (await func.InvokeAsync(new() { Services = sp }))?.ToString()); 340await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => func.InvokeAsync(new()).AsTask()); 341await Assert.ThrowsAsync<ArgumentException>("arguments", () => func.InvokeAsync(new() { Services = new ServiceCollection().BuildServiceProvider() }).AsTask()); 342Assert.Contains("123", (await func.InvokeAsync(new() { Services = sp }))?.ToString()); 347Assert.Contains("456", (await func.InvokeAsync(new()))?.ToString()); 348Assert.Contains("123", (await func.InvokeAsync(new() { Services = sp }))?.ToString()); 371var result = (Tuple<MyFunctionTypeWithOneArg, MyArgumentType>?)await func.InvokeAsync(new() { Services = sp }); 388Assert.Equal("42", await func.InvokeAsync()); 401await Assert.ThrowsAsync<InvalidOperationException>(async () => await func.InvokeAsync(new() { Services = sp })); 431var d1 = Assert.IsType<DisposableService>(await func.InvokeAsync()); 432var d2 = Assert.IsType<DisposableService>(await func.InvokeAsync()); 450var d1 = Assert.IsType<AsyncDisposableService>(await func.InvokeAsync()); 451var d2 = Assert.IsType<AsyncDisposableService>(await func.InvokeAsync()); 469var d1 = Assert.IsType<DisposableAndAsyncDisposableService>(await func.InvokeAsync()); 470var d2 = Assert.IsType<DisposableAndAsyncDisposableService>(await func.InvokeAsync()); 493Exception e = await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => f.InvokeAsync(new() { ["myInteger"] = 1 }).AsTask()); 496var result = await f.InvokeAsync(new() { ["myInteger"] = 1, Services = sp }); 514Exception e = await Assert.ThrowsAsync<ArgumentNullException>("arguments.Services", () => f.InvokeAsync(new() { ["myInteger"] = 1 }).AsTask()); 517var result = await f.InvokeAsync(new() { ["myInteger"] = 1, Services = sp }); 536var result = await f.InvokeAsync(new() { ["myInteger"] = 1 }); 539result = await f.InvokeAsync(new() { ["myInteger"] = 1, Services = sp }); 573Exception e = await Assert.ThrowsAsync<ArgumentException>(() => f.InvokeAsync(new() { ["myInteger"] = 1 }).AsTask()); 576e = await Assert.ThrowsAsync<ArgumentException>(() => f.InvokeAsync(new() 583var result = await f.InvokeAsync(new() 607var result = await f.InvokeAsync(new() { Services = sp1 }); 624var result = await f.InvokeAsync(args1); 647object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 670object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 693object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 716object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 739object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 762object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 785object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 808object? result = await f.InvokeAsync(new() { ["i"] = 42 }, cts.Token); 819object? result = await f.InvokeAsync();