@@ -118,6 +118,67 @@ public async Task AddOllamaApiClientEmbeddingGeneratorFromServiceCollectionAsync
118
118
Assert . Equal ( 1 , myHttpClientHandler . InvokedCount ) ;
119
119
}
120
120
121
+ [ Theory ]
122
+ [ Obsolete ( "Temporarily test for obsolete TextEmbeddingGenerationService." ) ]
123
+ [ MemberData ( nameof ( AddOllamaApiClientScenarios ) ) ]
124
+ public void AddOllamaTextEmbeddingGenerationShouldGetRequiredServiceFromKernel ( ServiceCollectionRegistration registration )
125
+ {
126
+ using var httpClient = new HttpClient ( ) { BaseAddress = new Uri ( "http://localhost:11434" ) , } ;
127
+ using var client = new OllamaApiClient ( httpClient ) ;
128
+ var builder = Kernel . CreateBuilder ( ) ;
129
+ string ? serviceId = null ;
130
+
131
+ switch ( registration )
132
+ {
133
+ case ServiceCollectionRegistration . KeyedOllamaApiClient :
134
+ builder . AddOllamaTextEmbeddingGeneration ( serviceId : serviceId = "model" , ollamaClient : client ) ;
135
+ break ;
136
+ case ServiceCollectionRegistration . OllamaApiClient :
137
+ builder . AddOllamaTextEmbeddingGeneration ( ollamaClient : client ) ;
138
+ break ;
139
+ case ServiceCollectionRegistration . Endpoint :
140
+ builder . AddOllamaTextEmbeddingGeneration ( "model" , httpClient . BaseAddress ) ;
141
+ break ;
142
+ case ServiceCollectionRegistration . KeyedIOllamaApiClient :
143
+ return ; // IOllamaApiClient is not supported for KernelBuilder extensions, skipping
144
+ }
145
+
146
+ var kernel = builder . Build ( ) ;
147
+
148
+ ITextEmbeddingGenerationService service = kernel . GetRequiredService < ITextEmbeddingGenerationService > ( serviceId ) ;
149
+ Assert . NotNull ( service ) ;
150
+ }
151
+
152
+ [ Theory ]
153
+ [ MemberData ( nameof ( AddOllamaApiClientScenarios ) ) ]
154
+ public void AddOllamaEmbeddingGeneratorShouldGetRequiredServiceFromKernel ( ServiceCollectionRegistration registration )
155
+ {
156
+ using var httpClient = new HttpClient ( ) { BaseAddress = new Uri ( "http://localhost:11434" ) , } ;
157
+ using var client = new OllamaApiClient ( httpClient ) ;
158
+ var builder = Kernel . CreateBuilder ( ) ;
159
+ string ? serviceId = null ;
160
+
161
+ switch ( registration )
162
+ {
163
+ case ServiceCollectionRegistration . KeyedOllamaApiClient :
164
+ builder . AddOllamaEmbeddingGenerator ( serviceId : serviceId = "model" , ollamaClient : client ) ;
165
+ break ;
166
+ case ServiceCollectionRegistration . OllamaApiClient :
167
+ builder . AddOllamaEmbeddingGenerator ( ollamaClient : client ) ;
168
+ break ;
169
+ case ServiceCollectionRegistration . Endpoint :
170
+ builder . AddOllamaEmbeddingGenerator ( "model" , httpClient . BaseAddress ) ;
171
+ break ;
172
+ case ServiceCollectionRegistration . KeyedIOllamaApiClient :
173
+ return ; // IOllamaApiClient is not supported for KernelBuilder extensions, skipping
174
+ }
175
+
176
+ var kernel = builder . Build ( ) ;
177
+
178
+ var service = kernel . GetRequiredService < IEmbeddingGenerator < string , Embedding < float > > > ( serviceId ) ;
179
+ Assert . NotNull ( service ) ;
180
+ }
181
+
121
182
[ Theory ]
122
183
[ MemberData ( nameof ( AddOllamaApiClientScenarios ) ) ]
123
184
[ Obsolete ( "Temporarily test for obsolete TextEmbeddingGenerationService." ) ]
0 commit comments