-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Labels
Description
Proposed topic or title
How to switch model providers with Microsoft.Extensions.AI
Location in table of contents.
https://github.com/dotnet/docs/tree/main/docs/ai/how-to
Reason for the article
Existing articles assume you're working with a single provider. However, there are scenarios where you might want or need to use different providers.
Scenarios:
- Local testing vs Production deployment
- Smart routing (choosing a different provider based on query complexity)
- Evaluations (batch testing prompts using different model providers)
Article abstract
Expand on this article, specifically these sections.
IChatClient chatClient =
environment == "Development"
? new OllamaApiClient("YOUR-OLLAMA-ENDPOINT", "qwen3")
: new AzureOpenAIClient("YOUR-AZURE-OPENAI-ENDPOINT", new DefaultAzureCredential())
.GetChatClient("gpt-4.1")
.AsIChatClient();
await foreach (var message in chatClient.GetStreamingResponseAsync("What is AI?"))
{
Console.Write($"{message.Text}");
};
IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator =
environment == "Development"
? new OllamaApiClient("YOUR-OLLAMA-ENDPOINT", "all-minilm")
: new AzureOpenAIClient("YOUR-AZURE-OPENAI-ENDPOINT", new DefaultAzureCredential())
.GetEmbeddingClient("text-embedding-3-small")
.AsIEmbeddingGenerator();
var embedding = await embeddingGenerator.GenerateAsync("What is AI?");
Relevant searches
- How to use multiple model providers with Microsoft.Extensions.AI
- Working with local and hosted models with Microsoft.Extensions.AI
- Switch model providers with Microsoft.Extensions.AI
Copilot