Skip to content

Commit 14ed2eb

Browse files
committed
test: add snapshot for web search
1 parent 2e108cc commit 14ed2eb

6 files changed

+108
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ public async Task ConversationCompletion_MessageFormatSse_SuccessAsync(
157157
Snapshots.TextGeneration.MessageFormat.SingleMessageWithTools,
158158
Snapshots.TextGeneration.MessageFormat.SingleMessageJson,
159159
Snapshots.TextGeneration.MessageFormat.SingleMessageLogprobs,
160-
Snapshots.TextGeneration.MessageFormat.SingleMessageTranslation);
160+
Snapshots.TextGeneration.MessageFormat.SingleMessageTranslation,
161+
Snapshots.TextGeneration.MessageFormat.SingleMessageWebSearch);
161162

162163
public static readonly TheoryData<RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
163164
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>> SingleGenerationMessageSseFormatData = new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"model": "qwen-max",
3+
"input": {
4+
"messages": [
5+
{
6+
"role": "user",
7+
"content": "总结博客园 dudu 的最新博客"
8+
}
9+
]
10+
},
11+
"parameters": {
12+
"result_format": "message",
13+
"enable_search": true,
14+
"search_options": {
15+
"enable_source": true,
16+
"enable_citation": true,
17+
"citation_format": "[ref_<number>]",
18+
"forced_search": true,
19+
"search_strategy": "standard"
20+
}
21+
}
22+
}
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+
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: 592
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"output":{"search_info":{"search_results":[{"site_name":"CSDN - 专业开发者社区","icon":"https://img.alicdn.com/imgextra/i3/O1CN01QA3ndK1maJQ8rZTo1_!!6000000004970-55-tps-32-32.svg","index":1,"title":"我与博客园的20年转载","url":"https://blog.csdn.net/weixin_40884228/article/details/148485212"},{"site_name":"博客园","icon":"https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg","index":2,"title":"dudu - 博客园","url":"https://www.cnblogs.com/dudu"},{"site_name":"博客园","icon":"https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg","index":3,"title":"dudu - 博客园","url":"https://www.cnblogs.com/dudu?page=36"},{"site_name":"阿里云官方网站","icon":"https://img.alicdn.com/imgextra/i3/O1CN015NhUWq1Z1sdj3359l_!!6000000003135-55-tps-32-32.svg","index":4,"title":"玩转博客园的心路总结 - 阿里云开发者社区","url":"https://developer.aliyun.com/article/331235"},{"site_name":"CSDN - 专业开发者社区","icon":"https://img.alicdn.com/imgextra/i3/O1CN01QA3ndK1maJQ8rZTo1_!!6000000004970-55-tps-32-32.svg","index":5,"title":"为.NET程序员打工的站长——博客园dudu 原创","url":"https://blog.csdn.net/Microsoft_MVP/article/details/2416055"}]},"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":"截至2025年6月7日,博客园的dudu站长发布的内容包括了技术分享和个人经历总结。以下是对dudu最近博客内容的一个概括:\n\n1. 代码重构经验分享:dudu在一篇博客中分享了他在博客园后台开发过程中遇到的一次代码重构经历。这次重构涉及到两个列表的合并(union),他需要实现一个自定义的`EqualityComparer`,基于列表元素的`Id`字段来进行比较,而不是默认的对象引用比较。这表明dudu在持续关注和改进博客园的技术架构,以确保其高效和可维护性。[ref_2]\n\n2. 开源工具介绍:另一篇博客介绍了名为NBearMapping的开源对象映射工具,该工具可用于不同类型的对象、DataRow以及DataReader之间的数据映射。dudu提到这个工具对于开发者来说非常有用,因为它可以简化数据层与业务逻辑层之间的交互。[ref_3]\n\n此外,还有关于个人与博客园共同成长的感想,提到了在过去20年间,无论是个人还是博客园本身都经历了巨大的变化。dudu也提到了自己正面临一些个人生活中的挑战,并表达了对博客园社区理解和支持的感激之情。[ref_1]\n\n这些博客不仅展示了dudu作为技术人员的专业知识和技术分享的热情,还反映了他对博客园这个平台的深厚感情和个人投入。如果您需要更详细的博客内容或有其他问题,请告知我以便提供进一步的帮助。"}}]},"usage":{"plugins":{"search":{"count":1}},"total_tokens":800,"output_tokens":304,"input_tokens":496,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"80753a20-2750-9ab6-bc2a-1b851ef43efc"}
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: 405d57ba-6cfc-9519-977f-0f519f712364
5+
x-dashscope-call-gateway: true
6+
x-dashscope-finished: true
7+
x-dashscope-timeout: 298
8+
req-cost-time: 810
9+
req-arrive-time: 1751899675324
10+
resp-start-time: 1751899676135
11+
x-envoy-upstream-service-time: 802
12+
content-encoding: gzip
13+
date: Mon, 07 Jul 2025 14:47:55 GMT
14+
server: istio-envoy
15+
transfer-encoding: chunked

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,66 @@ public static class MessageFormat
344344
}
345345
});
346346

