Skip to content

Commit 3d7ce60

Browse files
committed
test: add toolcall snapshot
1 parent 7bcb719 commit 3d7ce60

File tree

7 files changed

+204
-45
lines changed

7 files changed

+204
-45
lines changed

sample/Cnblogs.DashScope.Sample/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Cnblogs.DashScope.Sample.Text;
77
using Cnblogs.DashScope.Sdk;
88
using Cnblogs.DashScope.Sdk.QWen;
9-
using Cnblogs.DashScope.Sdk.TextEmbedding;
109
using Cnblogs.DashScope.Sdk.Wanx;
1110
using Json.Schema;
1211
using Json.Schema.Generation;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ public async Task ConversationCompletion_MessageFormatSse_SuccessAsync(
183183
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>> SingleGenerationMessageSseFormatData = new(
184184
Snapshots.TextGeneration.MessageFormat.SingleMessageIncremental,
185185
Snapshots.TextGeneration.MessageFormat.SingleMessageReasoningIncremental,
186-
Snapshots.TextGeneration.MessageFormat.SingleMessageWebSearchIncremental);
186+
Snapshots.TextGeneration.MessageFormat.SingleMessageWebSearchIncremental,
187+
Snapshots.TextGeneration.MessageFormat.SingleMessageWithToolsIncremental);
187188

188189
public static readonly TheoryData<RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
189190
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>> ConversationMessageFormatSseData = new(
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"model": "qwen-plus",
3+
"input": {
4+
"messages": [
5+
{
6+
"role": "user",
7+
"content": "杭州上海现在的天气如何?"
8+
},
9+
{
10+
"role": "assistant",
11+
"content": "",
12+
"tool_calls": [
13+
{
14+
"function": {
15+
"name": "get_current_weather",
16+
"arguments": "{\"location\": \"浙江省杭州市\"}"
17+
},
18+
"index": 0,
19+
"id": "call_cec4c19d27624537b583af",
20+
"type": "function"
21+
},
22+
{
23+
"function": {
24+
"name": "get_current_weather",
25+
"arguments": "{\"location\": \"上海市\"}"
26+
},
27+
"index": 1,
28+
"id": "call_dxjdop3d27624537b583af",
29+
"type": "function"
30+
}
31+
]
32+
},
33+
{
34+
"role": "tool",
35+
"content": "浙江省杭州市 大部多云,摄氏 18 度",
36+
"tool_call_id": "call_cec4c19d27624537b583af"
37+
},
38+
{
39+
"role": "tool",
40+
"content": "上海市 多云转小雨,摄氏 19 度",
41+
"tool_call_id": "call_dxjdop3d27624537b583af"
42+
}
43+
]
44+
},
45+
"parameters": {
46+
"result_format": "message",
47+
"seed": 6999,
48+
"max_tokens": 1500,
49+
"incremental_output": true,
50+
"tools": [
51+
{
52+
"type": "function",
53+
"function": {
54+
"name": "get_current_weather",
55+
"description": "获取现在的天气",
56+
"parameters": {
57+
"type": "object",
58+
"properties": {
59+
"location": {
60+
"type": "string",
61+
"description": "要获取天气的省市名称,例如浙江省杭州市"
62+
}
63+
},
64+
"required": [
65+
"location"
66+
]
67+
}
68+
}
69+
}
70+
],
71+
"parallel_tool_calls": true
72+
}
73+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST /api/v1/services/aigc/text-generation/generation 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: 2894
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
id:1
2+
event:result
3+
:HTTP_STATUS/200
4+
data:{"output":{"choices":[{"message":{"content":"目前","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":284,"output_tokens":1,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
5+
id:2
6+
event:result
7+
:HTTP_STATUS/200
8+
data:{"output":{"choices":[{"message":{"content":"杭州和","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":286,"output_tokens":3,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
9+
id:3
10+
event:result
11+
:HTTP_STATUS/200
12+
data:{"output":{"choices":[{"message":{"content":"上海的","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":288,"output_tokens":5,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
13+
id:4
14+
event:result
15+
:HTTP_STATUS/200
16+
data:{"output":{"choices":[{"message":{"content":"天气情况如下","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":291,"output_tokens":8,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
17+
id:5
18+
event:result
19+
:HTTP_STATUS/200
20+
data:{"output":{"choices":[{"message":{"content":":\n\n- **杭州**:","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":297,"output_tokens":14,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
21+
id:6
22+
event:result
23+
:HTTP_STATUS/200
24+
data:{"output":{"choices":[{"message":{"content":"大部多云","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":301,"output_tokens":18,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
25+
id:7
26+
event:result
27+
:HTTP_STATUS/200
28+
data:{"output":{"choices":[{"message":{"content":",气温为18℃","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":307,"output_tokens":24,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
29+
id:8
30+
event:result
31+
:HTTP_STATUS/200
32+
data:{"output":{"choices":[{"message":{"content":"。\n- **上海**:","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":313,"output_tokens":30,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
33+
id:9
34+
event:result
35+
:HTTP_STATUS/200
36+
data:{"output":{"choices":[{"message":{"content":"多云转小雨,","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":319,"output_tokens":36,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
37+
id:10
38+
event:result
39+
:HTTP_STATUS/200
40+
data:{"output":{"choices":[{"message":{"content":"气温为19℃。\n\n","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":325,"output_tokens":42,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
41+
id:11
42+
event:result
43+
:HTTP_STATUS/200
44+
data:{"output":{"choices":[{"message":{"content":"请注意天气变化,出门","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":330,"output_tokens":47,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
45+
id:12
46+
event:result
47+
:HTTP_STATUS/200
48+
data:{"output":{"choices":[{"message":{"content":"携带雨具以防","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":334,"output_tokens":51,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
49+
id:13
50+
event:result
51+
:HTTP_STATUS/200
52+
data:{"output":{"choices":[{"message":{"content":"下雨。","role":"assistant"},"index":0,"finish_reason":"null"}]},"usage":{"total_tokens":336,"output_tokens":53,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
53+
id:14
54+
event:result
55+
:HTTP_STATUS/200
56+
data:{"output":{"choices":[{"message":{"content":"","role":"assistant"},"index":0,"finish_reason":"stop"}]},"usage":{"total_tokens":336,"output_tokens":53,"input_tokens":283,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"dd51401b-146e-42a0-96d9-4067a5fac75a"}
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: dd51401b-146e-42a0-96d9-4067a5fac75a
4+
content-type: text/event-stream;charset=UTF-8
5+
x-dashscope-call-gateway: true
6+
x-dashscope-timeout: 298
7+
x-dashscope-finished: false
8+
req-cost-time: 166
9+
req-arrive-time: 1760967863780
10+
resp-start-time: 1760967863946
11+
x-envoy-upstream-service-time: 159
12+
date: Mon, 20 Oct 2025 13:44:23 GMT
13+
server: istio-envoy
14+
transfer-encoding: chunked

test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.TextGeneration.cs

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -807,44 +807,63 @@ public static readonly
807807

808808
public static readonly
809809
RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
810-
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>> SingleMessageChatClientWithTools =
810+
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>> SingleMessageWithToolsIncremental =
811811
new(
812812
"single-generation-message-with-tools",
813813
new ModelRequest<TextGenerationInput, ITextGenerationParameters>
814814
{
815-
Model = "qwen-max",
815+
Model = "qwen-plus",
816816
Input = new TextGenerationInput
817817
{
818818
Messages =
819-
new List<TextChatMessage> { TextChatMessage.User("杭州现在的天气如何?") }
819+
new List<TextChatMessage>
820+
{
821+
TextChatMessage.User("杭州上海现在的天气如何?"),
822+
TextChatMessage.Assistant(
823+
string.Empty,
824+
toolCalls: new List<ToolCall>()
825+
{
826+
new(
827+
"call_cec4c19d27624537b583af",
828+
"function",
829+
0,
830+
new FunctionCall(
831+
"get_current_weather",
832+
"{\"location\": \"浙江省杭州市\"}")),
833+
new(
834+
"call_dxjdop3d27624537b583af",
835+
"function",
836+
1,
837+
new FunctionCall(
838+
"get_current_weather",
839+
"{\"location\": \"上海市\"}")),
840+
}),
841+
TextChatMessage.Tool("浙江省杭州市 大部多云,摄氏 18 度", "call_cec4c19d27624537b583af"),
842+
TextChatMessage.Tool("上海市 多云转小雨,摄氏 19 度", "call_dxjdop3d27624537b583af")
843+
}
820844
},
821845
Parameters = new TextGenerationParameters
822846
{
823847
ResultFormat = "message",
824-
Seed = 1234,
848+
Seed = 6999,
825849
MaxTokens = 1500,
826-
TopP = 0.8f,
827-
TopK = 100,
828-
RepetitionPenalty = 1.1f,
829-
PresencePenalty = 1.2f,
830-
Temperature = 0.85f,
831-
Tools =
832-
new List<ToolDefinition>
833-
{
834-
new(
835-
"function",
836-
new FunctionDefinition(
837-
"get_current_weather",
838-
"获取现在的天气",
839-
new JsonSchemaBuilder().FromType<GetCurrentWeatherParameters>(
840-
new SchemaGeneratorConfiguration
841-
{
842-
PropertyNameResolver =
843-
PropertyNameResolvers.LowerSnakeCase
844-
})
845-
.Build()))
846-
},
847-
ToolChoice = ToolChoice.FunctionChoice("get_current_weather")
850+
IncrementalOutput = true,
851+
Tools = new List<ToolDefinition>
852+
{
853+
new(
854+
"function",
855+
new FunctionDefinition(
856+
"get_current_weather",
857+
"获取现在的天气",
858+
new JsonSchemaBuilder().FromType<GetCurrentWeatherParameters>(
859+
new SchemaGeneratorConfiguration
860+
{
861+
PropertyNameResolver =
862+
PropertyNameResolvers.LowerSnakeCase
863+
})
864+
.Build()))
865+
},
866+
ParallelToolCalls = true
848867
}
849868
},
850869
new ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>
@@ -857,28 +876,17 @@ public static readonly
857876
new()
858877
{
859878
FinishReason = "stop",
860-
Message = TextChatMessage.Assistant(
861-
string.Empty,
862-
toolCalls:
863-
new List<ToolCall>
864-
{
865-
new(
866-
"call_cec4c19d27624537b583af",
867-
ToolTypes.Function,
868-
0,
869-
new FunctionCall(
870-
"get_current_weather",
871-
"{\"location\": \"浙江省杭州市\"}"))
872-
})
879+
Message = TextChatMessage.Assistant("目前杭州和上海的天气情况如下:\n\n- **杭州**:大部多云,气温为18℃。\n- **上海**:多云转小雨,气温为19℃。\n\n请注意天气变化,出门携带雨具以防下雨。")
873880
}
874881
}
875882
},
876-
RequestId = "67300049-c108-9987-b1c1-8e0ee2de6b5d",
883+
RequestId = "dd51401b-146e-42a0-96d9-4067a5fac75a",
877884
Usage = new TextGenerationTokenUsage
878885
{
879-
InputTokens = 211,
880-
OutputTokens = 8,
881-
TotalTokens = 219
886+
InputTokens = 283,
887+
OutputTokens = 53,
888+
TotalTokens = 336,
889+
PromptTokensDetails = new TextGenerationPromptTokenDetails(0)
882890
}
883891
});
884892

0 commit comments

Comments
 (0)