Skip to content

Missing parameters to AIFunctionFactory functions result in default value being passed #6124

@stephentoub

Description

@stephentoub

If I have a non-optional parameter in an AIFunction returned by AIFunctionFactory, and the values passed to InvokeAsync do not include a value for that parameter, the default value ends up getting used, rather than an exception being thrown. Is that the desired behavior?

Repro:

using Microsoft.Extensions.AI;

AIFunction f = AIFunctionFactory.Create((int a, int b) => a + b);
Console.WriteLine(await f.InvokeAsync([new KeyValuePair<string, object?>("a", 42)]));

That prints 42 rather than throwing an exception, even though there's no value for the non-optional b parameter.

cc: @eiriktsarpalis, @SteveSandersonMS

Metadata

Metadata

Assignees

Labels

area-aiMicrosoft.Extensions.AI libraries

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions