Skip to content

[API Proposal]: IChatClient - Default ChatOptions #5941

@azchohfi

Description

@azchohfi

Background and motivation

Different IChatClient implementations might have different defaults for ChatOptions, which can be sent to CompleteAsync/CompleteStreamingAsync. Right now, there is no default way to retrieve such defaults. Yes, those methods allow you to send null to those parameters, which would use their default values for ChatOptions, but there is no way to retrieve that information in a generic way.
The only way to achieve this today is to use the GetService method, maybe sending a specific serviceKey ("DefaultChatOptions"?), but it would be nice to have a standard way of retrieving these values.

API Proposal

namespace System.Collections.Generic;

public interface IChatClient : IDisposable
{
...
ChatOptions? DefaultChatOptions { get; }
...
}

API Usage

IChatClient chatClient = ...;
// Check upper bound for MaxOutputTokens
if (desiredMaxOutputTokens < chatClient.DefaultChatOptions.MaxOutputTokens)
{
....
}

Alternative Designs

I can also see this being part of ChatClientMetadata, and maybe not even using ChatOptions directly, since it might have too many information that doesn't make sense for a default, but at least some default properties should be retrievable, somehow.

Risks

Its just extra metadata, so I don't see many risks. It is more work on implementations, but it should be optional/nullable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-aiMicrosoft.Extensions.AI libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions