Skip to content

Conversation

@kzu
Copy link
Member

@kzu kzu commented Oct 13, 2025

The following example (in this case using Tomlyn.Extensions.Configuration for .toml-formatted config) showcases configuration-driven clients for openai and xai:

[ai.clients.openai]
modelid = "gpt-4.1"
organizationid = "kzu"
projectid = "ai"
apikey = "sk-...."

[ai.clients.grok]
endpoint = "https://api.x.ai/v1"
modelid = "grok-4-fast-non-reasoning"
apikey = "xai-...."

Usage in an Azure Functions app:

var builder = FunctionsApplication.CreateBuilder(args);
builder.Configuration.AddTomlFile("ai.toml", optional: false, reloadOnChange: true);
builder.Services.UseChatClients(builder.Configuration);

var app = builder.Build();

var openai = services.GetRequiredKeyedService<IChatClient>("openai");
var xai = services.GetRequiredKeyedService<IChatClient>("grok");

The registered clients are fully reloadable when configuration changes, including swapping providers, changing default model, api key and so on.

This makes local development and testing of various settings super productive.

kzu added 4 commits October 11, 2025 20:59
Except for the ID since that's what the instance is exported as, everything else can be changed, including the model provider (i.e. openai > xai), default model id, apikey and whatever options are supported by the underlying provider.
@kzu kzu added the enhancement New feature or request label Oct 13, 2025
@kzu
Copy link
Member Author

kzu commented Oct 13, 2025

7 passed 7 passed 17 skipped

🧪 Details on Ubuntu 24.04.3 LTS

from dotnet-retest v1.0.0 on .NET 9.0.9 with 💜 by @devlooped

@kzu kzu merged commit f6c68da into main Oct 13, 2025
7 checks passed
@kzu kzu deleted the dev/configurable branch October 13, 2025 19:47
@devlooped devlooped locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants