1+ using Anthropic ;
12using Microsoft . Extensions . AI ;
23using Microsoft . Extensions . Configuration ;
34using OllamaSharp ;
@@ -20,12 +21,14 @@ internal sealed class ChatClientFactory : IChatClientFactory
2021 {
2122 private readonly IHttpClientFactory _httpClientFactory ;
2223 private readonly IConfiguration _configuration ;
24+ private readonly IAnthropicClient _anthropicClient ;
2325
24- public ChatClientFactory ( IHttpClientFactory httpClientFactory , IConfiguration configuration )
26+ public ChatClientFactory ( IHttpClientFactory httpClientFactory , IAnthropicClient anthropicClient , IConfiguration configuration )
2527 {
2628 _httpClientFactory = httpClientFactory ;
2729 _configuration = configuration ;
28- }
30+ _anthropicClient = anthropicClient ;
31+ }
2932
3033 public IChatClient CreateClient ( string urn )
3134 {
@@ -47,7 +50,11 @@ public IChatClient CreateClient(string urn)
4750 httpClient . BaseAddress = new Uri ( _configuration [ "OLLAMA_HOST" ] ) ;
4851 return new OllamaApiClient ( httpClient , model ) ;
4952 }
50- default :
53+ case "anthropic" :
54+ {
55+ return _anthropicClient . AsIChatClient ( model ) ;
56+ }
57+ default :
5158 throw new NotSupportedException ( $ "Provider '{ provider } ' is not supported.") ;
5259 }
5360 }
@@ -72,6 +79,11 @@ public async Task<IList<string>> GetModels(string urn, CancellationToken token)
7279 using var client = new OllamaApiClient ( httpClient ) ;
7380 var ollamaModels = await client . ListLocalModelsAsync ( token ) ;
7481 return [ .. ollamaModels . Select ( x => x . Name ) ] ;
82+ }
83+ case "anthropic" :
84+ {
85+ var models = await _anthropicClient . Models . List ( null , token ) ;
86+ return [ .. models . Items . Select ( x => x . ID ) ] ;
7587 }
7688 default :
7789 throw new NotSupportedException ( $ "Provider '{ provider } ' is not supported.") ;
0 commit comments