11using System . Diagnostics ;
22using System . Text ;
3- using Microsoft . Extensions . Configuration ;
4- using Microsoft . Extensions . DependencyInjection ;
53using Microsoft . SemanticKernel ;
64
75namespace SemanticKernel . DashScope . IntegrationTest ;
@@ -13,8 +11,7 @@ public async Task ChatCompletion_InvokePromptAsync_WorksCorrectly()
1311 {
1412 // Arrange
1513 var builder = Kernel . CreateBuilder ( ) ;
16- builder . Services . AddSingleton ( GetConfiguration ( ) ) ;
17- builder . AddDashScopeChatCompletion ( ) ;
14+ builder . AddDashScopeChatCompletion < DashScopeChatCompletionTests > ( ) ;
1815 var kernel = builder . Build ( ) ;
1916
2017 var prompt = @"<message role=""user"">博客园是什么网站</message>" ;
@@ -40,8 +37,7 @@ public async Task ChatCompletion_InvokePromptStreamingAsync_WorksCorrectly()
4037 {
4138 // Arrange
4239 var builder = Kernel . CreateBuilder ( ) ;
43- builder . Services . AddSingleton ( GetConfiguration ( ) ) ;
44- builder . AddDashScopeChatCompletion ( ) ;
40+ builder . AddDashScopeChatCompletion < DashScopeChatCompletionTests > ( ) ;
4541 var kernel = builder . Build ( ) ;
4642
4743 // Act
@@ -52,18 +48,9 @@ public async Task ChatCompletion_InvokePromptStreamingAsync_WorksCorrectly()
5248 var sb = new StringBuilder ( ) ;
5349 await foreach ( var message in result )
5450 {
55- Trace . WriteLine ( message ) ;
51+ Trace . Write ( message ) ;
5652 sb . Append ( message ) ;
5753 }
5854 Assert . Contains ( "博客园" , sb . ToString ( ) ) ;
5955 }
60-
61- private static IConfiguration GetConfiguration ( )
62- {
63- return new ConfigurationBuilder ( )
64- . SetBasePath ( Directory . GetCurrentDirectory ( ) )
65- . AddJsonFile ( "appsettings.json" )
66- . AddUserSecrets < DashScopeChatCompletionTests > ( )
67- . Build ( ) ;
68- }
6956}
0 commit comments