@@ -14,19 +14,30 @@ public static IKernelBuilder AddDashScopeChatCompletion(
14
14
Action < DashScopeClientOptions > ? configureOptions = null ,
15
15
Action < HttpClient > ? configureClient = null ,
16
16
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" )
17
28
{
18
29
Func < IServiceProvider , object ? , DashScopeChatCompletionService > factory = ( serviceProvider , _ ) =>
19
30
serviceProvider . GetRequiredService < DashScopeChatCompletionService > ( ) ;
20
31
21
- var optionsBuilder = builder . Services . AddOptions < DashScopeClientOptions > ( ) . BindConfiguration ( configSectionPath ) ;
32
+ var optionsBuilder = services . AddOptions < DashScopeClientOptions > ( ) . BindConfiguration ( configSectionPath ) ;
22
33
if ( configureOptions != null ) optionsBuilder . PostConfigure ( configureOptions ) ;
23
34
24
35
var httpClientBuilder = configureClient == null
25
- ? builder . Services . AddHttpClient < DashScopeChatCompletionService > ( )
26
- : builder . Services . AddHttpClient < DashScopeChatCompletionService > ( configureClient ) ;
36
+ ? services . AddHttpClient < DashScopeChatCompletionService > ( )
37
+ : services . AddHttpClient < DashScopeChatCompletionService > ( configureClient ) ;
27
38
28
- builder . Services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
29
- return builder ;
39
+ services . AddKeyedSingleton < IChatCompletionService > ( serviceId , factory ) ;
40
+ return services ;
30
41
}
31
42
32
43
public static IKernelBuilder AddDashScopeChatCompletion < T > (
@@ -38,7 +49,20 @@ public static IKernelBuilder AddDashScopeChatCompletion<T>(
38
49
Action < HttpClient > ? configureClient = null ,
39
50
string configSectionPath = "dashscope" ) where T : class
40
51
{
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 > ( ) ;
42
66
43
67
void AggConfigureOptions ( DashScopeClientOptions options )
44
68
{
@@ -47,7 +71,7 @@ void AggConfigureOptions(DashScopeClientOptions options)
47
71
configureOptions ? . Invoke ( options ) ;
48
72
}
49
73
50
- return builder . AddDashScopeChatCompletion ( serviceId , AggConfigureOptions , configureClient , configSectionPath ) ;
74
+ return services . AddDashScopeChatCompletion ( serviceId , AggConfigureOptions , configureClient , configSectionPath ) ;
51
75
}
52
76
53
77
public static IKernelBuilder AddDashScopeChatCompletion (
@@ -56,6 +80,17 @@ public static IKernelBuilder AddDashScopeChatCompletion(
56
80
string apiKey ,
57
81
string ? serviceId = null ,
58
82
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 )
59
94
{
60
95
Func < IServiceProvider , object ? , DashScopeChatCompletionService > factory = ( serviceProvider , _ ) =>
61
96
{
@@ -65,9 +100,9 @@ public static IKernelBuilder AddDashScopeChatCompletion(
65
100
return new DashScopeChatCompletionService ( options , httpClient ) ;
66
101
} ;
67
102
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 ;
71
106
}
72
107
73
108
private static IServiceCollection AddConfiguration < T > ( this IServiceCollection services ) where T : class
0 commit comments