8000 test: add workflow application tests · cnblogs/dashscope-sdk@dd5c316 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd5c316

Browse files
committed
test: add workflow application tests
1 parent 7287c7d commit dd5c316

11 files changed

+107
-19
lines changed

src/Cnblogs.DashScope.Core/ApplicationInput.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
/// <summary>
44
/// Inputs for application call.
55
/// </summary>
6-
/// <typeparam name="TBizContent">Type of the BizContent.</typeparam>
7-
public class ApplicationInput<TBizContent>
8-
where TBizContent : class
6+
/// <typeparam name="TBizParams">Type of the BizContent.</typeparam>
7+
public class ApplicationInput<TBizParams>
8+
where TBizParams : class
99
{
1010
/// <summary>
1111
/// The prompt for model to generate response upon. Optional when <see cref="Messages"/> has been set.
1212
/// </summary>
1313
/// <remarks>
1414
/// Prompt will be appended to <see cref="Messages"/> when both set.
1515
/// </remarks>
16-
public string? Prompt { get; set; } = null;
16+
public string? Prompt { get; set; }
1717

1818
/// <summary>
1919
/// The session id for conversation history. This will be ignored if <see cref="Messages"/> has been set.
2020
/// </summary>
21-
public string? SessionId { get; set; } = null;
21+
public string? SessionId { get; set; }
2222

2323
/// <summary>
2424
/// The conversation history.
2525
/// </summary>
26-
public IEnumerable<ApplicationMessage>? Messages { get; set; } = null;
26+
public IEnumerable<ApplicationMessage>? Messages { get; set; }
2727

2828
/// <summary>
2929
/// The id of memory when enabled.
3030
/// </summary>
31-
public string? MemoryId { get; set; } = null;
31+
public string? MemoryId { get; set; }
3232

3333
/// <summary>
3434
/// List of image urls for inputs.
@@ -38,7 +38,7 @@ public class ApplicationInput<TBizContent>
3838
/// <summary>
3939
/// User defined content.
4040
/// </summary>
41-
public TBizContent? Content { get; set; } = null;
41+
public TBizParams? BizParams { get; set; } = null;
4242
}
4343

4444
/// <summary>