347+
public static readonly RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
348+
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>
349+
SingleMessageWebSearch = new(
350+
"single-generation-message-search",
351+
new ModelRequest<TextGenerationInput, ITextGenerationParameters>
352+
{
353+
Model = "qwen-max",
354+
Input =
355+
new TextGenerationInput
356+
{
357+
Messages =
358+
new List<TextChatMessage> { TextChatMessage.User("总结博客园 dudu 的最新博客") }
359+
},
360+
Parameters = new TextGenerationParameters
361+
{
362+
ResultFormat = "message",
363+
EnableSearch = true,
364+
SearchOptions = new TextGenerationSearchOptions()
365+
{
366+
EnableSource = true,
367+
EnableCitation = true,
368+
CitationFormat = "[ref_<number>]",
369+
ForcedSearch = true,
370+
SearchStrategy = "standard"
371+
}
372+
}
373+
},
374+
new ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>
375+
{
376+
Output = new TextGenerationOutput
377+
{
378+
Choices =
379+
new List<TextGenerationChoice>
380+
{
381+
new()
382+
{
383+
FinishReason = "stop",
384+
Message = TextChatMessage.Assistant(
385+
"截至2025年6月7日,博客园的dudu站长发布的内容包括了技术分享和个人经历总结。以下是对dudu最近博客内容的一个概括:\n\n1. 代码重构经验分享:dudu在一篇博客中分享了他在博客园后台开发过程中遇到的一次代码重构经历。这次重构涉及到两个列表的合并(union),他需要实现一个自定义的`EqualityComparer`,基于列表元素的`Id`字段来进行比较,而不是默认的对象引用比较。这表明dudu在持续关注和改进博客园的技术架构,以确保其高效和可维护性。[ref_2]\n\n2. 开源工具介绍:另一篇博客介绍了名为NBearMapping的开源对象映射工具,该工具可用于不同类型的对象、DataRow以及DataReader之间的数据映射。dudu提到这个工具对于开发者来说非常有用,因为它可以简化数据层与业务逻辑层之间的交互。[ref_3]\n\n此外,还有关于个人与博客园共同成长的感想,提到了在过去20年间,无论是个人还是博客园本身都经历了巨大的变化。dudu也提到了自己正面临一些个人生活中的挑战,并表达了对博客园社区理解和支持的感激之情。[ref_1]\n\n这些博客不仅展示了dudu作为技术人员的专业知识和技术分享的热情,还反映了他对博客园这个平台的深厚感情和个人投入。如果您需要更详细的博客内容或有其他问题,请告知我以便提供进一步的帮助。"),
386+
}
387+
},
388+
SearchInfo = new TextGenerationWebSearchInfo(new List<TextGenerationWebSearchResult>()
389+
{
390+
new("CSDN - 专业开发者社区", "https://img.alicdn.com/imgextra/i3/O1CN01QA3ndK1maJQ8rZTo1_!!6000000004970-55-tps-32-32.svg", 1, "我与博客园的20年转载", "https://blog.csdn.net/weixin_40884228/article/details/148485212"),
391+
new("博客园", "https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg", 2, "dudu - 博客园", "https://www.cnblogs.com/dudu"),
392+
new("博客园", "https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg", 3, "dudu - 博客园", "https://www.cnblogs.com/dudu?page=36"),
393+
new("阿里云官方网站", "https://img.alicdn.com/imgextra/i3/O1CN015NhUWq1Z1sdj3359l_!!6000000003135-55-tps-32-32.svg", 4, "玩转博客园的心路总结 - 阿里云开发者社区", "https://developer.aliyun.com/article/331235"),
394+
new("CSDN - 专业开发者社区", "https://img.alicdn.com/imgextra/i3/O1CN01QA3ndK1maJQ8rZTo1_!!6000000004970-55-tps-32-32.svg", 5, "为.NET程序员打工的站长——博客园dudu 原创", "https://blog.csdn.net/Microsoft_MVP/article/details/2416055")
395+
})
396+
},
397+
RequestId = "80753a20-2750-9ab6-bc2a-1b851ef43efc",
398+
Usage = new TextGenerationTokenUsage
399+
{
400+
TotalTokens = 800,
401+
OutputTokens = 304,
402+
InputTokens = 496,
403+
PromptTokensDetails = new TextGenerationPromptTokenDetails(0)
404+
}
405+
});
406+
347407
public static readonly RequestSnapshot<ModelRequest<TextGenerationInput, ITextGenerationParameters>,
348408
ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>>
349409
SingleMessageJson = new(

0 commit comments

Comments
 (0)