Skip to content

Commit 0ff8223

Browse files
committed
feat: add single prompt sse tests
1 parent 1e23e96 commit 0ff8223

18 files changed

+2345
-1757
lines changed

src/Cnblogs.DashScope.Core/ApplicationOutputThought.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// <param name="ActionInputStream">The streaming result of action input.</param>
1111
/// <param name="ActionInput">The input of the action.</param>
1212
/// <param name="Observation">Lookup or plugin output.</param>
13-
/// <param name="ReasoningContent">Reasoning output when using DeepSeek-R1.</param>
13+
/// <param name="Response">Reasoning output when using DeepSeek-R1.</param>
1414
/// <param name="Arguments">Arguments of the action.</param>
1515
public record ApplicationOutputThought(
1616
string? Thought,
@@ -20,5 +20,5 @@ public record ApplicationOutputThought(
2020
string? ActionInputStream,
2121
string? ActionInput,
2222
string? Observation,
23-
string? ReasoningContent,
23+
string? Response,
2424
string? Arguments);

src/Cnblogs.DashScope.Core/ApplicationResponse.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
/// Response of application call.
55
/// </summary>
66
/// <param name="RequestId">Unique id of this request.</param>
7-
/// <param name="Code">Error code. Null when request is successful.</param>
8-
/// <param name="Message">Error message. Null when request is successful.</param>
97
/// <param name="Output">The output of application call.</param>
108
/// <param name="Usage">Token usage of this application call.</param>
119
public record ApplicationResponse(
1210
string RequestId,
13-
string? Code,
14-
string? Message,
1511
ApplicationOutput Output,
1612
ApplicationUsage Usage);

test/Cnblogs.DashScope.Sdk.UnitTests/ApplicationSerializationTests.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public async Task SingleCompletion_TextNoSse_SuccessAsync()
1111
{
1212
// Arrange
1313
const bool sse = false;
14-
var testCase = Snapshots.Application.SinglePrompt;
14+
var testCase = Snapshots.Application.SinglePromptNoSse;
1515
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
1616

1717
// Act
@@ -23,4 +23,45 @@ public async Task SingleCompletion_TextNoSse_SuccessAsync()
2323
Arg.Any<CancellationToken>());
2424
response.Should().BeEquivalentTo(testCase.ResponseModel);
2525
}
26+
27+
[Fact]
28+
public async Task SingleCompletion_ThoughtNoSse_SuccessAsync()
29+
{
30+
// Arrange
31+
const bool sse = false;
32+
var testCase = Snapshots.Application.SinglePromptWithThoughtsNoSse;
33+
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
34+
35+
// Act
36+
var response = await client.GetApplicationResponseAsync("anyId", testCase.RequestModel);
37+
38+
// Assert
39+
handler.Received().MockSend(
40+
Arg.Is<HttpRequestMessage>(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))),
41+
Arg.Any<CancellationToken>());
42+
response.Should().BeEquivalentTo(testCase.ResponseModel);
43+
}
44+
45+
[Fact]
46+
public async Task SingleCompletion_TextSse_SuccessAsync()
47+
{
48+
// Arrange
49+
const bool sse = true;
50+
var testCase = Snapshots.Application.SinglePromptSse;
51+
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
52+
53+
// Act
54+
var outputs = await client.GetApplicationResponseStreamAsync("anyId", testCase.RequestModel).ToListAsync();
55+
var text = string.Join(string.Empty, outputs.Select(o => o.Output.Text));
56+
57+
// Assert
58+
handler.Received().MockSend(
59+
Arg.Is<HttpRequestMessage>(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))),
60+
Arg.Any<CancellationToken>());
61+
outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.FinishReason.Should().Be("null"));
62+
outputs.Last().Should().BeEquivalentTo(
63+
testCase.ResponseModel,
64+
o => o.Excluding(y => y.Output.Text).Excluding(x => x.Output.Thoughts));
65+
text.Should().Be(testCase.ResponseModel.Output.Text);
66+
}
2667
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"input": {
3+
"prompt": "总结xUnit Test Patterns中的内容"
4+
},
5+
"parameters": {
6+
"incremental_output": true,
7+
"top_k": 100,
8+
"top_p": 0.8,
9+
"seed": 1234,
10+
"temperature": 0.85,
11+
"rag_options": {
12+
"pipeline_ids": ["thie5bysoj"],
13+
"tags": ["xUnit"]
14+
}
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/apps/010aa085cc9943268731861c9511bb0c/completion HTTP/1.1
2+
Accept: text/event-stream
3+
Content-Type: application/json
4+
Cache-Control: no-cache
5+
Host: dashscope.aliyuncs.com
6+
Accept-Encoding: gzip, deflate, br
7+
Connection: keep-alive
8+
Content-Length: 364

test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.response.body.txt

Lines changed: 325 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
HTTP/1.1 200 OK
2+
vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers
3+
x-request-id: fec856c6-c146-99bc-940c-fd6c36939a16
4+
content-type: text/event-stream;charset=UTF-8
5+
x-dashscope-call-gateway: true
6+
x-dashscope-timeout: 180
7+
x-dashscope-finished: false
8+
req-cost-time: 1755
9+
req-arrive-time: 1742113457368
10+
resp-start-time: 1742113459124
11+
x-envoy-upstream-service-time: 1744
12+
date: Sun, 16 Mar 2025 08:24:18 GMT
13+
server: istio-envoy
14+
transfer-encoding: chunked
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"input": {
3+
"prompt": "总结xUnit Test Patterns中的内容"
4+
},
5+
"parameters": {
6+
"has_thoughts": true,
7+
"top_k": 100,
8+
"top_p": 0.8,
9+
"seed": 1234,
10+
"temperature": 0.85,
11+
"rag_options": {
12+
"pipeline_ids": ["thie5bysoj"],
13+
"file_ids": ["file_d129d632800c45aa9e7421b30561f447_10207234"]
14+
}
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/apps/010aa085cc9943268731861c9511bb0c/completion HTTP/1.1
2+
Content-Type: application/json
3+
Accept: */*
4+
Cache-Control: no-cache
5+
Host: dashscope.aliyuncs.com
6+
Accept-Encoding: gzip, deflate, br
7+
Connection: keep-alive
8+
Content-Length: 403

0 commit comments

Comments
 (0)