src/Cnblogs.DashScope.Core/ApplicationRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
/// <summary>
44
/// Request body for an application all.
55
/// </summary>
6-
/// <typeparam name="TBizContent">Type of the biz_content</typeparam>
7-
public class ApplicationRequest<TBizContent>
8-
where TBizContent : class
6+
/// <typeparam name="TBizParams">Type of the biz_content</typeparam>
7+
public class ApplicationRequest<TBizParams>
8+
where TBizParams : class
99
{
1010
/// <summary>
1111
/// Content of this call.
1212
/// </summary>
13-
public required ApplicationInput<TBizContent> Input { get; init; }
13+
public required ApplicationInput<TBizParams> Input { get; init; }
1414

1515
/// <summary>
1616
/// Optional configurations.

src/Cnblogs.DashScope.Core/ApplicationUsage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/// <summary>
44
/// Total token usages of this application call.
55
/// </summary>
6-
/// <param name="Models">All models been used and their token usages.</param>
7-
public record ApplicationUsage(List<ApplicationModelUsage> Models);
6+
/// <param name="Models">All models been used and their token usages. Can be null when workflow application without using any model.</param>
7+
public record ApplicationUsage(List<ApplicationModelUsage>? Models);

src/Cnblogs.DashScope.Core/IDashScopeClient.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Cnblogs.DashScope.Core;
1+
using System.Text.Json;
2+
3+
namespace Cnblogs.DashScope.Core;
24

35
/// <summary>
46
/// DashScope APIs.
@@ -28,13 +30,13 @@ Task<ApplicationResponse> GetApplicationResponseAsync(
2830
/// <param name="applicationId">Name of the application.</param>
2931
/// <param name="input">The request body.</param>
3032
/// <param name="cancellationToken">The cancellation token to use.</param>
31-
/// <typeparam name="TBizContent">Type of the biz_content.</typeparam>
33+
/// <typeparam name="TBizParams">Type of the biz_content.</typeparam>
3234
/// <returns></returns>
33-
Task<ApplicationResponse> GetApplicationResponseAsync<TBizContent>(
35+
Task<ApplicationResponse> GetApplicationResponseAsync<TBizParams>(
3436
string applicationId,
35-
ApplicationRequest<TBizContent> input,
37+
ApplicationRequest<TBizParams> input,
3638
CancellationToken cancellationToken = default)
37-
where TBizContent : class;
39+
where TBizParams : class;
3840

3941
/// <summary>
4042
/// Make a call to custom application.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,22 @@ public async Task SingleCompletion_MemoryNoSse_SuccessAsync()
118118
Arg.Any<CancellationToken>());
119119
response.Should().BeEquivalentTo(testCase.ResponseModel);
120120
}
121+
122+
[Fact]
123+
public async Task SingleCompletion_WorkflowNoSse_SuccessAsync()
124+
{
125+
// Arrange
126+
const bool sse = false;
127+
var testCase = Snapshots.Application.WorkflowNoSse;
128+
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
129+
130+
// Act
131+
var response = await client.GetApplicationResponseAsync("anyId", testCase.RequestModel);
132+
133+
// Assert
134+
handler.Received().MockSend(
135+
Arg.Is<HttpRequestMessage>(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))),
136+
Arg.Any<CancellationToken>());
137+
response.Should().BeEquivalentTo(testCase.ResponseModel);
138+
}
121139
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"input": {
3+
"prompt": "请你跟我这样说",
4+
"biz_params": {
5+
"sourceCode": "code"
6+
}
7+
},
8+
"parameters": {
9+
"top_k": 100,
10+
"top_p": 0.8,
11+
"seed": 1234,
12+
"temperature": 0.85
13+
}
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/apps/debbb624ccfd4ebdac605edc27f94f7a/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: 268
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"output":{"finish_reason":"stop","session_id":"5a20b47dac2f43a7b1cbb8924ca66c47","text":"code"},"usage":{},"request_id":"10990f51-e2d0-9338-9c52-319af5f4858b"}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
HTTP/1.1 200 OK
2+
vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding
3+
content-type: application/json
4+
x-request-id: 10990f51-e2d0-9338-9c52-319af5f4858b
5+
x-dashscope-timeout: 180
6+
x-dashscope-call-gateway: true
7+
x-dashscope-finished: true
8+
req-cost-time: 414
9+
req-arrive-time: 1742133858888
10+
resp-start-time: 1742133859303
11+
x-envoy-upstream-service-time: 406
12+
content-encoding: gzip
13+
date: Sun, 16 Mar 2025 14:04:18 GMT
14+
server: istio-envoy
15+
transfer-encoding: chunked

test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Application.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,29 @@ public static class Application
250250
null),
251251
new ApplicationUsage([new ApplicationModelUsage("qwen-plus", 1201, 43)])));
252252

253+
public static readonly RequestSnapshot<ApplicationRequest<TestApplicationBizParam>, ApplicationResponse>
254+
WorkflowNoSse =
255+
new(
256+
"application-workflow",
257+
new ApplicationRequest<TestApplicationBizParam>()
258+
{
259+
Input = new ApplicationInput<TestApplicationBizParam>()
260+
{
261+
BizParams = new TestApplicationBizParam("code"), Prompt = "请你跟我这样说"
262+
},
263+
Parameters = new ApplicationParameters()
264+
{
265+
TopK = 100,
266+
TopP = 0.8f,
267+
Seed = 1234,
268+
Temperature = 0.85f,
269+
}
270+
},
271+
new ApplicationResponse(
272+
"10990f51-e2d0-9338-9c52-319af5f4858b",
273+
new ApplicationOutput("code", "stop", "5a20b47dac2f43a7b1cbb8924ca66c47", null, null),
274+
new ApplicationUsage(null)));
275+
253276
public static readonly RequestSnapshot<ApplicationRequest, ApplicationResponse> ConversationSessionIdNoSse =
254277
new(
255278
"application-conversation-generation-session-id",

0 commit comments

Comments
 (0)
0