-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDeepSeekTextGenerationApiTests.cs
74 lines (61 loc) · 2.6 KB
/
DeepSeekTextGenerationApiTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Cnblogs.DashScope.Core;
using Cnblogs.DashScope.Sdk.DeepSeek;
using NSubstitute;
namespace Cnblogs.DashScope.Sdk.UnitTests;
public class DeepSeekTextGenerationApiTests
{
[Fact]
public async Task TextCompletion_UseEnum_SuccessAsync()
{
// Arrange
var client = Substitute.For<IDashScopeClient>();
// Act
await client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSeekR1, [TextChatMessage.User("你好")]);
// Assert
await client.Received().GetTextCompletionAsync(
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
x => x.Model == "deepseek-r1" && x.Input.Messages!.First().Content == "你好" && x.Parameters == null));
}
[Fact]
public async Task TextCompletion_UseCustomModel_SuccessAsync()
{
// Arrange
const string customModel = "deepseek-v3";
var client = Substitute.For<IDashScopeClient>();
// Act
await client.GetDeepSeekChatCompletionAsync(customModel, [TextChatMessage.User("你好")]);
// Assert
await client.Received().GetTextCompletionAsync(
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
x => x.Model == customModel && x.Input.Messages!.First().Content == "你好" && x.Parameters == null));
}
[Fact]
public void StreamCompletion_UseEnum_SuccessAsync()
{
// Arrange
var client = Substitute.For<IDashScopeClient>();
// Act
_ = client.GetDeepSeekChatCompletionStreamAsync(DeepSeekLlm.DeepSeekV3, [TextChatMessage.User("你好")]);
// Assert
_ = client.Received().GetTextCompletionStreamAsync(
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
x => x.Model == "deepseek-v3"
&& x.Input.Messages!.First().Content == "你好"
&& x.Parameters!.IncrementalOutput == true));
}
[Fact]
public void StreamCompletion_CustomModel_SuccessAsync()
{
// Arrange
const string customModel = "deepseek-v3";
var client = Substitute.For<IDashScopeClient>();
// Act
_ = client.GetDeepSeekChatCompletionStreamAsync(customModel, [TextChatMessage.User("你好")]);
// Assert
_ = client.Received().GetTextCompletionStreamAsync(
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
x => x.Model == customModel
&& x.Input.Messages!.First().Content == "你好"
&& x.Parameters!.IncrementalOutput == true));
}
}