Skip to content

[API Proposal]: Microsoft.Extensions.AI - Use structured output with function calling #5612

@sylvain-guillet

Description

@sylvain-guillet

Background and motivation

Allow developers to use structured output with function calling : https://platform.openai.com/docs/guides/function-calling#function-calling-with-structured-outputs

Open AI says:

"By default, when you use function calling, the API will offer best-effort matching for your parameters, which means that occasionally the model may miss parameters or get their types wrong when using complicated schemas.

Structured Outputs is a feature that ensures model outputs for function calls will exactly match your supplied schema.

Structured Outputs for function calling can be enabled with a single parameter, just by supplying strict: true"

API Proposal

public static AIFunction Create(
      Delegate method,
bool isStrict,
      string? name = null,
      string? description = null,
      JsonSerializerOptions? serializerOptions = null)
    {
      ...
    }

API Usage

AIFunctionFactory.Create(Tools.TimeTools.ConvertDateTime,strict:true), //set strict to true

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions