Skip to content

Commit 921927d

Browse files
committed
test: add memory id tests
1 parent 3e76a7a commit 921927d

6 files changed

+95
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,22 @@ public async Task ConversationCompletion_MessageNoSse_SuccessAsync()
100100
Arg.Any<CancellationToken>());
101101
response.Should().BeEquivalentTo(testCase.ResponseModel);
102102
}
103+
104+
[Fact]
105+
public async Task SingleCompletion_MemoryNoSse_SuccessAsync()
106+
{
107+
// Arrange
108+
const bool sse = false;
109+
var testCase = Snapshots.Application.SinglePromptWithMemoryNoSse;
110+
var (client, handler) = await Sut.GetTestClientAsync(sse, testCase);
111+
112+
// Act
113+
var response = await client.GetApplicationResponseAsync("anyId", testCase.RequestModel);
114+
115+
// Assert
116+
handler.Received().MockSend(
117+
Arg.Is<HttpRequestMessage>(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))),
118+
Arg.Any<CancellationToken>());
119+
response.Should().BeEquivalentTo(testCase.ResponseModel);
120+
}
103121
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"input": {
3+
"prompt": "我爱吃面食",
4+
"memory_id": "ffd8be2352d84c6b9350e91c865b512e"
5+
},
6+
"parameters": {
7+
"has_thoughts": true,
8+
"top_k": 100,
9+
"top_p": 0.8,
10+
"seed": 1234,
11+
"temperature": 0.85
12+
}
13+
}
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: 280
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":"[]","action_name":"知识检索","action":"rag","arguments":"{}"},{"action_input_stream":"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"我爱吃面食\"}","action_type":"api","observation":"[\"[2025-3-16 20:47:40 周日] 用户喜欢吃面食。\"]","action_name":"长期记忆检索","action":"memory","arguments":"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"我爱吃面食\"}"}],"finish_reason":"stop","session_id":"cd395cb8d4604db786a14555fdcffa1a","text":"那您一定会对面条、馒头或者饺子这些美食很感兴趣呢!如果您有特定的面食问题或者需要推荐相关的菜品,可以告诉我,我很乐意为您提供帮助<ref>[1]</ref>。"},"usage":{"models":[{"output_tokens":43,"model_id":"qwen-plus","input_tokens":1201}]},"request_id":"8cea84fe-2770-91b0-a6d1-e1e8ef176fa6"}
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: 8cea84fe-2770-91b0-a6d1-e1e8ef176fa6
5+
x-dashscope-timeout: 180
6+
x-dashscope-call-gateway: true
7+
x-dashscope-finished: true
8+
req-cost-time: 2516
9+
req-arrive-time: 1742129333100
10+
resp-start-time: 1742129335617
11+
x-envoy-upstream-service-time: 2508
12+
content-encoding: gzip
13+
date: Sun, 16 Mar 2025 12:48:55 GMT
14+
server: istio-envoy
15+
transfer-encoding: chunked

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,46 @@ public static class Application
210210
null),
211211
new ApplicationUsage([new ApplicationModelUsage("deepseek-r1", 1129, 1126)])));
212212

213+
public static readonly RequestSnapshot<ApplicationRequest, ApplicationResponse> SinglePromptWithMemoryNoSse =
214+
new(
215+
"application-single-generation-text-with-memory",
216+
new ApplicationRequest()
217+
{
218+
Input = new ApplicationInput()
219+
{
220+
Prompt = "我爱吃面食", MemoryId = "ffd8be2352d84c6b9350e91c865b512e"
221+
},
222+
Parameters = new ApplicationParameters()
223+
{
224+
TopK = 100,
225+
TopP = 0.8f,
226+
Seed = 1234,
227+
Temperature = 0.85f,
228+
HasThoughts = true
229+
}
230+
},
231+
new ApplicationResponse(
232+
"8cea84fe-2770-91b0-a6d1-e1e8ef176fa6",
233+
new ApplicationOutput(
234+
"那您一定会对面条、馒头或者饺子这些美食很感兴趣呢!如果您有特定的面食问题或者需要推荐相关的菜品,可以告诉我,我很乐意为您提供帮助<ref>[1]</ref>。",
235+
"stop",
236+
"cd395cb8d4604db786a14555fdcffa1a",
237+
[
238+
new ApplicationOutputThought(null, "agentRag", "知识检索", "rag", "{}", null, "[]", null, "{}"),
239+
new ApplicationOutputThought(
240+
null,
241+
"api",
242+
"长期记忆检索",
243+
"memory",
244+
"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"我爱吃面食\"}",
245+
null,
246+
"[\"[2025-3-16 20:47:40 周日] 用户喜欢吃面食。\"]",
247+
null,
248+
"{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"我爱吃面食\"}")
249+
],
250+
null),
251+
new ApplicationUsage([new ApplicationModelUsage("qwen-plus", 1201, 43)])));
252+
213253
public static readonly RequestSnapshot<ApplicationRequest, ApplicationResponse> ConversationSessionIdNoSse =
214254
new(
215255
"application-conversation-generation-session-id",

0 commit comments

Comments
 (0)