[New article]: Add how-to that shows how to switch model providers with Microsoft.Extensions.AI
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
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
https://devblogs.microsoft.com/dotnet/ai-vector-data-dotnet-extensions-ga/#portability-across-model-and-vector-store-providers
Expand on this article, specifically these sections.
```csharp
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> 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
Contributor guide
Assessment
This issue has not been assessed yet.