1
1
using System . Diagnostics ;
2
2
using System . Text ;
3
- using Microsoft . Extensions . Configuration ;
4
- using Microsoft . Extensions . DependencyInjection ;
5
3
using Microsoft . SemanticKernel ;
6
4
7
5
namespace SemanticKernel . DashScope . IntegrationTest ;
@@ -13,8 +11,7 @@ public async Task ChatCompletion_InvokePromptAsync_WorksCorrectly()
13
11
{
14
12
// Arrange
15
13
var builder = Kernel . CreateBuilder ( ) ;
16
- builder . Services . AddSingleton ( GetConfiguration ( ) ) ;
17
- builder . AddDashScopeChatCompletion ( ) ;
14
+ builder . AddDashScopeChatCompletion < DashScopeChatCompletionTests > ( ) ;
18
15
var kernel = builder . Build ( ) ;
19
16
20
17
var prompt = @"<message role=""user"">博客园是什么网站</message>" ;
@@ -40,8 +37,7 @@ public async Task ChatCompletion_InvokePromptStreamingAsync_WorksCorrectly()
40
37
{
41
38
// Arrange
42
39
var builder = Kernel . CreateBuilder ( ) ;
43
- builder . Services . AddSingleton ( GetConfiguration ( ) ) ;
44
- builder . AddDashScopeChatCompletion ( ) ;
40
+ builder . AddDashScopeChatCompletion < DashScopeChatCompletionTests > ( ) ;
45
41
var kernel = builder . Build ( ) ;
46
42
47
43
// Act
@@ -52,18 +48,9 @@ public async Task ChatCompletion_InvokePromptStreamingAsync_WorksCorrectly()
52
48
var sb = new StringBuilder ( ) ;
53
49
await foreach ( var message in result )
54
50
{
55
- Trace . WriteLine ( message ) ;
51
+ Trace . Write ( message ) ;
56
52
sb . Append ( message ) ;
57
53
}
58
54
Assert . Contains ( "博客园" , sb . ToString ( ) ) ;
59
55
}
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
- }
69
56
}
0 commit comments