Skip to content

Commit 3e76a7a

Browse files
committed
test: add message conversation test
1 parent 5e1e896 commit 3e76a7a

7 files changed

+138
-1
lines changed

src/Cnblogs.DashScope.Core/ApplicationRagOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ApplicationRagOptions
3030
/// <summary>
3131
/// Filter for structured files.
3232
/// </summary>
33-
public Dictionary<string, string>? StructuredFilter { get; set; }
33+
public Dictionary<string, object>? StructuredFilter { get; set; }
3434

3535
/// <summary>
3636
/// File ids for current session.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,22 @@ public async Task ConversationCompletion_SessionIdNoSse_SuccessAsync()
8282
Arg.Any<CancellationToken>());
8383
response.Should().BeEquivalentTo(testCase.ResponseModel);
8484
}
85+
86+
[Fact]
87+
public async Task ConversationCompletion_MessageNoSse_SuccessAsync()
88+
{
89+
// Arrange
90+
const bool sse = false;
91+
var testCase = Snapshots.Application.ConversationMessageNoSse;
92+
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
93+
94+
// Act
95+
var response = await client.GetApplicationResponseAsync("anyId", testCase.RequestModel);
96+
97+
// Assert
98+
handler.Received().MockSend(
99+
Arg.Is<HttpRequestMessage>(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))),
100+
Arg.Any<CancellationToken>());
101+
response.Should().BeEquivalentTo(testCase.ResponseModel);
102+
}
85103
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"input": {
3+
"messages": [
4+
{
5+
"role": "system",
6+
"content": "You are a helpful assistant."
7+
},
8+
{
9+
"role": "user",
10+
"content": "你是谁?"
11+
},
12+
{
13+
"role": "assistant",
14+
"content": "我是阿里云开发的大规模语言模型,我叫通义千问。"
15+
},
16+
{
17+
"role": "user",
18+
"content": "哪些人的主食偏好是米饭?"
19+
}
20+
]
21+
},
22+
"parameters": {
23+
"has_thoughts": true,
24+
"top_k": 100,
25+
"top_p": 0.8,
26+
"seed": 1234,
27+
"temperature": 0.85,
28+
"rag_options": {
29+
"pipeline_ids": ["e6md69132k"],
30+
"structured_filter": {
31+
"年龄": 14
32+
}
33+
}
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/apps/5ccc140108fd4b2ea5e6101fbada7583/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: 914
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"output":{"thoughts":[{"action_input_stream":"{}","action_type":"agentRag","observation":"[{\"content\":\"【文档名】:用户食物偏好\\n名字:小明\\n主食偏好:面食\\n年龄:14\\n\",\"dataId\":\"table_df4b06e8931545b4b0a65e011087c197_10207234_1\",\"dataName\":\"用户食物偏好\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_e6md69132k_table_df4b06e8931545b4b0a65e011087c197_10207234_1\",\"referenceIndex\":1,\"score\":0.2185690850019455,\"webSearch\":false}]","action_name":"知识检索","action":"rag","arguments":"{}"},{"action_input_stream":"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"哪些人的主食偏好是米饭?\"}","action_type":"api","observation":"[]","action_name":"长期记忆检索","action":"memory","arguments":"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"哪些人的主食偏好是米饭?\"}"}],"finish_reason":"stop","session_id":"9e2cf8c81f9a4fbe900a1f04b8522244","text":"米饭作为主食,深受许多国家和地区人们的喜爱。以下是一些以米饭为主食的群体:\n\n1. **中国人**:尤其在南方地区,米饭是大多数家庭的主要食物。从广东、福建到四川、云南,米饭搭配各种菜肴构成了日常饮食的重要部分。\n\n2. **日本人**:日本料理中,白米饭占据核心地位,无论是便当中的小碗饭还是寿司的基础,都体现了米饭在日本饮食文化中的重要性。\n\n3. **韩国人**:韩国家庭餐桌上的“石锅拌饭”、“紫菜包饭”等经典菜品,反映了米饭在韩国饮食习惯里的不可或缺。\n\n4. **东南亚各国居民**(如泰国、越南、菲律宾、印尼等):这些地区的传统美食几乎都离不开米饭,像泰国香米更是闻名全球,成为该国饮食文化的象征之一。\n\n5. **印度及南亚次大陆部分地区人群**:虽然面饼(Roti/Naan)也很受欢迎,但米饭特别是与咖喱一起食用时,同样是众多印度家庭及其他南亚国家(如孟加拉国、斯里兰卡等)的重要主食选择。\n\n6. **中东部分国家的人们**:尽管面包可能是更普遍的选择,但在一些特定场合或日常饮食中,例如搭配烤肉、炖菜时,米饭同样被广泛使用。\n\n总体而言,由于其易于种植、营养丰富且能够很好地与其他食材结合的特点,米饭成为了上述地区人们世代相传的主要食物来源之一。"},"usage":{"models":[{"output_tokens":311,"model_id":"qwen-plus","input_tokens":344}]},"request_id":"d42335b3-fcb2-9d11-b651-29562ac02abe"}
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: d42335b3-fcb2-9d11-b651-29562ac02abe
5+
x-dashscope-timeout: 180
6+
x-dashscope-call-gateway: true
7+
x-dashscope-finished: true
8+
req-cost-time: 8647
9+
req-arrive-time: 1742127970039
10+
resp-start-time: 1742127978686
11+
x-envoy-upstream-service-time: 8640
12+
content-encoding: gzip
13+
date: Sun, 16 Mar 2025 12:26:18 GMT
14+
server: istio-envoy
15+
transfer-encoding: chunked

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,65 @@ public static class Application
264264
],
265265
null),
266266
new ApplicationUsage([new ApplicationModelUsage("deepseek-r1", 1283, 1081)])));
267+
268+
public static readonly RequestSnapshot<ApplicationRequest, ApplicationResponse> ConversationMessageNoSse =
269+
new(
270+
"application-conversation-generation-message",
271+
new ApplicationRequest()
272+
{
273+
Input = new ApplicationInput()
274+
{
275+
Messages =
276+
[
277+
ApplicationMessage.System("You are a helpful assistant."),
278+
ApplicationMessage.User("你是谁?"),
279+
ApplicationMessage.Assistant("我是阿里云开发的大规模语言模型,我叫通义千问。"),
280+
ApplicationMessage.User("哪些人的主食偏好是米饭?"),
281+
],
282+
},
283+
Parameters = new ApplicationParameters()
284+
{
285+
TopK = 100,
286+
TopP = 0.8f,
287+
Seed = 1234,
288+
Temperature = 0.85f,
289+
RagOptions = new ApplicationRagOptions()
290+
{
291+
PipelineIds = ["e6md69132k"],
292+
StructuredFilter = new Dictionary<string, object> { { "年龄", 14 } }
293+
},
294+
HasThoughts = true
295+
}
296+
},
297+
new ApplicationResponse(
298+
"d42335b3-fcb2-9d11-b651-29562ac02abe",
299+
new ApplicationOutput(
300+
"米饭作为主食,深受许多国家和地区人们的喜爱。以下是一些以米饭为主食的群体:\n\n1. **中国人**:尤其在南方地区,米饭是大多数家庭的主要食物。从广东、福建到四川、云南,米饭搭配各种菜肴构成了日常饮食的重要部分。\n\n2. **日本人**:日本料理中,白米饭占据核心地位,无论是便当中的小碗饭还是寿司的基础,都体现了米饭在日本饮食文化中的重要性。\n\n3. **韩国人**:韩国家庭餐桌上的“石锅拌饭”、“紫菜包饭”等经典菜品,反映了米饭在韩国饮食习惯里的不可或缺。\n\n4. **东南亚各国居民**(如泰国、越南、菲律宾、印尼等):这些地区的传统美食几乎都离不开米饭,像泰国香米更是闻名全球,成为该国饮食文化的象征之一。\n\n5. **印度及南亚次大陆部分地区人群**:虽然面饼(Roti/Naan)也很受欢迎,但米饭特别是与咖喱一起食用时,同样是众多印度家庭及其他南亚国家(如孟加拉国、斯里兰卡等)的重要主食选择。\n\n6. **中东部分国家的人们**:尽管面包可能是更普遍的选择,但在一些特定场合或日常饮食中,例如搭配烤肉、炖菜时,米饭同样被广泛使用。\n\n总体而言,由于其易于种植、营养丰富且能够很好地与其他食材结合的特点,米饭成为了上述地区人们世代相传的主要食物来源之一。",
301+
"stop",
302+
"9e2cf8c81f9a4fbe900a1f04b8522244",
303+
[
304+
new ApplicationOutputThought(
305+
null,
306+
"agentRag",
307+
"知识检索",
308+
"rag",
309+
"{}",
310+
null,
311+
"[{\"content\":\"【文档名】:用户食物偏好\\n名字:小明\\n主食偏好:面食\\n年龄:14\\n\",\"dataId\":\"table_df4b06e8931545b4b0a65e011087c197_10207234_1\",\"dataName\":\"用户食物偏好\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_e6md69132k_table_df4b06e8931545b4b0a65e011087c197_10207234_1\",\"referenceIndex\":1,\"score\":0.2185690850019455,\"webSearch\":false}]",
312+
null,
313+
"{}"),
314+
new ApplicationOutputThought(
315+
null,
316+
"api",
317+
"长期记忆检索",
318+
"memory",
319+
"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"哪些人的主食偏好是米饭?\"}",
320+
null,
321+
"[]",
322+
null,
323+
"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"哪些人的主食偏好是米饭?\"}")
324+
],
325+
null),
326+
new ApplicationUsage([new ApplicationModelUsage("qwen-plus", 344, 311)])));
267327
}
268328
}

0 commit comments

Comments
 (0)