@@ -14,19 +14,30 @@ public static IKernelBuilder AddDashScopeChatCompletion(
1414 Action < DashScopeClientOptions > ? configureOptions = null ,
1515 Action < HttpClient > ? configureClient = null ,
1616 string configSectionPath = "dashscope" )
17+ {
18+ builder . Services . AddDashScopeChatCompletion ( serviceId , configureOptions , configureClient , configSectionPath ) ;
19+ return builder ;
20+ }
21+
22+ public static IServiceCollection AddDashScopeChatCompletion (
23+ this IServiceCollection services ,
24+ string ? serviceId = null ,
25+ Action < DashScopeClientOptions > ? configureOptions = null ,
26+ Action < HttpClient > ? configureClient = null ,
27+ string configSectionPath = "dashscope" )
1728 {
1829 Func < IServiceProvider , object ? , DashScopeChatCompletionService > factory = ( serviceProvider , _ ) =>
1930 serviceProvider . GetRequiredService < DashScopeChatCompletionService > ( ) ;
2031
21- var optionsBuilder = builder . Services . AddOptions < DashScopeClientOptions > ( ) . BindConfiguration ( configSectionPath ) ;
32+ var optionsBuilder = services . AddOptions < DashScopeClientOptions > ( ) . BindConfiguration ( configSectionPath ) ;
2233 if ( configureOptions != null ) optionsBuilder . PostConfigure ( configureOptions ) ;
2334
2435 var httpClientBuilder = configureClient == null
25- ? builder . Services . AddHttpClient < DashScopeChatCompletionService > ( )
26- : builder . Services . AddHttpClient < DashScopeChatCompletionService > ( configureClient ) ;
36+ ? services . AddHttpClient < DashScopeChatCompletionService > ( )
37+ : services . AddHttpClient < DashScopeChatCompletionService > ( configureClient ) ;
2738
28- builder . Services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
29- return builder ;
39+ services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
40+ return services ;
3041 }
3142
3243 public static IKernelBuilder AddDashScopeChatCompletion < T > (
@@ -38,7 +49,20 @@ public static IKernelBuilder AddDashScopeChatCompletion<T>(
3849 Action < HttpClient > ? configureClient = null ,
3950 string configSectionPath = "dashscope" ) where T : class
4051 {
41- builder . Services . AddConfiguration < T > ( ) ;
52+ builder . Services . AddDashScopeChatCompletion < T > ( modelId , apiKey , serviceId , configureOptions , configureClient ) ;
53+ return builder ;
54+ }
55+
56+ public static IServiceCollection AddDashScopeChatCompletion < T > (
57+ this IServiceCollection services ,
58+ string ? modelId = null ,
59+ string ? apiKey = null ,
60+ string ? serviceId = null ,
61+ Action < DashScopeClientOptions > ? configureOptions = null ,
62+ Action < HttpClient > ? configureClient = null ,
63+ string configSectionPath = "dashscope" ) where T : class
64+ {
65+ services . AddConfiguration < T > ( ) ;
4266
4367 void AggConfigureOptions ( DashScopeClientOptions options )
4468 {
@@ -47,7 +71,7 @@ void AggConfigureOptions(DashScopeClientOptions options)
4771 configureOptions ? . Invoke ( options ) ;
4872 }
4973
50- return builder . AddDashScopeChatCompletion ( serviceId , AggConfigureOptions , configureClient , configSectionPath ) ;
74+ return services . AddDashScopeChatCompletion ( serviceId , AggConfigureOptions , configureClient , configSectionPath ) ;
5175 }
5276
5377 public static IKernelBuilder AddDashScopeChatCompletion (
@@ -56,6 +80,17 @@ public static IKernelBuilder AddDashScopeChatCompletion(
5680 string apiKey ,
5781 string ? serviceId = null ,
5882 Action < HttpClient > ? configureClient = null )
83+ {
84+ builder . Services . AddDashScopeChatCompletion ( modelId , apiKey , serviceId , configureClient ) ;
85+ return builder ;
86+ }
87+
88+ public static IServiceCollection AddDashScopeChatCompletion (
89+ this IServiceCollection services ,
90+ string modelId ,
91+ string apiKey ,
92+ string ? serviceId = null ,
93+ Action < HttpClient > ? configureClient = null )
5994 {
6095 Func < IServiceProvider , object ? , DashScopeChatCompletionService > factory = ( serviceProvider , _ ) =>
6196 {
@@ -65,9 +100,9 @@ public static IKernelBuilder AddDashScopeChatCompletion(
65100 return new DashScopeChatCompletionService ( options , httpClient ) ;
66101 } ;
67102
68- builder . Services . AddHttpClient ( ) ;
69- builder . Services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
70- return builder ;
103+ services . AddHttpClient ( ) ;
104+ services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
105+ return services ;
71106 }
72107
73108 private static IServiceCollection AddConfiguration < T > ( this IServiceCollection services ) where T : class
0 commit comments