diff --git a/.editorconfig b/.editorconfig index 6b17d25..644e447 100644 --- a/.editorconfig +++ b/.editorconfig @@ -384,5 +384,5 @@ dotnet_naming_style.s_camelcase.capitalization = camel_case indent_size = 2 tab_width = 2 -[*.{props,targets,config,nuspec,json}] +[*.{props,targets,config,nuspec,json,yml}] indent_size = 2 diff --git "a/.github/ISSUE_TEMPLATE/api-\347\274\272\345\244\261.md" "b/.github/ISSUE_TEMPLATE/api-\347\274\272\345\244\261.md" new file mode 100644 index 0000000..9cadf76 --- /dev/null +++ "b/.github/ISSUE_TEMPLATE/api-\347\274\272\345\244\261.md" @@ -0,0 +1,16 @@ +--- +name: API 缺失 +about: 百炼文档中提到了某个 API/参数/返回值,但 SDK 中没有 +title: "[API Sync]" +labels: bug, untriaged +assignees: ikesnowy + +--- + +**百炼文档链接** +提供百炼对应的文档链接,以及希望添加的内容 + +**SDK 对应的方法(如果有)** + +**其他信息** +例如,希望 SDK 通过 Enum 提供代码提示友好的接入 diff --git "a/.github/ISSUE_TEMPLATE/bug-\345\217\215\351\246\210.md" "b/.github/ISSUE_TEMPLATE/bug-\345\217\215\351\246\210.md" new file mode 100644 index 0000000..c9d377f --- /dev/null +++ "b/.github/ISSUE_TEMPLATE/bug-\345\217\215\351\246\210.md" @@ -0,0 +1,30 @@ +--- +name: Bug 反馈 +about: 代码不起作用/抛出异常/结果不正确 +title: "[BUG]" +labels: bug, untriaged +assignees: ikesnowy + +--- + +**环境信息** +安装的包及版本(例如 `Cnblogs.DashScope.Sdk/v0.7.6`): +`.NET` 版本(例如 `net8.0)`: +使用的模型名称(例如 `qwen-max`): + +**复现流程** + +进行如下调用时触发了 bug: + +```csharp +// 输入参数 + +// 调用的方法 + +``` + +**预期结果** +按预期,以上调用应当返回 xxx 结果 + +**其他相关信息** +例如初步 debug 截图/部署方法(IIS, docker,k8s,控制台等)/日志信息/使用场景/访问规模等有关 BUG 出现场景的信息。 diff --git "a/.github/ISSUE_TEMPLATE/sdk-\344\275\277\347\224\250\344\275\223\351\252\214.md" "b/.github/ISSUE_TEMPLATE/sdk-\344\275\277\347\224\250\344\275\223\351\252\214.md" new file mode 100644 index 0000000..1fb6156 --- /dev/null +++ "b/.github/ISSUE_TEMPLATE/sdk-\344\275\277\347\224\250\344\275\223\351\252\214.md" @@ -0,0 +1,24 @@ +--- +name: SDK 相关 +about: SDK 本身的改进,例如升级依赖包版本/添加方法重载/提供额外能力等 +title: "[SDK]" +labels: untriaged +assignees: ikesnowy + +--- + +**希望更改的 SDK 内容** + +受影响的 SDK API +```csharp +// 提供 SDK 的方法名或者调用方法 +``` + +希望做出的改进 +```csharp +// 希望以这种方式调用 +``` + +**其他信息** + +使用场景/项目背景/限制条件(例如:无法依赖 xx 包),以及可接受的其他方式 diff --git "a/.github/ISSUE_TEMPLATE/\346\226\207\346\241\243\347\233\270\345\205\263.md" "b/.github/ISSUE_TEMPLATE/\346\226\207\346\241\243\347\233\270\345\205\263.md" new file mode 100644 index 0000000..90e2b60 --- /dev/null +++ "b/.github/ISSUE_TEMPLATE/\346\226\207\346\241\243\347\233\270\345\205\263.md" @@ -0,0 +1,12 @@ +--- +name: 文档相关 +about: SDK 在文档上需要做出的改进 +title: "[DOC]" +labels: documentation, untriaged +assignees: ikesnowy + +--- + +**文档文件位置(如果有)** + +**希望做出的改进** diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ab7c15..0af6bf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,15 +7,25 @@ on: branches: [ "main" ] jobs: - test: + test-net6: runs-on: ubuntu-latest - container: mcr.microsoft.com/dotnet/sdk:8.0 + container: mcr.microsoft.com/dotnet/sdk:6.0 steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build - run: dotnet build -c Release - - name: Test - run: dotnet test -c Release + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: dotnet build src/Cnblogs.DashScope.AspNetCore -c Release + - name: Test + run: dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release + test-net8: + runs-on: ubuntu-latest + container: mcr.microsoft.com/dotnet/sdk:8.0 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: dotnet build src/Cnblogs.DashScope.AI -c Release + - name: Test + run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release diff --git a/Cnblogs.DashScope.Sdk.sln b/Cnblogs.DashScope.Sdk.sln index 26d0161..2cb77fe 100644 --- a/Cnblogs.DashScope.Sdk.sln +++ b/Cnblogs.DashScope.Sdk.sln @@ -16,10 +16,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.AspNetCor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Core", "src\Cnblogs.DashScope.Core\Cnblogs.DashScope.Core.csproj", "{CC389455-A3EA-4F09-B524-4DC351A1E1AA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Sdk.SnapshotGenerator", "test\Cnblogs.DashScope.Sdk.SnapshotGenerator\Cnblogs.DashScope.Sdk.SnapshotGenerator.csproj", "{5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.AI", "src\Cnblogs.DashScope.AI\Cnblogs.DashScope.AI.csproj", "{5D5AD75A-8084-4738-AC56-B8A23E649452}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.AI.UnitTests", "test\Cnblogs.DashScope.AI.UnitTests\Cnblogs.DashScope.AI.UnitTests.csproj", "{25EE79E1-147B-42FD-AFEA-E1550EDD1D36}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cnblogs.DashScope.Tests.Shared", "test\Cnblogs.DashScope.Tests.Shared\Cnblogs.DashScope.Tests.Shared.csproj", "{06F0AF23-445B-4C6F-9E19-570DA9B7435D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,8 +33,9 @@ Global {8885149A-78F0-4C8E-B9AA-87A46EA69219} = {2E15D1EC-4A07-416E-8BE6-D907F509FD35} {C910495B-87AB-4AC1-989C-B6720695A139} = {008988ED-0A3B-4272-BCC3-7B4110699345} {CC389455-A3EA-4F09-B524-4DC351A1E1AA} = {008988ED-0A3B-4272-BCC3-7B4110699345} - {5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1} = {CFC8ECB3-5248-46CD-A56C-EC088F2A3804} {5D5AD75A-8084-4738-AC56-B8A23E649452} = {008988ED-0A3B-4272-BCC3-7B4110699345} + {25EE79E1-147B-42FD-AFEA-E1550EDD1D36} = {CFC8ECB3-5248-46CD-A56C-EC088F2A3804} + {06F0AF23-445B-4C6F-9E19-570DA9B7435D} = {CFC8ECB3-5248-46CD-A56C-EC088F2A3804} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {FA6A118A-8D26-4B7A-9952-8504B8A0025B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -55,13 +58,17 @@ Global {CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {CC389455-A3EA-4F09-B524-4DC351A1E1AA}.Release|Any CPU.Build.0 = Release|Any CPU - {5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5088DE77-1CE3-46FB-B9D0-27A6C9A5EED1}.Release|Any CPU.Build.0 = Release|Any CPU {5D5AD75A-8084-4738-AC56-B8A23E649452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5D5AD75A-8084-4738-AC56-B8A23E649452}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D5AD75A-8084-4738-AC56-B8A23E649452}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D5AD75A-8084-4738-AC56-B8A23E649452}.Release|Any CPU.Build.0 = Release|Any CPU + {25EE79E1-147B-42FD-AFEA-E1550EDD1D36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25EE79E1-147B-42FD-AFEA-E1550EDD1D36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25EE79E1-147B-42FD-AFEA-E1550EDD1D36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25EE79E1-147B-42FD-AFEA-E1550EDD1D36}.Release|Any CPU.Build.0 = Release|Any CPU + {06F0AF23-445B-4C6F-9E19-570DA9B7435D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06F0AF23-445B-4C6F-9E19-570DA9B7435D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06F0AF23-445B-4C6F-9E19-570DA9B7435D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06F0AF23-445B-4C6F-9E19-570DA9B7435D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Cnblogs.DashScope.Sdk.sln.DotSettings b/Cnblogs.DashScope.Sdk.sln.DotSettings index 3ad7f9e..9866f59 100644 --- a/Cnblogs.DashScope.Sdk.sln.DotSettings +++ b/Cnblogs.DashScope.Sdk.sln.DotSettings @@ -1,4 +1,8 @@  + True True True - True \ No newline at end of file + True + True + True + True \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index f39a7b6..3eaabd9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net6.0 enable enable Cnblogs diff --git a/README.md b/README.md index 02f3ff3..18049e2 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,40 @@ English | [简体中文](https://github.com/cnblogs/dashscope-sdk/blob/main/README.zh-Hans.md) +# Cnblogs.DashScopeSDK + [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.AI?style=flat&logo=nuget&label=Cnblogs.DashScope.AI)](https://www.nuget.org/packages/Cnblogs.DashScope.AI) [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.Sdk?style=flat&logo=nuget&label=Cnblogs.DashScope.Sdk&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FCnblogs.DashScope.Sdk)](https://www.nuget.org/packages/Cnblogs.DashScope.Sdk) [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.AspNetCore?style=flat&logo=nuget&label=Cnblogs.DashScope.AspNetCore&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FCnblogs.DashScope.AspNetCore)](https://www.nuget.org/packages/Cnblogs.DashScope.AspNetCore) -# DashScope SDK for .NET - -An unofficial DashScope SDK maintained by Cnblogs. +A non-official DashScope (Bailian) service SDK maintained by Cnblogs. -**Warning**: this project is under active development, **Breaking Changes** may introduced without notice or major version change. Make sure you read the Release Notes before upgrading. +**Note:** This project is actively under development. Breaking changes may occur even in minor versions. Please review the Release Notes before upgrading. -# Quick Start +## Quick Start -## Using `Microsoft.Extensions.AI` - -Install `Cnblogs.DashScope.AI` Package +### Using `Microsoft.Extensions.AI` Interface +Install NuGet package `Cnblogs.DashScope.AI` ```csharp var client = new DashScopeClient("your-api-key").AsChatClient("qwen-max"); var completion = await client.CompleteAsync("hello"); Console.WriteLine(completion) ``` -## Console App - -Install `Cnblogs.DashScope.Sdk` package. +### Console Application +Install NuGet package `Cnblogs.DashScope.Sdk` ```csharp var client = new DashScopeClient("your-api-key"); var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); -// or pass the model name string directly. +// Or use model name string // var completion = await client.GetQWenCompletionAsync("qwen-max", prompt); Console.WriteLine(completion.Output.Text); ``` -## ASP.NET Core +### ASP.NET Core Application -Install the Cnblogs.DashScope.AspNetCore package. +Install NuGet package `Cnblogs.DashScope.AspNetCore` `Program.cs` ```csharp @@ -44,99 +42,42 @@ builder.AddDashScopeClient(builder.Configuration); ``` `appsettings.json` + ```json { "DashScope": { - "ApiKey": "your-api-key", + "ApiKey": "your-api-key" } } ``` -`Usage` +Application class: + ```csharp public class YourService(IDashScopeClient client) { public async Task CompletePromptAsync(string prompt) { - var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); - return completion.Output.Text; + var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); + return completion.Output.Text; } } ``` +## Supported APIs +- [Chat](#Chat) - QWen3, DeepSeek, etc. Supports reasoning, tool calling, web search, translation +- [Multimodal](#multimodal) - QWen-VL, QVQ, etc. Supports reasoning, visual understanding, OCR, audio understanding +- [Text-to-Speech (TTS)](#Text-to-Speech) - CosyVoice, Sambert +- [Image Generation](#image-generation) - Wanx2.1 (text-to-image, portrait style transfer) +- [Application Call](#application-call) +- [Text Vectorization](#text-vectorization) -# Supported APIs - -- Text Embedding API - `GetTextEmbeddingsAsync()` -- Text Generation API(qwen-turbo, qwen-max, etc.) - `GetQWenCompletionAsync()` and `GetQWenCompletionStreamAsync()` -- DeepSeek Models - `GetDeepSeekCompletionAsync()` and `GetDeepSeekCompletionStreamAsync()` -- BaiChuan Models - Use `GetBaiChuanTextCompletionAsync()` -- LLaMa2 Models - `GetLlama2TextCompletionAsync()` -- Multimodal Generation API(qwen-vl-max, etc.) - `GetQWenMultimodalCompletionAsync()` and `GetQWenMultimodalCompletionStreamAsync()` -- Wanx Models(Image generation, background generation, etc) - - Image Synthesis - `CreateWanxImageSynthesisTaskAsync()` and `GetWanxImageSynthesisTaskAsync()` - - Image Generation - `CreateWanxImageGenerationTaskAsync()` and `GetWanxImageGenerationTaskAsync()` - - Background Image Generation - `CreateWanxBackgroundGenerationTaskAsync()` and `GetWanxBackgroundGenerationTaskAsync()` -- File API that used by Qwen-Long - `UploadFileAsync()` and `DeleteFileAsync` -- Application call - `GetApplicationResponseAsync()` and `GetApplicationResponseStreamAsync()` - -# Examples - -Visit [snapshots](./test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs) for calling samples. - -Visit [tests](./test/Cnblogs.DashScope.Sdk.UnitTests) for more usage of each api. - -## General Text Completion API - -Use `client.GetTextCompletionAsync` and `client.GetTextCompletionStreamAsync` to access text generation api directly. - -```csharp -var completion = await dashScopeClient.GetTextCompletionAsync( - new ModelRequest - { - Model = "your-model-name", - Input = new TextGenerationInput { Prompt = prompt }, - Parameters = new TextGenerationParameters() - { - // control parameters as you wish. - EnableSearch = true - } - }); -var completions = dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = "your-model-name", - Input = new TextGenerationInput { Messages = [TextChatMessage.System("you are a helpful assistant"), TextChatMessage.User("How are you?")] }, - Parameters = new TextGenerationParameters() - { - // control parameters as you wish. - EnableSearch = true, - IncreamentalOutput = true - } - }); -``` - -## Single Text Completion -```csharp -var prompt = "hello" -var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); -Console.WriteLine(completion.Output.Text); -``` - -## Reasoning +### Chat -Use `completion.Output.Choices![0].Message.ReasoningContent` to access the reasoning content from model. - -```csharp -var history = new List -{ - ChatMessage.User("Calculate 1+1") -}; -var completion = await client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSeekR1, history); -Console.WriteLine(completion.Output.Choices[0]!.Message.ReasoningContent); -``` +Use `GetTextCompletionAsync`/`GetTextCompletionStreamAsync` for direct text generation. +For QWen and DeepSeek, use shortcuts: `GetQWenChatCompletionAsync`/`GetDeepSeekChatCompletionAsync` -## Multi-round chat +[Official Documentation](https://help.aliyun.com/zh/model-studio/user-guide/text-generation/) ```csharp var history = new List @@ -153,115 +94,191 @@ var completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenMax, histor Console.WriteLine(completion.Output.Choices[0].Message.Content); // The number is 42 ``` -## Function Call +#### Reasoning -Creates a function with parameters +Access model thoughts via `ReasoningContent` property +```csharp +var history = new List +{ + TextChatMessage.User("Calculate 1+1") +}; +var completion = await client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSeekR1, history); +Console.WriteLine(completion.Output.Choices[0]!.Message.ReasoningContent); +``` +For QWen3 models, enable reasoning with `TextGenerationParameters.EnableThinking` +```csharp +var stream = dashScopeClient + .GetQWenChatStreamAsync( + QWenLlm.QWenPlusLatest, + history, + new TextGenerationParameters + { + IncrementalOutput = true, + ResultFormat = ResultFormats.Message, + EnableThinking = true + }); +``` +#### Tool Calling +Define a function for model to use: ```csharp string GetCurrentWeather(GetCurrentWeatherParameters parameters) { - // actual implementation should be different. - return "Sunny, 14" + parameters.Unit switch - { - TemperatureUnit.Celsius => "℃", - TemperatureUnit.Fahrenheit => "℉" - }; + return "Sunny"; } - public record GetCurrentWeatherParameters( [property: Required] - [property: Description("The city and state, e.g. San Francisco, CA")] + [property: Description("City and state, e.g. San Francisco, CA")] string Location, [property: JsonConverter(typeof(EnumStringConverter))] TemperatureUnit Unit = TemperatureUnit.Celsius); - -public enum TemperatureUnit -{ - Celsius, - Fahrenheit -} +public enum TemperatureUnit { Celsius, Fahrenheit } ``` - -Append tool information to chat messages. - +Invoke with tool definitions. We using `JsonSchema.Net` for example, you could use any other library to generate JSON schema) ```csharp -var tools = new List() +var tools = new List { new( ToolTypes.Function, new FunctionDefinition( nameof(GetCurrentWeather), - "Get the weather abount given location", + "Get current weather", new JsonSchemaBuilder().FromType().Build())) }; +var history = new List { ChatMessage.User("What's the weather in CA?") }; +var parameters = new TextGenerationParameters { ResultFormat = ResultFormats.Message, Tools = tools }; -var history = new List -{ - ChatMessage.User("What is the weather today in C.A?") -}; - -var parameters = new TextGenerationParamters() -{ - ResultFormat = ResultFormats.Message, - Tools = tools -}; - -// send question with available tools. +// request model var completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenMax, history, parameters); -history.Add(completion.Output.Choice[0].Message); - -// model responding with tool calls. Console.WriteLine(completion.Output.Choice[0].Message.ToolCalls[0].Function.Name); // GetCurrentWeather +history.Add(completion.Output.Choice[0].Message); -// calling tool that model requests and append result into history. -var result = GetCurrentWeather(JsonSerializer.Deserialize(completion.Output.Choice[0].Message.ToolCalls[0].Function.Arguments)); -history.Add(ChatMessage.Tool(result, nameof(GetCurrentWeather))); +// calls tool +var result = GetCurrentWeather(new() { Location = "CA" }); +history.Add(new("tool", result, nameof(GetCurrentWeather))); -// get back answers. +// Get final answer completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenMax, history, parameters); -Console.WriteLine(completion.Output.Choice[0].Message.Content); +Console.WriteLine(completion.Output.Choices[0].Message.Content); // "Current weather in California: Sunny" ``` +#### File Upload (Long Context Models) +For Qwen-Long models: +```csharp +var file = new FileInfo("test.txt"); +var uploadedFile = await dashScopeClient.UploadFileAsync(file.OpenRead(), file.Name); +var history = new List { ChatMessage.File(uploadedFile.Id) }; +var completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenLong, history); +Console.WriteLine(completion.Output.Choices[0].Message.Content); +// Cleanup +await dashScopeClient.DeleteFileAsync(uploadedFile.Id); +``` +### Multimodal +Use `GetMultimodalGenerationAsync`/`GetMultimodalGenerationStreamAsync` +[Official Documentation](https://help.aliyun.com/zh/model-studio/multimodal) -Append the tool calling result with `tool` role, then model will generate answers based on tool calling result. +```csharp +var image = await File.ReadAllBytesAsync("Lenna.jpg"); +var response = dashScopeClient.GetMultimodalGenerationStreamAsync( + new ModelRequest() + { + Model = "qvq-plus", + Input = new MultimodalInput() + { + Messages = + [ + MultimodalMessage.User( + [ + MultimodalMessageContent.ImageContent(image, "image/jpeg"), + MultimodalMessageContent.TextContent("她是谁?") + ]) + ] + }, + Parameters = new MultimodalParameters { IncrementalOutput = true, VlHighResolutionImages = false } + }); + +// output +var reasoning = false; +await foreach (var modelResponse in response) +{ + var choice = modelResponse.Output.Choices.FirstOrDefault(); + if (choice != null) + { + if (choice.FinishReason != "null") + { + break; + } + if (string.IsNullOrEmpty(choice.Message.ReasoningContent) == false) + { + if (reasoning == false) + { + reasoning = true; + Console.WriteLine(""); + } -## QWen-Long with files + Console.Write(choice.Message.ReasoningContent); + continue; + } -Upload file first. + if (reasoning) + { + reasoning = false; + Console.WriteLine(""); + } -```csharp -var file = new FileInfo("test.txt"); -var uploadedFile = await dashScopeClient.UploadFileAsync(file.OpenRead(), file.Name); + Console.Write(choice.Message.Content[0].Text); + } +} ``` +### Text-to-Speech + +Create a speech synthesis session using `dashScopeClient.CreateSpeechSynthesizerSocketSessionAsync()`. -Using uploaded file id in messages. +Note: Use the using statement to automatically dispose the session, or manually call Dispose() to release resources. Avoid reusing sessions. +Create a synthesis session: ```csharp -var history = new List +using var tts = await dashScopeClient.CreateSpeechSynthesizerSocketSessionAsync("cosyvoice-v2"); +var taskId = await tts.RunTaskAsync(new SpeechSynthesizerParameters { Voice = "longxiaochun_v2", Format = "mp3" }); +await tts.ContinueTaskAsync(taskId, "Cnblogs"); +await tts.ContinueTaskAsync(taskId, "Code changes the world"); +await tts.FinishTaskAsync(taskId); +var file = new FileInfo("tts.mp3"); +using var stream = file.OpenWrite(); +await foreach (var b in tts.GetAudioAsync()) { - ChatMessage.File(uploadedFile.Id), // use array for multiple files, e.g. [file1.Id, file2.Id] - ChatMessage.User("Summarize the content of file.") + stream.WriteByte(b); } -var parameters = new TextGenerationParameters() -{ - ResultFormat = ResultFormats.Message -}; -var completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenLong, history, parameters); -Console.WriteLine(completion.Output.Choices[0].Message.Content); +Console.WriteLine($"Audio saved to {file.FullName}"); ``` - -Delete file if needed - +### Image Generation +#### Text-to-Image +Use shortcuts for Wanx models: ```csharp -var deletionResult = await dashScopeClient.DeleteFileAsync(uploadedFile.Id); +var task = await dashScopeClient.CreateWanxImageSynthesisTaskAsync( + WanxModel.WanxV21Turbo, + "A futuristic cityscape at sunset", + new ImageSynthesisParameters { Style = ImageStyles.OilPainting }); +// Pull status +while (true) +{ + var result = await dashScopeClient.GetWanxImageSynthesisTaskAsync(task.TaskId); + if (result.Output.TaskStatus == DashScopeTaskStatus.Succeeded) + { + Console.WriteLine($"Image URL: {result.Output.Results[0].Url}"); + break; + } + await Task.Delay(500); +} ``` +#### Portrait Style Transfer +Use `CreateWanxImageGenerationTaskAsync` and `GetWanxImageGenerationTaskAsync` -## Application call +#### Background Generation -Use `GetApplicationResponseAsync` to call an application. - -Use `GetApplicationResponseStreamAsync` for streaming output. +Use `CreateWanxBackgroundGenerationTaskAsync` and `GetWanxBackgroundGenerationTaskAsync` +### Application Call ```csharp var request = new ApplicationRequest() @@ -283,8 +300,7 @@ var request = var response = await client.GetApplicationResponseAsync("your-application-id", request); Console.WriteLine(response.Output.Text); ``` - -`ApplicationRequest` use an `Dictionary` as `BizParams` by default. +`ApplicationRequest` uses `Dictionary` as the default type for `BizParams`. ```csharp var request = @@ -302,14 +318,13 @@ var request = var response = await client.GetApplicationResponseAsync("your-application-id", request); Console.WriteLine(response.Output.Text); ``` - -You can use the generic version `ApplicationRequest` for strong-typed `BizParams`. But keep in mind that client use `snake_case` by default when doing json serialization, you may need to use `[JsonPropertyName("camelCase")]` for other type of naming policy. +For strong typing support, you can use the generic class `ApplicationRequest`. +Note that the SDK uses `snake_case` for JSON serialization. If your application uses different naming conventions, manually specify the serialized property names using `[JsonPropertyName("camelCase")]`. ```csharp public record TestApplicationBizParam( [property: JsonPropertyName("sourceCode")] string SourceCode); - var request = new ApplicationRequest() { @@ -323,3 +338,18 @@ var response = await client.GetApplicationResponseAsync("your-application-id", r Console.WriteLine(response.Output.Text); ``` +### Text Vectorization + +```csharp +var text = "Sample text for embedding"; +var response = await dashScopeClient.GetTextEmbeddingsAsync( + TextEmbeddingModel.TextEmbeddingV4, + [text], + new TextEmbeddingParameters { Dimension = 512 }); +var embedding = response.Output.Embeddings.First().Embedding; +Console.WriteLine($"Embedding vector length: {embedding.Length}"); +``` + +See [Snapshot Files](./test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.cs) for API parameter examples. + +Review [Tests](./test) for comprehensive usage examples. diff --git a/README.zh-Hans.md b/README.zh-Hans.md index f275d76..aea5642 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -1,18 +1,18 @@ [English](https://github.com/cnblogs/dashscope-sdk/blob/main/README.md) | 简体中文 +# Cnblogs.DashScopeSDK + [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.AI?style=flat&logo=nuget&label=Cnblogs.DashScope.AI)](https://www.nuget.org/packages/Cnblogs.DashScope.AI) [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.Sdk?style=flat&logo=nuget&label=Cnblogs.DashScope.Sdk&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FCnblogs.DashScope.Sdk)](https://www.nuget.org/packages/Cnblogs.DashScope.Sdk) [![NuGet Version](https://img.shields.io/nuget/v/Cnblogs.DashScope.AspNetCore?style=flat&logo=nuget&label=Cnblogs.DashScope.AspNetCore&link=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FCnblogs.DashScope.AspNetCore)](https://www.nuget.org/packages/Cnblogs.DashScope.AspNetCore) -# Cnblogs.DashScopeSDK - 由博客园维护并使用的非官方灵积(百炼)服务 SDK。 使用前注意:当前项目正在积极开发中,小版本也可能包含破坏性更改,升级前请查看对应版本 Release Note 进行迁移。 -# 快速开始 +## 快速开始 -## 使用 `Microsoft.Extensions.AI` 接口 +### 使用 `Microsoft.Extensions.AI` 接口 安装 NuGet 包 `Cnblogs.DashScope.AI` @@ -22,7 +22,7 @@ var completion = await client.CompleteAsync("hello"); Console.WriteLine(completion) ``` -## 控制台应用 +### 控制台应用 安装 NuGet 包 `Cnblogs.DashScope.Sdk`。 @@ -34,7 +34,7 @@ var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); Console.WriteLine(completion.Output.Text); ``` -## ASP.NET Core 应用 +### ASP.NET Core 应用 安装 NuGet 包 `Cnblogs.DashScope.AspNetCore`。 @@ -64,70 +64,22 @@ public class YourService(IDashScopeClient client) } ``` -# 支持的 API +## 支持的 API -- 通用文本向量 - `GetTextEmbeddingsAsync()` -- 通义千问(`qwen-turbo`, `qwen-max` 等) - `GetQWenCompletionAsync()` 和 `GetQWenCompletionStreamAsync()` -- DeepSeek 系列模型(`deepseek-r1`,`deepseek-v3` 等) - `GetDeepSeekChatCompletionAsync()` 和 `GetDeepSeekChatCompletionStreamAsync()` -- 百川开源大模型 - `GetBaiChuanTextCompletionAsync()` -- LLaMa2 大语言模型 - `GetLlama2TextCompletionAsync()` -- 通义千问 VL 和通义千问 Audio(`qwen-vl-max`, `qwen-audio`) - `GetQWenMultimodalCompletionAsync()` 和 `GetQWenMultimodalCompletionStreamAsync()` -- 通义万相系列 - - 文生图 - `CreateWanxImageSynthesisTaskAsync()` 和 `GetWanxImageSynthesisTaskAsync()` - - 人像风格重绘 - `CreateWanxImageGenerationTaskAsync()` 和 `GetWanxImageGenerationTaskAsync()` - - 图像背景生成 - `CreateWanxBackgroundGenerationTaskAsync()` 和 `GetWanxBackgroundGenerationTaskAsync()` -- 适用于 QWen-Long 的文件 API `UploadFileAsync()` 和 `DeleteFileAsync` -- 应用调用 `GetApplicationResponseAsync` 和 `GetApplicationResponseStreamAsync()` -- 其他使用相同 Endpoint 的模型 +- [对话](#对话) - QWen3, DeepSeek 等,支持推理/工具调用/网络搜索/翻译等场景 +- [多模态](#多模态) - QWen-VL,QVQ 等,支持推理/视觉理解/OCR/音频理解等场景 +- [语音合成](#语音合成) - CosyVoice,Sambert 等,支持 TTS 等应用场景 +- [图像生成](#图像生成) - wanx2.1 等,支持文生图,人像风格重绘等应用场景 +- [应用调用](#应用调用) +- [文本向量](#文本向量) -# 示例 - -查看 [Snapshots.cs](./test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs) 获得 API 调用参数示例. - -查看 [测试](./test) 获得更多 API 使用示例。 - -## 文本生成 +### 对话 使用 `dashScopeClient.GetTextCompletionAsync` 和 `dashScopeClient.GetTextCompletionStreamAsync` 来直接访问文本生成接口。 -相关文档:https://help.aliyun.com/zh/model-studio/user-guide/text-generation/ - -```csharp -var completion = await dashScopeClient.GetTextCompletionAsync( - new ModelRequest - { - Model = "your-model-name", - Input = new TextGenerationInput { Prompt = prompt }, - Parameters = new TextGenerationParameters() - { - // control parameters as you wish. - EnableSearch = true - } - }); - -var completions = dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest - { - Model = "your-model-name", - Input = new TextGenerationInput { Messages = [TextChatMessage.System("you are a helpful assistant"), TextChatMessage.User("How are you?")] }, - Parameters = new TextGenerationParameters() - { - // control parameters as you wish. - EnableSearch = true, - IncreamentalOutput = true - } - }); -``` +针对通义千问和 DeekSeek,我们提供了快捷方法进行调用: `GetQWenChatCompletionAsync` /`GetDeepSeekChatCompletionAsync` -## 单轮对话 - -```csharp -var prompt = "你好" -var completion = await client.GetQWenCompletionAsync(QWenLlm.QWenMax, prompt); -Console.WriteLine(completion.Output.Text); -``` - -## 多轮对话 +相关文档:https://help.aliyun.com/zh/model-studio/user-guide/text-generation/ ```csharp var history = new List @@ -144,7 +96,7 @@ var completion = await client.GetQWenChatCompletionAsync(QWenLlm.QWenMax, histor Console.WriteLine(completion.Output.Choices[0].Message.Content); // The number is 42 ``` -## 推理 +#### 推理 使用推理模型时,模型的思考过程可以通过 `ReasoningContent` 属性获取。 @@ -157,7 +109,22 @@ var completion = await client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSee Console.WriteLine(completion.Output.Choices[0]!.Message.ReasoningContent); ``` -## 工具调用 +对于支持的模型(例如 qwen3),可以使用 `TextGenerationParameters.EnableThinking` 决定是否使用模型的推理能力。 + +```csharp +var stream = dashScopeClient + .GetQWenChatStreamAsync( + QWenLlm.QWenPlusLatest, + history, + new TextGenerationParameters + { + IncrementalOutput = true, + ResultFormat = ResultFormats.Message, + EnableThinking = true + }); +``` + +#### 工具调用 创建一个可供模型使用的方法。 @@ -182,7 +149,7 @@ public enum TemperatureUnit } ``` -对话时带上方法的名称、描述和参数列表,参数列表以 JSON Schema 的形式提供。 +对话时带上方法的名称、描述和参数列表,参数列表以 JSON Schema 的形式提供(这里使用 `JsonSchema.Net` 库,您也可以使用其它具有类似功能的库)。 ```csharp var tools = new List() @@ -224,9 +191,9 @@ Console.WriteLine(completion.Output.Choice[0].Message.Content) // 现在浙江 当模型认为应当调用工具时,返回消息中 `ToolCalls` 会提供调用的详情,本地在调用完成后可以把结果以 `tool` 角色返回。 -## 上传文件(QWen-Long) +#### 上传文件(qwen-long) -需要先提前将文件上传到 DashScope 来获得 Id。 +使用长上下文模型时,需要先提前将文件上传到 DashScope 来获得 Id。 ```csharp var file = new FileInfo("test.txt"); @@ -255,7 +222,162 @@ Console.WriteLine(completion.Output.Choices[0].Message.Content); var deletionResult = await dashScopeClient.DeleteFileAsync(uploadedFile.Id); ``` -## 应用调用 +### 多模态 + +使用 `dashScopeClient.GetMultimodalGenerationAsync` 和 `dashScopeClient.GetMultimodalGenerationStreamAsync` 来访问多模态文本生成接口。 + +相关文档:[多模态_大模型服务平台百炼(Model Studio)-阿里云帮助中心](https://help.aliyun.com/zh/model-studio/multimodal) + +#### 视觉理解/推理 + +使用 `MultimodalMessage.User()` 可以快速创建对应角色的消息。 + +媒体内容可以通过公网 URL 或者 `byte[]` 传入。 + +```csharp +var image = await File.ReadAllBytesAsync("Lenna.jpg"); +var response = dashScopeClient.GetMultimodalGenerationStreamAsync( + new ModelRequest() + { + Model = "qvq-plus", + Input = new MultimodalInput() + { + Messages = + [ + MultimodalMessage.User( + [ + MultimodalMessageContent.ImageContent(image, "image/jpeg"), + MultimodalMessageContent.TextContent("她是谁?") + ]) + ] + }, + Parameters = new MultimodalParameters { IncrementalOutput = true, VlHighResolutionImages = false } + }); + +// output +var reasoning = false; +await foreach (var modelResponse in response) +{ + var choice = modelResponse.Output.Choices.FirstOrDefault(); + if (choice != null) + { + if (choice.FinishReason != "null") + { + break; + } + + if (string.IsNullOrEmpty(choice.Message.ReasoningContent) == false) + { + if (reasoning == false) + { + reasoning = true; + Console.WriteLine(""); + } + + Console.Write(choice.Message.ReasoningContent); + continue; + } + + if (reasoning) + { + reasoning = false; + Console.WriteLine(""); + } + + Console.Write(choice.Message.Content[0].Text); + } +} +``` + +### 语音合成 + +通过 `dashScopeClient.CreateSpeechSynthesizerSocketSessionAsync()` 来创建一个语音合成会话。 + +**注意:使用 using 语句来自动释放会话,或者手动 Dispose 会话,尽量不要重用会话。** + +相关文档:[语音合成-CosyVoice_大模型服务平台百炼(Model Studio)-阿里云帮助中心](https://help.aliyun.com/zh/model-studio/cosyvoice-large-model-for-speech-synthesis) + +```csharp +using var tts = await dashScopeClient.CreateSpeechSynthesizerSocketSessionAsync("cosyvoice-v2"); +var taskId = await tts.RunTaskAsync( + new SpeechSynthesizerParameters { Voice = "longxiaochun_v2", Format = "mp3" }); +await tts.ContinueTaskAsync(taskId, "博客园"); +await tts.ContinueTaskAsync(taskId, "代码改变世界"); +await tts.FinishTaskAsync(taskId); +var file = new FileInfo("tts.mp3"); +using var stream = file.OpenWrite(); +await foreach (var b in tts.GetAudioAsync()) +{ + stream.WriteByte(b); +} + +stream.Close(); + +var tokenUsage = 0; +await foreach (var message in tts.GetMessagesAsync()) +{ + if (message.Payload.Usage?.Characters > tokenUsage) + { + tokenUsage = message.Payload.Usage.Characters; + } +} + +Console.WriteLine($"audio saved to {file.FullName}, token usage: {tokenUsage}"); +break; +``` + +### 图像生成 + +#### 文生图 + +我们针对通义万相提供了快捷 API `dashScopeClient.CreateWanxImageSynthesisTaskAsync()` 和 `GetWanxImageSynthesisTaskAsync()`。 + +图片生成需要数秒到数十秒不等,对于 HTTP 请求来说太长,需要通过任务方式生成。 + +先使用 `CreateWanxImageSynthesisTaskAsync()` 创建任务,再轮询 `GetWanxImageSynthesisTaskAsync()` 检查任务完成状态。 + +相关文档:[通义万相2.1文生图V2版API参考_大模型服务平台百炼(Model Studio)-阿里云帮助中心](https://help.aliyun.com/zh/model-studio/text-to-image-v2-api-reference) + +```csharp +var prompt = Console.ReadLine(); +var task = await dashScopeClient.CreateWanxImageSynthesisTaskAsync( + WanxModel.WanxV21Turbo, + prompt, + null, + new ImageSynthesisParameters { Style = ImageStyles.OilPainting }); +Console.WriteLine($"Task({task.TaskId}) submitted, checking status..."); +var watch = Stopwatch.StartNew(); +while (watch.Elapsed.TotalSeconds < 120) +{ + var result = await dashScopeClient.GetWanxImageSynthesisTaskAsync(task.TaskId); + Console.WriteLine($"{watch.ElapsedMilliseconds}ms - Status: {result.Output.TaskStatus}"); + if (result.Output.TaskStatus == DashScopeTaskStatus.Succeeded) + { + Console.WriteLine($"Image generation finished, URL: {result.Output.Results![0].Url}"); + return; + } + + if (result.Output.TaskStatus == DashScopeTaskStatus.Failed) + { + Console.WriteLine($"Image generation failed, error message: {result.Output.Message}"); + return; + } + + await Task.Delay(500); +} + +Console.WriteLine($"Task timout, taskId: {task.TaskId}"); +``` + +#### 人像风格重绘和图像背景生成 + +与文生图类似,先创建任务,再轮询状态。 + +人像风格重绘 - `CreateWanxImageGenerationTaskAsync` 和 `GetWanxImageGenerationTaskAsync` + +图像背景生成 - `CreateWanxBackgroundGenerationTaskAsync` 和 `GetWanxBackgroundGenerationTaskAsync` + +### 应用调用 `GetApplicationResponseAsync` 用于进行应用调用。 @@ -322,3 +444,25 @@ var request = var response = await client.GetApplicationResponseAsync("your-application-id", request); Console.WriteLine(response.Output.Text); ``` + +### 文本向量 + +使用 `GetTextEmbeddingsAsync` 来调用文本向量接口。 + +相关文档:[通用文本向量同步接口API详情_大模型服务平台百炼(Model Studio)-阿里云帮助中心](https://help.aliyun.com/zh/model-studio/text-embedding-synchronous-api) + +```csharp +var text = Console.ReadLine(); +var response = await dashScopeClient.GetTextEmbeddingsAsync( + TextEmbeddingModel.TextEmbeddingV4, + [text], + new TextEmbeddingParameters() { Dimension = 512, }); +var array = response.Output.Embeddings.First().Embedding; +Console.WriteLine("Embedding"); +Console.WriteLine(string.Join('\n', array)); +Console.WriteLine($"Token usage: {response.Usage?.TotalTokens}"); +``` + +查看 [快照文件](./test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.cs) 获得 API 调用参数示例. + +查看 [测试](./test) 获得更多 API 使用示例。 diff --git a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj index 6fcdad9..ef379a0 100644 --- a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj +++ b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj @@ -1,26 +1,29 @@  - - Exe - net8.0 - enable - enable - false - + + Exe + net8.0 + enable + enable + false + - - - - + + + + - - - Always - - + + + Always + + + PreserveNewest + + - - - + + + diff --git a/sample/Cnblogs.DashScope.Sample/Lenna.jpg b/sample/Cnblogs.DashScope.Sample/Lenna.jpg new file mode 100644 index 0000000..4030eed Binary files /dev/null and b/sample/Cnblogs.DashScope.Sample/Lenna.jpg differ diff --git a/sample/Cnblogs.DashScope.Sample/Program.cs b/sample/Cnblogs.DashScope.Sample/Program.cs index 8841af4..a0aa669 100644 --- a/sample/Cnblogs.DashScope.Sample/Program.cs +++ b/sample/Cnblogs.DashScope.Sample/Program.cs @@ -1,15 +1,19 @@ -using System.Text; +using System.Diagnostics; +using System.Text; using System.Text.Json; using Cnblogs.DashScope.Core; using Cnblogs.DashScope.Sample; using Cnblogs.DashScope.Sdk; using Cnblogs.DashScope.Sdk.QWen; +using Cnblogs.DashScope.Sdk.TextEmbedding; +using Cnblogs.DashScope.Sdk.Wanx; using Json.Schema; using Json.Schema.Generation; using Microsoft.Extensions.AI; Console.WriteLine("Reading key from environment variable DASHSCOPE_KEY"); -var apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY"); +var apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_KEY", EnvironmentVariableTarget.Process) + ?? Environment.GetEnvironmentVariable("DASHSCOPE_KEY", EnvironmentVariableTarget.User); if (string.IsNullOrEmpty(apiKey)) { Console.Write("ApiKey > "); @@ -32,12 +36,12 @@ switch (type) { case SampleType.TextCompletion: - Console.WriteLine("Prompt > "); + Console.Write("Prompt > "); userInput = Console.ReadLine()!; await TextCompletionAsync(userInput); break; case SampleType.TextCompletionSse: - Console.WriteLine("Prompt > "); + Console.Write("Prompt > "); userInput = Console.ReadLine()!; await TextCompletionStreamAsync(userInput); break; @@ -47,9 +51,15 @@ case SampleType.ChatCompletionWithTool: await ChatWithToolsAsync(); break; + case SampleType.MultimodalCompletion: + await ChatWithImageAsync(); + break; case SampleType.ChatCompletionWithFiles: await ChatWithFilesAsync(); break; + case SampleType.Text2Image: + await Text2ImageAsync(); + break; case SampleType.MicrosoftExtensionsAi: await ChatWithMicrosoftExtensions(); break; @@ -63,6 +73,54 @@ userInput = Console.ReadLine()!; await ApplicationCallAsync(applicationId, userInput); break; + case SampleType.TextToSpeech: + { + using var tts = await dashScopeClient.CreateSpeechSynthesizerSocketSessionAsync("cosyvoice-v2"); + var taskId = await tts.RunTaskAsync( + new SpeechSynthesizerParameters { Voice = "longxiaochun_v2", Format = "mp3" }); + await tts.ContinueTaskAsync(taskId, "博客园"); + await tts.ContinueTaskAsync(taskId, "代码改变世界"); + await tts.FinishTaskAsync(taskId); + var file = new FileInfo("tts.mp3"); + await using var stream = file.OpenWrite(); + await foreach (var b in tts.GetAudioAsync()) + { + stream.WriteByte(b); + } + + stream.Close(); + + var tokenUsage = 0; + await foreach (var message in tts.GetMessagesAsync()) + { + if (message.Payload.Usage?.Characters > tokenUsage) + { + tokenUsage = message.Payload.Usage.Characters; + } + } + + Console.WriteLine($"audio saved to {file.FullName}, token usage: {tokenUsage}"); + break; + } + + case SampleType.TextEmbedding: + Console.Write("text> "); + var text = Console.ReadLine(); + if (string.IsNullOrEmpty(text)) + { + text = "Coding changes world"; + Console.WriteLine($"using default text: {text}"); + } + + var response = await dashScopeClient.GetTextEmbeddingsAsync( + TextEmbeddingModel.TextEmbeddingV3, + [text], + new TextEmbeddingParameters() { Dimension = 512, }); + var array = response.Output.Embeddings.First().Embedding; + Console.WriteLine("Embedding"); + Console.WriteLine(string.Join('\n', array)); + Console.WriteLine($"Token usage: {response.Usage?.TotalTokens}"); + break; } return; @@ -97,9 +155,14 @@ async Task ChatStreamAsync() history.Add(TextChatMessage.User(input)); var stream = dashScopeClient .GetQWenChatStreamAsync( - QWenLlm.QWenMax, + QWenLlm.QWenPlusLatest, history, - new TextGenerationParameters { IncrementalOutput = true, ResultFormat = ResultFormats.Message }); + new TextGenerationParameters + { + IncrementalOutput = true, + ResultFormat = ResultFormats.Message, + EnableThinking = true + }); var role = string.Empty; var message = new StringBuilder(); await foreach (var modelResponse in stream) @@ -112,7 +175,10 @@ async Task ChatStreamAsync() } message.Append(chunk.Message.Content); - Console.Write(chunk.Message.Content); + var write = string.IsNullOrEmpty(chunk.Message.ReasoningContent) + ? chunk.Message.Content + : chunk.Message.ReasoningContent; + Console.Write(write); } Console.WriteLine(); @@ -122,6 +188,60 @@ async Task ChatStreamAsync() // ReSharper disable once FunctionNeverReturns } +async Task ChatWithImageAsync() +{ + var image = await File.ReadAllBytesAsync("Lenna.jpg"); + var response = dashScopeClient.GetMultimodalGenerationStreamAsync( + new ModelRequest() + { + Model = "qvq-plus", + Input = new MultimodalInput() + { + Messages = + [ + MultimodalMessage.User( + [ + MultimodalMessageContent.ImageContent(image, "image/jpeg"), + MultimodalMessageContent.TextContent("她是谁?") + ]) + ] + }, + Parameters = new MultimodalParameters { IncrementalOutput = true, VlHighResolutionImages = false } + }); + var reasoning = false; + await foreach (var modelResponse in response) + { + var choice = modelResponse.Output.Choices.FirstOrDefault(); + if (choice != null) + { + if (choice.FinishReason != "null") + { + break; + } + + if (string.IsNullOrEmpty(choice.Message.ReasoningContent) == false) + { + if (reasoning == false) + { + reasoning = true; + Console.WriteLine(""); + } + + Console.Write(choice.Message.ReasoningContent); + continue; + } + + if (reasoning) + { + reasoning = false; + Console.WriteLine(""); + } + + Console.Write(choice.Message.Content[0].Text); + } + } +} + async Task ChatWithFilesAsync() { var history = new List(); @@ -177,7 +297,7 @@ async Task ChatWithToolsAsync() "获得当前天气", new JsonSchemaBuilder().FromType().Build())) }; - var chatParameters = new TextGenerationParameters() { ResultFormat = ResultFormats.Message, Tools = tools }; + var chatParameters = new TextGenerationParameters { ResultFormat = ResultFormats.Message, Tools = tools }; var question = TextChatMessage.User("请问现在杭州的天气如何?"); history.Add(question); Console.WriteLine($"{question.Role} > {question.Content}"); @@ -214,18 +334,54 @@ async Task ChatWithMicrosoftExtensions() Console.WriteLine("Requesting model..."); var chatClient = dashScopeClient.AsChatClient("qwen-max"); List conversation = - [ - new(ChatRole.System, "You are a helpful AI assistant"), - new(ChatRole.User, "What is AI?") - ]; + new() { new(ChatRole.System, "You are a helpful AI assistant"), new(ChatRole.User, "What is AI?") }; var response = await chatClient.GetResponseAsync(conversation); var serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web) { WriteIndented = true }; Console.WriteLine(JsonSerializer.Serialize(response, serializerOptions)); } +async Task Text2ImageAsync() +{ + Console.Write("Prompt> "); + var prompt = Console.ReadLine(); + if (string.IsNullOrEmpty(prompt)) + { + Console.WriteLine("Using sample prompt"); + prompt = "A fluffy cat"; + } + + var task = await dashScopeClient.CreateWanxImageSynthesisTaskAsync( + WanxModel.WanxV21Turbo, + prompt, + null, + new ImageSynthesisParameters { Style = ImageStyles.OilPainting }); + Console.WriteLine($"Task({task.TaskId}) submitted, checking status..."); + var watch = Stopwatch.StartNew(); + while (watch.Elapsed.TotalSeconds < 120) + { + var result = await dashScopeClient.GetWanxImageSynthesisTaskAsync(task.TaskId); + Console.WriteLine($"{watch.ElapsedMilliseconds}ms - Status: {result.Output.TaskStatus}"); + if (result.Output.TaskStatus == DashScopeTaskStatus.Succeeded) + { + Console.WriteLine($"Image generation finished, URL: {result.Output.Results![0].Url}"); + return; + } + + if (result.Output.TaskStatus == DashScopeTaskStatus.Failed) + { + Console.WriteLine($"Image generation failed, error message: {result.Output.Message}"); + return; + } + + await Task.Delay(500); + } + + Console.WriteLine($"Task timout, taskId: {task.TaskId}"); +} + async Task ApplicationCallAsync(string applicationId, string prompt) { - var request = new ApplicationRequest() { Input = new ApplicationInput() { Prompt = prompt } }; + var request = new ApplicationRequest { Input = new ApplicationInput { Prompt = prompt } }; var response = await dashScopeClient.GetApplicationResponseAsync(applicationId, request); Console.WriteLine(response.Output.Text); } diff --git a/sample/Cnblogs.DashScope.Sample/SampleType.cs b/sample/Cnblogs.DashScope.Sample/SampleType.cs index feddf79..c78d94a 100644 --- a/sample/Cnblogs.DashScope.Sample/SampleType.cs +++ b/sample/Cnblogs.DashScope.Sample/SampleType.cs @@ -12,9 +12,17 @@ public enum SampleType ChatCompletionWithFiles, + MultimodalCompletion, + + Text2Image, + MicrosoftExtensionsAi, MicrosoftExtensionsAiToolCall, - ApplicationCall + ApplicationCall, + + TextToSpeech, + + TextEmbedding } diff --git a/sample/Cnblogs.DashScope.Sample/SampleTypeDescriptor.cs b/sample/Cnblogs.DashScope.Sample/SampleTypeDescriptor.cs index 26988a5..2cd398a 100644 --- a/sample/Cnblogs.DashScope.Sample/SampleTypeDescriptor.cs +++ b/sample/Cnblogs.DashScope.Sample/SampleTypeDescriptor.cs @@ -11,9 +11,13 @@ public static string GetDescription(this SampleType sampleType) SampleType.ChatCompletion => "Conversation between user and assistant", SampleType.ChatCompletionWithTool => "Function call sample", SampleType.ChatCompletionWithFiles => "File upload sample using qwen-long", + SampleType.MultimodalCompletion => "Multimodal completion", + SampleType.Text2Image => "Text to Image generation", SampleType.MicrosoftExtensionsAi => "Use with Microsoft.Extensions.AI", SampleType.MicrosoftExtensionsAiToolCall => "Use tool call with Microsoft.Extensions.AI interfaces", SampleType.ApplicationCall => "Call pre-defined application", + SampleType.TextToSpeech => "TTS task", + SampleType.TextEmbedding => "Get text embedding", _ => throw new ArgumentOutOfRangeException(nameof(sampleType), sampleType, "Unsupported sample option") }; } diff --git a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs index 0c30cd4..72ccc1e 100644 --- a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs +++ b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs @@ -12,7 +12,7 @@ public static async Task ToolCallWithExtensionAsync(this IDashScopeClient dashSc [Description("Gets the weather")] string GetWeather(string location) => Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining"; - var chatOptions = new ChatOptions { Tools = [AIFunctionFactory.Create(GetWeather)] }; + var chatOptions = new ChatOptions { Tools = new List { AIFunctionFactory.Create(GetWeather) } }; var client = dashScopeClient.AsChatClient("qwen-max").AsBuilder().UseFunctionInvocation().Build(); await foreach (var message in client.GetStreamingResponseAsync("What is weather of LA today?", chatOptions)) diff --git a/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj b/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj index a92e8fc..5e45397 100644 --- a/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj +++ b/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj @@ -1,5 +1,6 @@  + net8.0 Cnblogs.DashScope.AI true Cnblogs;Dashscope;Microsoft.Extensions.AI;Sdk;Embedding; @@ -10,7 +11,8 @@ - + + diff --git a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs index 11b86af..c8a0d0f 100644 --- a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs +++ b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using System.Text.Json; using Cnblogs.DashScope.Core; using Cnblogs.DashScope.Sdk; @@ -17,7 +17,7 @@ public sealed class DashScopeChatClient : IChatClient private readonly string _modelId; private static readonly JsonSchema EmptyObjectSchema = - JsonSchema.FromText("""{"type":"object","required":[],"properties":{}}"""); + JsonSchema.FromText("{\"type\":\"object\",\"required\":[],\"properties\":{}}"); private static readonly TextGenerationParameters DefaultTextGenerationParameter = new() { ResultFormat = "message" }; @@ -55,7 +55,7 @@ public async Task GetResponseAsync( if (useVl) { var response = await _dashScopeClient.GetMultimodalGenerationAsync( - new ModelRequest() + new ModelRequest { Input = new MultimodalInput { Messages = ToMultimodalMessages(chatMessages) }, Parameters = ToMultimodalParameters(options), @@ -63,7 +63,7 @@ public async Task GetResponseAsync( }, cancellationToken); - var returnMessage = new ChatMessage() + var returnMessage = new ChatMessage { RawRepresentation = response, Role = ToChatRole(response.Output.Choices[0].Message.Role), }; @@ -80,7 +80,7 @@ public async Task GetResponseAsync( if (response.Usage != null) { - completion.Usage = new UsageDetails() + completion.Usage = new UsageDetails { InputTokenCount = response.Usage.InputTokens, OutputTokenCount = response.Usage.OutputTokens, }; @@ -92,7 +92,7 @@ public async Task GetResponseAsync( { var parameters = ToTextGenerationParameters(options) ?? DefaultTextGenerationParameter; var response = await _dashScopeClient.GetTextCompletionAsync( - new ModelRequest() + new ModelRequest { Input = new TextGenerationInput { @@ -116,7 +116,7 @@ public async Task GetResponseAsync( if (response.Usage != null) { - completion.Usage = new UsageDetails() + completion.Usage = new UsageDetails { InputTokenCount = response.Usage.InputTokens, OutputTokenCount = response.Usage.OutputTokens, @@ -147,7 +147,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( var parameter = ToMultimodalParameters(options); parameter.IncrementalOutput = true; var stream = _dashScopeClient.GetMultimodalGenerationStreamAsync( - new ModelRequest() + new ModelRequest { Input = new MultimodalInput { Messages = ToMultimodalMessages(chatMessages) }, Parameters = parameter, @@ -164,7 +164,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( : ToFinishReason(response.Output.Choices[0].FinishReason); completionId ??= response.RequestId; - var update = new ChatResponseUpdate() + var update = new ChatResponseUpdate { ResponseId = completionId, CreatedAt = DateTimeOffset.Now, @@ -199,7 +199,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( { // qwen does not support streaming with function call, fallback to non-streaming var completion = await GetResponseAsync(chatMessages, options, cancellationToken); - yield return new ChatResponseUpdate() + yield return new ChatResponseUpdate { ResponseId = completion.ResponseId, Role = completion.Messages[0].Role, @@ -216,7 +216,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( var parameters = ToTextGenerationParameters(options) ?? DefaultTextGenerationParameter; parameters.IncrementalOutput = true; var stream = _dashScopeClient.GetTextCompletionStreamAsync( - new ModelRequest() + new ModelRequest { Input = new TextGenerationInput { @@ -238,7 +238,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( : ToFinishReason(response.Output.Choices[0].FinishReason); completionId ??= response.RequestId; - var update = new ChatResponseUpdate() + var update = new ChatResponseUpdate { ResponseId = completionId, CreatedAt = DateTimeOffset.Now, @@ -257,7 +257,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( { update.Contents.Add( new UsageContent( - new UsageDetails() + new UsageDetails { InputTokenCount = response.Usage.InputTokens, OutputTokenCount = response.Usage.OutputTokens, @@ -299,7 +299,7 @@ public void Dispose() private static ChatMessage ToChatMessage(TextChatMessage message) { - var returnMessage = new ChatMessage() + var returnMessage = new ChatMessage { RawRepresentation = message, Role = ToChatRole(message.Role), }; @@ -485,7 +485,7 @@ private IEnumerable ToTextChatMessages( format = "json_object"; } - return new TextGenerationParameters() + return new TextGenerationParameters { ResultFormat = format, Temperature = options.Temperature, @@ -503,7 +503,8 @@ private IEnumerable ToTextChatMessages( RequiredChatToolMode required when string.IsNullOrEmpty(required.RequiredFunctionName) == false => ToolChoice.FunctionChoice(required.RequiredFunctionName), _ => ToolChoice.AutoChoice - } + }, + ParallelToolCalls = options.AllowMultipleToolCalls, }; } diff --git a/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs b/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs index 06c28d7..f735844 100644 --- a/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs +++ b/src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs @@ -44,7 +44,7 @@ public async Task>> GenerateAsync( e => new Embedding(e.Embedding) { ModelId = _modelId, CreatedAt = DateTimeOffset.Now }); var rawUsage = rawResponse.Usage; var usage = rawUsage != null - ? new UsageDetails() { InputTokenCount = rawUsage.TotalTokens, TotalTokenCount = rawUsage.TotalTokens } + ? new UsageDetails { InputTokenCount = rawUsage.TotalTokens, TotalTokenCount = rawUsage.TotalTokens } : null; return new GeneratedEmbeddings>(embeddings) { diff --git a/src/Cnblogs.DashScope.AspNetCore/Assembly.cs b/src/Cnblogs.DashScope.AspNetCore/Assembly.cs new file mode 100644 index 0000000..b79c4ed --- /dev/null +++ b/src/Cnblogs.DashScope.AspNetCore/Assembly.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly:InternalsVisibleTo("Cnblogs.DashScope.Sdk.UnitTests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/Cnblogs.DashScope.AspNetCore/Cnblogs.DashScope.AspNetCore.csproj b/src/Cnblogs.DashScope.AspNetCore/Cnblogs.DashScope.AspNetCore.csproj index 1ab06a5..ba30d5f 100644 --- a/src/Cnblogs.DashScope.AspNetCore/Cnblogs.DashScope.AspNetCore.csproj +++ b/src/Cnblogs.DashScope.AspNetCore/Cnblogs.DashScope.AspNetCore.csproj @@ -3,7 +3,8 @@ Cnblogs.DashScopeSDK true - Cnblogs;Dashscope;AI;Sdk;Embedding;AspNetCore + Cnblogs;Dashscope;AI;Sdk;Embedding;AspNetCore;Bailian + Cnblogs.DashScope.AspNetCore diff --git a/src/Cnblogs.DashScope.AspNetCore/DashScopeAspNetCoreDefaults.cs b/src/Cnblogs.DashScope.AspNetCore/DashScopeAspNetCoreDefaults.cs new file mode 100644 index 0000000..1cdbb63 --- /dev/null +++ b/src/Cnblogs.DashScope.AspNetCore/DashScopeAspNetCoreDefaults.cs @@ -0,0 +1,6 @@ +namespace Cnblogs.DashScope.AspNetCore; + +internal static class DashScopeAspNetCoreDefaults +{ + public const string DefaultHttpClientName = "Cnblogs.DashScope.Http"; +} diff --git a/src/Cnblogs.DashScope.AspNetCore/DashScopeClientAspNetCore.cs b/src/Cnblogs.DashScope.AspNetCore/DashScopeClientAspNetCore.cs new file mode 100644 index 0000000..be4a685 --- /dev/null +++ b/src/Cnblogs.DashScope.AspNetCore/DashScopeClientAspNetCore.cs @@ -0,0 +1,20 @@ +using Cnblogs.DashScope.Core; + +namespace Cnblogs.DashScope.AspNetCore; + +/// +/// The with DI and options pattern support. +/// +public class DashScopeClientAspNetCore + : DashScopeClientCore +{ + /// + /// The with DI and options pattern support. + /// + /// The factory to create . + /// The socket pool for WebSocket API calls. + public DashScopeClientAspNetCore(IHttpClientFactory factory, DashScopeClientWebSocketPool pool) + : base(factory.CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName), pool) + { + } +} diff --git a/src/Cnblogs.DashScope.AspNetCore/ServiceCollectionInjector.cs b/src/Cnblogs.DashScope.AspNetCore/ServiceCollectionInjector.cs index ee6b00a..8b521f0 100644 --- a/src/Cnblogs.DashScope.AspNetCore/ServiceCollectionInjector.cs +++ b/src/Cnblogs.DashScope.AspNetCore/ServiceCollectionInjector.cs @@ -1,6 +1,9 @@ using System.Net.Http.Headers; +using Cnblogs.DashScope.AspNetCore; using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Core.Internals; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection; @@ -37,9 +40,10 @@ public static IHttpClientBuilder AddDashScopeClient(this IServiceCollection serv { var apiKey = section["apiKey"] ?? throw new InvalidOperationException("There is no apiKey provided in given section"); - var baseAddress = section["baseAddress"]; + var baseAddress = section["baseAddress"] ?? DashScopeDefaults.HttpApiBaseAddress; var workspaceId = section["workspaceId"]; - return services.AddDashScopeClient(apiKey, baseAddress, workspaceId); + services.Configure(section); + return services.AddDashScopeHttpClient(apiKey, baseAddress, workspaceId); } /// @@ -48,16 +52,49 @@ public static IHttpClientBuilder AddDashScopeClient(this IServiceCollection serv /// The service collection to add service to. /// The DashScope api key. /// The DashScope api base address, you may change this value if you are using proxy. + /// The DashScope websocket base address, you may want to change this value if use are using proxy. /// Default workspace id to use. /// public static IHttpClientBuilder AddDashScopeClient( this IServiceCollection services, string apiKey, string? baseAddress = null, + string? baseWebsocketAddress = null, string? workspaceId = null) { - baseAddress ??= "https://dashscope.aliyuncs.com/api/v1/"; - return services.AddHttpClient( + services.Configure(o => + { + o.ApiKey = apiKey; + if (baseAddress != null) + { + o.BaseAddress = baseAddress; + } + + if (baseWebsocketAddress != null) + { + o.WebsocketBaseAddress = baseWebsocketAddress; + } + + o.WorkspaceId = workspaceId; + }); + + return services.AddDashScopeHttpClient(apiKey, baseAddress, workspaceId); + } + + private static IHttpClientBuilder AddDashScopeHttpClient( + this IServiceCollection services, + string apiKey, + string? baseAddress, + string? workspaceId) + { + services.AddSingleton(); + services.AddSingleton(sp + => new DashScopeClientWebSocketPool( + sp.GetRequiredService(), + sp.GetRequiredService>().Value)); + services.AddScoped(); + return services.AddHttpClient( + DashScopeAspNetCoreDefaults.DefaultHttpClientName, h => { h.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); @@ -66,7 +103,7 @@ public static IHttpClientBuilder AddDashScopeClient( h.DefaultRequestHeaders.Add("X-DashScope-WorkSpace", workspaceId); } - h.BaseAddress = new Uri(baseAddress); + h.BaseAddress = new Uri(baseAddress ?? DashScopeDefaults.HttpApiBaseAddress); }); } } diff --git a/src/Cnblogs.DashScope.Core/ApplicationInput.cs b/src/Cnblogs.DashScope.Core/ApplicationInput.cs index 965124b..fc537e6 100644 --- a/src/Cnblogs.DashScope.Core/ApplicationInput.cs +++ b/src/Cnblogs.DashScope.Core/ApplicationInput.cs @@ -44,4 +44,6 @@ public class ApplicationInput /// /// Inputs for application call. /// -public class ApplicationInput : ApplicationInput>; +public class ApplicationInput : ApplicationInput> +{ +} diff --git a/src/Cnblogs.DashScope.Core/ApplicationRequest.cs b/src/Cnblogs.DashScope.Core/ApplicationRequest.cs index bdafef5..c1980e7 100644 --- a/src/Cnblogs.DashScope.Core/ApplicationRequest.cs +++ b/src/Cnblogs.DashScope.Core/ApplicationRequest.cs @@ -13,7 +13,7 @@ public class ApplicationRequest : IDashScopeWorkspaceConfig /// /// Content of this call. /// - public required ApplicationInput Input { get; set; } + public ApplicationInput Input { get; set; } = new(); /// /// Optional configurations. @@ -30,4 +30,6 @@ public class ApplicationRequest : IDashScopeWorkspaceConfig /// /// Request body for an application call with dictionary biz_content. /// -public class ApplicationRequest : ApplicationRequest>; +public class ApplicationRequest : ApplicationRequest> +{ +} diff --git a/src/Cnblogs.DashScope.Core/BackgroundGenerationInput.cs b/src/Cnblogs.DashScope.Core/BackgroundGenerationInput.cs index bd820dc..dd5b2b3 100644 --- a/src/Cnblogs.DashScope.Core/BackgroundGenerationInput.cs +++ b/src/Cnblogs.DashScope.Core/BackgroundGenerationInput.cs @@ -8,7 +8,7 @@ public class BackgroundGenerationInput /// /// The image url to generation background on. /// - public required string BaseImageUrl { get; set; } + public string BaseImageUrl { get; set; } = string.Empty; /// /// The reference image url for. diff --git a/src/Cnblogs.DashScope.Core/BatchGetEmbeddingsInput.cs b/src/Cnblogs.DashScope.Core/BatchGetEmbeddingsInput.cs index b9ab6e0..36b04cd 100644 --- a/src/Cnblogs.DashScope.Core/BatchGetEmbeddingsInput.cs +++ b/src/Cnblogs.DashScope.Core/BatchGetEmbeddingsInput.cs @@ -8,5 +8,5 @@ public class BatchGetEmbeddingsInput /// /// The url of text file to compute embeddings from. /// - public required string Url { get; set; } + public string Url { get; set; } = string.Empty; } diff --git a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj index 791029d..f337ae6 100644 --- a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj +++ b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj @@ -3,16 +3,17 @@ Cnblogs.DashScopeSDK true - Cnblogs;Dashscope;AI;Sdk;Embedding; + Cnblogs;Dashscope;AI;Sdk;Embedding;Bailian; Provide pure api access to DashScope without extra references. Cnblogs.DashScope.Sdk should be used for general purpose. - + - + + - + diff --git a/src/Cnblogs.DashScope.Core/DashScopeClient.cs b/src/Cnblogs.DashScope.Core/DashScopeClient.cs index dea20f9..1d1b0ca 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeClient.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeClient.cs @@ -9,14 +9,17 @@ namespace Cnblogs.DashScope.Core; public class DashScopeClient : DashScopeClientCore { private static readonly Dictionary ClientPools = new(); + private static readonly Dictionary SocketPools = new(); /// /// Creates a DashScopeClient for further api call. /// /// The DashScope api key. /// The timeout for internal http client, defaults to 2 minute. - /// The base address for dashscope api call. + /// The base address for DashScope api call. + /// The base address for DashScope websocket api call. /// The workspace id. + /// Maximum size of socket pool. /// /// The underlying httpclient is cached by constructor parameter list. /// Client created with same parameter value will share same underlying instance. @@ -24,10 +27,42 @@ public class DashScopeClient : DashScopeClientCore public DashScopeClient( string apiKey, TimeSpan? timeout = null, - string? baseAddress = null, + string baseAddress = DashScopeDefaults.HttpApiBaseAddress, + string baseWebsocketAddress = DashScopeDefaults.WebsocketApiBaseAddress, + string? workspaceId = null, + int socketPoolSize = 32) + : base( + GetConfiguredClient(apiKey, timeout, baseAddress, workspaceId), + GetConfiguredSocketPool(apiKey, baseWebsocketAddress, socketPoolSize, workspaceId)) + { + } + + private static DashScopeClientWebSocketPool GetConfiguredSocketPool( + string apiKey, + string baseAddress, + int socketPoolSize, string? workspaceId = null) - : base(GetConfiguredClient(apiKey, timeout, baseAddress, workspaceId)) { + var key = GetCacheKey(); + + var pool = SocketPools.GetValueOrDefault(key); + if (pool is null) + { + pool = new DashScopeClientWebSocketPool( + new DashScopeClientWebSocketFactory(), + new DashScopeOptions + { + ApiKey = apiKey, + WebsocketBaseAddress = baseAddress, + SocketPoolSize = socketPoolSize, + WorkspaceId = workspaceId + }); + SocketPools.Add(key, pool); + } + + return pool; + + string GetCacheKey() => $"{apiKey}-{socketPoolSize}-{baseAddress}-{workspaceId}"; } private static HttpClient GetConfiguredClient( @@ -41,7 +76,7 @@ private static HttpClient GetConfiguredClient( { client = new HttpClient { - BaseAddress = new Uri(baseAddress ?? DashScopeDefaults.DashScopeApiBaseAddress), + BaseAddress = new Uri(baseAddress ?? DashScopeDefaults.HttpApiBaseAddress), Timeout = timeout ?? TimeSpan.FromMinutes(2) }; diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs b/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs index 7cca41f..997ef63 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs @@ -4,7 +4,6 @@ using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; -using System.Text.Json.Serialization; using Cnblogs.DashScope.Core.Internals; namespace Cnblogs.DashScope.Core; @@ -14,22 +13,18 @@ namespace Cnblogs.DashScope.Core; /// public class DashScopeClientCore : IDashScopeClient { - private static readonly JsonSerializerOptions SerializationOptions = - new() - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, - }; - private readonly HttpClient _httpClient; + private readonly DashScopeClientWebSocketPool _socketPool; /// /// For DI container to inject pre-configured httpclient. /// /// Pre-configured httpclient. - public DashScopeClientCore(HttpClient httpClient) + /// Websocket pool. + public DashScopeClientCore(HttpClient httpClient, DashScopeClientWebSocketPool pool) { _httpClient = httpClient; + _socketPool = pool; } /// @@ -283,6 +278,15 @@ public async Task DeleteFileAsync( return (await SendCompatibleAsync(request, cancellationToken))!; } + /// + public async Task CreateSpeechSynthesizerSocketSessionAsync( + string modelId, + CancellationToken cancellationToken = default) + { + var socket = await _socketPool.RentSocketAsync(cancellationToken); + return new SpeechSynthesizerSocketSession(socket, modelId); + } + private static HttpRequestMessage BuildSseRequest(HttpMethod method, string url, TPayload payload) where TPayload : class { @@ -304,7 +308,9 @@ private static HttpRequestMessage BuildRequest( { var message = new HttpRequestMessage(method, url) { - Content = payload != null ? JsonContent.Create(payload, options: SerializationOptions) : null + Content = payload != null + ? JsonContent.Create(payload, options: DashScopeDefaults.SerializationOptions) + : null }; if (sse) @@ -332,7 +338,7 @@ private static HttpRequestMessage BuildRequest( { var response = await GetSuccessResponseAsync( message, - r => new DashScopeError() + r => new DashScopeError { Code = r.Error.Type, Message = r.Error.Message, @@ -340,7 +346,9 @@ private static HttpRequestMessage BuildRequest( }, HttpCompletionOption.ResponseContentRead, cancellationToken); - return await response.Content.ReadFromJsonAsync(SerializationOptions, cancellationToken); + return await response.Content.ReadFromJsonAsync( + DashScopeDefaults.SerializationOptions, + cancellationToken); } private async Task SendAsync(HttpRequestMessage message, CancellationToken cancellationToken) @@ -350,7 +358,9 @@ private static HttpRequestMessage BuildRequest( message, HttpCompletionOption.ResponseContentRead, cancellationToken); - return await response.Content.ReadFromJsonAsync(SerializationOptions, cancellationToken); + return await response.Content.ReadFromJsonAsync( + DashScopeDefaults.SerializationOptions, + cancellationToken); } private async IAsyncEnumerable StreamAsync( @@ -367,13 +377,14 @@ private async IAsyncEnumerable StreamAsync( if (cancellationToken.IsCancellationRequested) throw new TaskCanceledException(); - var line = await reader.ReadLineAsync(cancellationToken); + var line = await reader.ReadLineAsync(); if (line != null && line.StartsWith("data:")) { var data = line["data:".Length..]; if (data.StartsWith("{\"code\":")) { - var error = JsonSerializer.Deserialize(data, SerializationOptions)!; + var error = + JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; throw new DashScopeException( message.RequestUri?.ToString(), (int)response.StatusCode, @@ -381,7 +392,7 @@ private async IAsyncEnumerable StreamAsync( error.Message); } - yield return JsonSerializer.Deserialize(data, SerializationOptions)!; + yield return JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; } } } @@ -418,7 +429,9 @@ private async Task GetSuccessResponseAsync( DashScopeError? error = null; try { - var r = await response.Content.ReadFromJsonAsync(SerializationOptions, cancellationToken); + var r = await response.Content.ReadFromJsonAsync( + DashScopeDefaults.SerializationOptions, + cancellationToken); error = r == null ? null : errorMapper.Invoke(r); } catch (Exception) diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientWebSocket.cs b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocket.cs new file mode 100644 index 0000000..464aa4c --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocket.cs @@ -0,0 +1,262 @@ +using System.Net.WebSockets; +using System.Text; +using System.Text.Json; +using System.Threading.Channels; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Core; + +/// +/// A websocket client for DashScope websocket API. +/// +public sealed class DashScopeClientWebSocket : IDisposable +{ + private static readonly UnboundedChannelOptions UnboundedChannelOptions = + new() + { + SingleWriter = true, + SingleReader = true, + AllowSynchronousContinuations = true + }; + + private readonly IClientWebSocket _socket; + private Task? _receiveTask; + private TaskCompletionSource _taskStartedSignal = new(); + private Channel? _binaryOutput; + private Channel>? _jsonOutput; + + /// + /// Unique id of this socket. + /// + internal Guid Id { get; } = Guid.NewGuid(); + + /// + /// The binary output. + /// + public ChannelReader BinaryOutput + => _binaryOutput?.Reader + ?? throw new InvalidOperationException("Please call ResetOutput() before accessing output"); + + /// + /// The json output. + /// + /// Throws when ResetOutput is not called. + public ChannelReader> JsonOutput + => _jsonOutput?.Reader + ?? throw new InvalidOperationException("Please call ResetOutput() before accessing output"); + + /// + /// A task that completed when received task-started event. + /// + public Task TaskStarted => _taskStartedSignal.Task; + + /// + /// Current state for this websocket. + /// + public DashScopeWebSocketState State { get; private set; } + + /// + /// Initialize a configured web socket client. + /// + /// The api key to use. + /// Optional workspace id. + public DashScopeClientWebSocket(string apiKey, string? workspaceId = null) + { + _socket = new ClientWebSocketWrapper(new ClientWebSocket()); + _socket.Options.SetRequestHeader("X-DashScope-DataInspection", "enable"); + _socket.Options.SetRequestHeader("Authorization", $"bearer {apiKey}"); + if (string.IsNullOrEmpty(workspaceId) == false) + { + _socket.Options.SetRequestHeader("X-DashScope-WorkspaceId", workspaceId); + } + } + + /// + /// Initiate a with a pre-configured . + /// + /// Pre-configured . + internal DashScopeClientWebSocket(IClientWebSocket socket) + { + _socket = socket; + } + + /// + /// Start a websocket connection. + /// + /// Websocket API uri. + /// The cancellation token to use. + /// + /// When was request. + public async Task ConnectAsync(Uri uri, CancellationToken cancellationToken = default) + { + await _socket.ConnectAsync(uri, cancellationToken); + _receiveTask = ReceiveMessagesAsync(cancellationToken); + State = DashScopeWebSocketState.Ready; + } + + /// + /// Reset binary output. + /// + public void ResetOutput() + { + _binaryOutput?.Writer.TryComplete(); + _binaryOutput = Channel.CreateUnbounded(UnboundedChannelOptions); + _jsonOutput?.Writer.TryComplete(); + _jsonOutput = Channel.CreateUnbounded>(UnboundedChannelOptions); + _taskStartedSignal.TrySetResult(false); + _taskStartedSignal = new TaskCompletionSource(); + } + + /// + /// Send message to server. + /// + /// Request to send. + /// A cancellation token used to propagate notification that this operation should be canceled. + /// + /// Type of the input. + /// Type of the parameter. + /// The is requested. + /// Websocket is not connected or already closed. + /// The underlying websocket has already been closed. + public Task SendMessageAsync( + DashScopeWebSocketRequest request, + CancellationToken cancellationToken = default) + where TInput : class, new() + where TParameter : class + { + if (State == DashScopeWebSocketState.Closed) + { + throw new InvalidOperationException("Socket is already closed."); + } + + var json = JsonSerializer.Serialize(request, DashScopeDefaults.SerializationOptions); + return _socket.SendAsync( + new ArraySegment(Encoding.UTF8.GetBytes(json)), + WebSocketMessageType.Text, + true, + cancellationToken); + } + + private async Task?> ReceiveMessageAsync( + CancellationToken cancellationToken = default) + { + var buffer = new byte[1024 * 4]; + var segment = new ArraySegment(buffer); + + try + { + var result = await _socket.ReceiveAsync(segment, cancellationToken); + if (result.MessageType == WebSocketMessageType.Close) + { + await CloseAsync(cancellationToken); + return null; + } + + if (result.MessageType == WebSocketMessageType.Binary) + { + for (var i = 0; i < result.Count; i++) + { + await _binaryOutput!.Writer.WriteAsync(buffer[i], cancellationToken); + } + + return null; + } + + var message = Encoding.UTF8.GetString(buffer, 0, result.Count); + var jsonResponse = + JsonSerializer.Deserialize>( + message, + DashScopeDefaults.SerializationOptions); + return jsonResponse; + } + catch + { + // close socket when exception happens. + await CloseAsync(cancellationToken); + } + + return null; + } + + /// + /// Wait for server response. + /// + /// A cancellation token used to propagate notification that this operation should be canceled. + /// The task was failed. + private async Task ReceiveMessagesAsync(CancellationToken cancellationToken = default) + { + while (State != DashScopeWebSocketState.Closed && _socket.CloseStatus == null) + { + var json = await ReceiveMessageAsync(cancellationToken); + if (json == null) + { + continue; + } + + if (_jsonOutput is not null) + { + await _jsonOutput.Writer.WriteAsync(json, cancellationToken); + } + + var eventStr = json.Header.Event; + switch (eventStr) + { + case "task-started": + State = DashScopeWebSocketState.RunningTask; + _taskStartedSignal.TrySetResult(true); + break; + case "task-finished": + State = DashScopeWebSocketState.Ready; + _binaryOutput?.Writer.Complete(); + _jsonOutput?.Writer.Complete(); + break; + case "task-failed": + await CloseAsync(cancellationToken); + _binaryOutput?.Writer.Complete(); + _jsonOutput?.Writer.Complete(); + throw new DashScopeException( + null, + 400, + new DashScopeError + { + Code = json.Header.ErrorCode ?? string.Empty, + Message = json.Header.ErrorMessage ?? string.Empty, + RequestId = json.Header.Attributes.RequestUuid ?? string.Empty + }, + json.Header.ErrorMessage ?? "The task was failed"); + } + } + + await CloseAsync(cancellationToken); + } + + /// + /// Close the underlying websocket. + /// + /// A cancellation token used to propagate notification that this operation should be canceled. + /// + public async Task CloseAsync(CancellationToken cancellationToken = default) + { + await _socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cancellationToken); + State = DashScopeWebSocketState.Closed; + _binaryOutput?.Writer.TryComplete(); + _jsonOutput?.Writer.TryComplete(); + } + + private void Dispose(bool disposing) + { + if (disposing) + { + // Dispose managed resources. + _socket.Dispose(); + _binaryOutput?.Writer.TryComplete(); + _jsonOutput?.Writer.TryComplete(); + } + } + + /// + public void Dispose() + { + Dispose(true); + } +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketFactory.cs b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketFactory.cs new file mode 100644 index 0000000..06edecb --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketFactory.cs @@ -0,0 +1,13 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Default implementation for . +/// +public class DashScopeClientWebSocketFactory : IDashScopeClientWebSocketFactory +{ + /// + public DashScopeClientWebSocket GetClientWebSocket(string apiKey, string? workspaceId = null) + { + return new DashScopeClientWebSocket(apiKey, workspaceId); + } +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketPool.cs b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketPool.cs new file mode 100644 index 0000000..57cbed5 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketPool.cs @@ -0,0 +1,140 @@ +using System.Collections.Concurrent; + +namespace Cnblogs.DashScope.Core; + +/// +/// Socket pool for DashScope API. +/// +public sealed class DashScopeClientWebSocketPool : IDisposable +{ + private readonly ConcurrentBag _available = new(); + private readonly ConcurrentDictionary _active = new(); + private readonly DashScopeOptions _options; + private readonly IDashScopeClientWebSocketFactory _dashScopeClientWebSocketFactory; + + /// + /// Socket pool for DashScope API. + /// + /// + /// Options for DashScope sdk. + public DashScopeClientWebSocketPool( + IDashScopeClientWebSocketFactory dashScopeClientWebSocketFactory, + DashScopeOptions options) + { + _dashScopeClientWebSocketFactory = dashScopeClientWebSocketFactory; + _options = options; + } + + /// + /// Get available connection count. + /// + internal int AvailableSocketCount => _available.Count; + + /// + /// Get active connection count. + /// + internal int ActiveSocketCount => _active.Count; + + internal DashScopeClientWebSocketPool( + IEnumerable sockets, + IDashScopeClientWebSocketFactory dashScopeClientWebSocketFactory) + { + _options = new DashScopeOptions(); + foreach (var socket in sockets) + { + _available.Add(socket); + } + + _dashScopeClientWebSocketFactory = dashScopeClientWebSocketFactory; + } + + internal void ReturnSocket(DashScopeClientWebSocket socket) + { + _active.Remove(socket.Id, out _); + + if (socket.State != DashScopeWebSocketState.Ready) + { + // not returnable, disposing. + socket.Dispose(); + return; + } + + _available.Add(socket); + } + + /// + /// Rent or create a socket connection from pool. + /// + /// + /// + public async Task RentSocketAsync(CancellationToken cancellationToken = default) + { + var found = false; + DashScopeClientWebSocket? socket = null; + while (found == false) + { + if (_available.IsEmpty == false) + { + found = _available.TryTake(out socket); + if (socket?.State != DashScopeWebSocketState.Ready) + { + // expired + found = false; + socket?.Dispose(); + } + } + else + { + socket = await InitializeNewSocketAsync(_options.WebsocketBaseAddress, cancellationToken); + found = true; + } + } + + return ActivateSocket(socket!); + } + + private DashScopeClientWebSocketWrapper ActivateSocket(DashScopeClientWebSocket socket) + { + _active.TryAdd(socket.Id, socket); + return new DashScopeClientWebSocketWrapper(socket, this); + } + + private async Task InitializeNewSocketAsync( + string url, + CancellationToken cancellationToken = default) + { + if (_available.Count + _active.Count >= _options.SocketPoolSize) + { + throw new InvalidOperationException("[DashScopeSDK] Socket pool is full"); + } + + var socket = _dashScopeClientWebSocketFactory.GetClientWebSocket(_options.ApiKey, _options.WorkspaceId); + await socket.ConnectAsync(new Uri(url), cancellationToken); + return socket; + } + + private void Dispose(bool disposing) + { + if (disposing) + { + // Dispose managed resources. + while (_available.IsEmpty == false) + { + _available.TryTake(out var socket); + socket?.Dispose(); + } + + var activeSockets = _active.Values; + foreach (var activeSocket in activeSockets) + { + activeSocket.Dispose(); + } + } + } + + /// + public void Dispose() + { + Dispose(true); + } +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketWrapper.cs b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketWrapper.cs new file mode 100644 index 0000000..696f304 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeClientWebSocketWrapper.cs @@ -0,0 +1,56 @@ +using System.Text.Json; + +namespace Cnblogs.DashScope.Core; + +/// +/// Represents a transient wrapper for rented websocket, should be transient. +/// +/// The rented websocket +/// The pool to return the socket to. +public sealed record DashScopeClientWebSocketWrapper(DashScopeClientWebSocket Socket, DashScopeClientWebSocketPool Pool) + : IDisposable +{ + /// + /// The binary output. + /// + public IAsyncEnumerable BinaryOutput => Socket.BinaryOutput.ReadAllAsync(); + + /// + /// The json message output. + /// + public IAsyncEnumerable> JsonOutput => Socket.JsonOutput.ReadAllAsync(); + + /// + /// Reset task signal and output cannel. + /// + public void ResetTask() => Socket.ResetOutput(); + + /// + /// The task that completes when received task-started event from server. + /// + public Task TaskStarted => Socket.TaskStarted; + + /// + /// Send message to server. + /// + /// Request to send. + /// A cancellation token used to propagate notification that this operation should be canceled. + /// + /// Type of the input. + /// Type of the parameter. + /// The is requested. + /// Websocket is not connected. + /// The underlying websocket has already been closed. + public Task SendMessageAsync( + DashScopeWebSocketRequest request, + CancellationToken cancellationToken = default) + where TInput : class, new() + where TParameter : class + => Socket.SendMessageAsync(request, cancellationToken); + + /// + public void Dispose() + { + Pool.ReturnSocket(Socket); + } +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeException.cs b/src/Cnblogs.DashScope.Core/DashScopeException.cs index d4aba49..3826f87 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeException.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeException.cs @@ -3,24 +3,35 @@ /// /// Represents error detail for DashScope API calls. /// -/// The requested api url. -/// The status code of response. Would be 0 if no response is received. -/// The error detail returned by server. -/// The error message. -public class DashScopeException(string? apiUrl, int status, DashScopeError? error, string message) : Exception(message) +public class DashScopeException : Exception { + /// + /// Represents error detail for DashScope API calls. + /// + /// The requested api url. + /// The status code of response. Would be 0 if no response is received. + /// The error detail returned by server. + /// The error message. + public DashScopeException(string? apiUrl, int status, DashScopeError? error, string message) + : base(message) + { + ApiUrl = apiUrl; + Error = error; + Status = status; + } + /// /// The requested api url. /// - public string? ApiUrl { get; } = apiUrl; + public string? ApiUrl { get; } /// /// The error detail returned by server. /// - public DashScopeError? Error { get; } = error; + public DashScopeError? Error { get; } /// /// The status code of response. Would be 0 if no response is received. /// - public int Status { get; } = status; + public int Status { get; } } diff --git a/src/Cnblogs.DashScope.Core/DashScopeOptions.cs b/src/Cnblogs.DashScope.Core/DashScopeOptions.cs new file mode 100644 index 0000000..d68d1bb --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeOptions.cs @@ -0,0 +1,34 @@ +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Core; + +/// +/// Options for DashScope client. +/// +public class DashScopeOptions +{ + /// + /// The api key used to access DashScope api + /// + public string ApiKey { get; set; } = string.Empty; + + /// + /// Base address for DashScope HTTP API. + /// + public string BaseAddress { get; set; } = DashScopeDefaults.HttpApiBaseAddress; + + /// + /// Base address for DashScope websocket API. + /// + public string WebsocketBaseAddress { get; set; } = DashScopeDefaults.WebsocketApiBaseAddress; + + /// + /// Default workspace Id. + /// + public string? WorkspaceId { get; set; } + + /// + /// Default socket pool size. + /// + public int SocketPoolSize { get; set; } = 32; +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeTaskOutput.cs b/src/Cnblogs.DashScope.Core/DashScopeTaskOutput.cs index 8ca43f9..7a8bee7 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeTaskOutput.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeTaskOutput.cs @@ -11,7 +11,7 @@ public abstract record DashScopeTaskOutput /// /// The unique id of this task. /// - public required string TaskId { get; set; } + public string TaskId { get; set; } = string.Empty; /// /// The status of this task. diff --git a/src/Cnblogs.DashScope.Core/DashScopeTaskStatus.cs b/src/Cnblogs.DashScope.Core/DashScopeTaskStatus.cs index 83a3509..3b87579 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeTaskStatus.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeTaskStatus.cs @@ -5,7 +5,7 @@ namespace Cnblogs.DashScope.Core; /// /// Represents status of DashScope task. /// -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(JsonStringEnumConverter))] public enum DashScopeTaskStatus { /// diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequest.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequest.cs new file mode 100644 index 0000000..b1845e0 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequest.cs @@ -0,0 +1,21 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Represents a websocket request to DashScope. +/// +/// Type of the input. +/// Type of the parameter. +public class DashScopeWebSocketRequest + where TInput : class, new() + where TParameter : class +{ + /// + /// Metadata of the request. + /// + public DashScopeWebSocketRequestHeader Header { get; set; } = new(); + + /// + /// Payload of the request. + /// + public DashScopeWebSocketRequestPayload Payload { get; set; } = new(); +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestHeader.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestHeader.cs new file mode 100644 index 0000000..a54c9c0 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestHeader.cs @@ -0,0 +1,22 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Metadata for websocket request. +/// +public class DashScopeWebSocketRequestHeader +{ + /// + /// Action name. + /// + public string Action { get; set; } = string.Empty; + + /// + /// UUID for task. + /// + public string TaskId { get; set; } = string.Empty; + + /// + /// Streaming type. + /// + public string? Streaming { get; set; } = "duplex"; +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestPayload.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestPayload.cs new file mode 100644 index 0000000..e994239 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestPayload.cs @@ -0,0 +1,41 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Payload for websocket request. +/// +/// Type of the input. +/// Type of the parameter. +public class DashScopeWebSocketRequestPayload + where TInput : class, new() // Input's default value must be empty object(not null or omitted). + where TParameter : class +{ + /// + /// Group name of task. + /// + public string? TaskGroup { get; set; } + + /// + /// Requesting task name. + /// + public string? Task { get; set; } + + /// + /// Requesting function name. + /// + public string? Function { get; set; } + + /// + /// Model id. + /// + public string? Model { get; set; } + + /// + /// Optional parameters. + /// + public TParameter? Parameters { get; set; } + + /// + /// The input of the request. + /// + public TInput Input { get; set; } = new(); +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponse.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponse.cs new file mode 100644 index 0000000..bffc68b --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponse.cs @@ -0,0 +1,11 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Response from websocket API. +/// +/// Response metadatas. +/// Response body. +/// Output type of the response. +public record DashScopeWebSocketResponse( + DashScopeWebSocketResponseHeader Header, + DashScopeWebSocketResponsePayload Payload); diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeader.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeader.cs new file mode 100644 index 0000000..26bbb9f --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeader.cs @@ -0,0 +1,16 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Metadata of the websocket response. +/// +/// TaskId of the task. +/// Event name. +/// Error code when is task-failed. +/// Error message when is task-failed. +/// Optional attributes +public record DashScopeWebSocketResponseHeader( + string TaskId, + string Event, + string? ErrorCode, + string? ErrorMessage, + DashScopeWebSocketResponseHeaderAttributes Attributes); diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeaderAttributes.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeaderAttributes.cs new file mode 100644 index 0000000..1ee663e --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseHeaderAttributes.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Attributes field in websocket response header. +/// +/// UUID for current request. +public record DashScopeWebSocketResponseHeaderAttributes(string? RequestUuid); diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseMapper.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseMapper.cs new file mode 100644 index 0000000..3dea7d0 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseMapper.cs @@ -0,0 +1,27 @@ +using System.Text.Json; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Core; + +/// +/// Mapper class for +/// +internal static class DashScopeWebSocketResponseMapper +{ + public static DashScopeWebSocketResponse DeserializeOutput(this DashScopeWebSocketResponse source) + where TOutput : class + { + var output = source.Payload.Output; + if (output.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined) + { + return new DashScopeWebSocketResponse( + source.Header, + new DashScopeWebSocketResponsePayload(null, source.Payload.Usage)); + } + + var mapped = output.Deserialize(DashScopeDefaults.SerializationOptions); + return new DashScopeWebSocketResponse( + source.Header, + new DashScopeWebSocketResponsePayload(mapped, source.Payload.Usage)); + } +} diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponsePayload.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponsePayload.cs new file mode 100644 index 0000000..cce48aa --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponsePayload.cs @@ -0,0 +1,9 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Payload field of websocket API response. +/// +/// Content of the response. +/// Task usage info. +/// Type of the response content. +public record DashScopeWebSocketResponsePayload(TOutput? Output, DashScopeWebSocketResponseUsage? Usage); diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseUsage.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseUsage.cs new file mode 100644 index 0000000..7e7f734 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketResponseUsage.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Usage info of websocket task. +/// +/// Current character usage count. +public record DashScopeWebSocketResponseUsage(int Characters); diff --git a/src/Cnblogs.DashScope.Core/DashScopeWebSocketState.cs b/src/Cnblogs.DashScope.Core/DashScopeWebSocketState.cs new file mode 100644 index 0000000..2cb73b1 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/DashScopeWebSocketState.cs @@ -0,0 +1,27 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// The state of . +/// +public enum DashScopeWebSocketState +{ + /// + /// The socket has been created but not connected yet. + /// + Created, + + /// + /// The socket has been connected and ready. + /// + Ready, + + /// + /// The socket has a running task waiting to be finished. + /// + RunningTask, + + /// + /// The socket has been closed. + /// + Closed +} diff --git a/src/Cnblogs.DashScope.Core/IBatchGetEmbeddingsParameters.cs b/src/Cnblogs.DashScope.Core/IBatchGetEmbeddingsParameters.cs index d2640e0..04a28d3 100644 --- a/src/Cnblogs.DashScope.Core/IBatchGetEmbeddingsParameters.cs +++ b/src/Cnblogs.DashScope.Core/IBatchGetEmbeddingsParameters.cs @@ -3,4 +3,6 @@ /// /// Optional parameter of batch get embeddings request. /// -public interface IBatchGetEmbeddingsParameters : ITextEmbeddingParameters; +public interface IBatchGetEmbeddingsParameters : ITextEmbeddingParameters +{ +} diff --git a/src/Cnblogs.DashScope.Core/IDashScopeClient.cs b/src/Cnblogs.DashScope.Core/IDashScopeClient.cs index a123050..cb61eb5 100644 --- a/src/Cnblogs.DashScope.Core/IDashScopeClient.cs +++ b/src/Cnblogs.DashScope.Core/IDashScopeClient.cs @@ -247,4 +247,14 @@ public Task UploadFileAsync( public Task DeleteFileAsync( DashScopeFileId id, CancellationToken cancellationToken = default); + + /// + /// Start a speech synthesizer session. Related model: cosyvoice + /// + /// The model to use. + /// Cancellation token. + /// + public Task CreateSpeechSynthesizerSocketSessionAsync( + string modelId, + CancellationToken cancellationToken = default); } diff --git a/src/Cnblogs.DashScope.Core/IDashScopeClientWebSocketFactory.cs b/src/Cnblogs.DashScope.Core/IDashScopeClientWebSocketFactory.cs new file mode 100644 index 0000000..0cf7359 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/IDashScopeClientWebSocketFactory.cs @@ -0,0 +1,15 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// A factory abstraction for a component that can create DashScopeClientWebSocket instance. +/// +public interface IDashScopeClientWebSocketFactory +{ + /// + /// Creates a new . + /// + /// The api key. + /// Optional workspace id. + /// + DashScopeClientWebSocket GetClientWebSocket(string apiKey, string? workspaceId = null); +} diff --git a/src/Cnblogs.DashScope.Core/IImageSynthesisParameters.cs b/src/Cnblogs.DashScope.Core/IImageSynthesisParameters.cs index 5e241c6..70a3b47 100644 --- a/src/Cnblogs.DashScope.Core/IImageSynthesisParameters.cs +++ b/src/Cnblogs.DashScope.Core/IImageSynthesisParameters.cs @@ -24,4 +24,14 @@ public interface IImageSynthesisParameters /// Seed for randomizer, max at 4294967290. Once set, generated image will use seed, seed+1, seed+2, seed+3 depends on . /// public uint? Seed { get; } + + /// + /// Let LLM to rewrite your positive prompt, Defaults to true. + /// + public bool? PromptExtend { get; } + + /// + /// Adds AI-Generated watermark on bottom right corner. + /// + public bool? Watermark { get; } } diff --git a/src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs b/src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs index c32bb72..9c3b763 100644 --- a/src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs +++ b/src/Cnblogs.DashScope.Core/ITextGenerationParameters.cs @@ -1,10 +1,11 @@ -namespace Cnblogs.DashScope.Core; +namespace Cnblogs.DashScope.Core; /// /// The text generation options. /// public interface ITextGenerationParameters - : IIncrementalOutputParameter, ISeedParameter, IProbabilityParameter, IPenaltyParameter, IMaxTokenParameter, IStopTokenParameter + : IIncrementalOutputParameter, ISeedParameter, IProbabilityParameter, IPenaltyParameter, IMaxTokenParameter, + IStopTokenParameter { /// /// The format of the result, must be text or message. @@ -40,6 +41,31 @@ public interface ITextGenerationParameters /// public bool? EnableSearch { get; } + /// + /// Search options. should set to true. + /// + public TextGenerationSearchOptions? SearchOptions { get; set; } + + /// + /// Thinking option. Valid for supported models.(e.g. qwen3) + /// + public bool? EnableThinking { get; } + + /// + /// Maximum length of thinking content. Valid for supported models.(e.g. qwen3) + /// + public int? ThinkingBudget { get; set; } + + /// + /// Include log possibilities in response. + /// + public bool? Logprobs { get; set; } + + /// + /// How many choices should be returned. Range: [0, 5] + /// + public int? TopLogprobs { get; set; } + /// /// Available tools for model to call. /// @@ -49,4 +75,14 @@ public interface ITextGenerationParameters /// Behavior when choosing tools. /// public ToolChoice? ToolChoice { get; } + + /// + /// Whether to enable parallel tool calling + /// + public bool? ParallelToolCalls { get; } + + /// + /// Options when using QWen-MT models. + /// + public TextGenerationTranslationOptions? TranslationOptions { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/ImageGenerationInput.cs b/src/Cnblogs.DashScope.Core/ImageGenerationInput.cs index d21dca1..4ea9876 100644 --- a/src/Cnblogs.DashScope.Core/ImageGenerationInput.cs +++ b/src/Cnblogs.DashScope.Core/ImageGenerationInput.cs @@ -8,10 +8,10 @@ public class ImageGenerationInput /// /// The image url to generation new image from. /// - public required string ImageUrl { get; set; } + public string ImageUrl { get; set; } = string.Empty; /// /// The style the new image should use, checkout docs for sample image of different indexes: https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-wanxiang-style-repaint /// - public required int StyleIndex { get; set; } + public int StyleIndex { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/ImageSynthesisInput.cs b/src/Cnblogs.DashScope.Core/ImageSynthesisInput.cs index 9c78118..21c0dcc 100644 --- a/src/Cnblogs.DashScope.Core/ImageSynthesisInput.cs +++ b/src/Cnblogs.DashScope.Core/ImageSynthesisInput.cs @@ -8,7 +8,7 @@ public class ImageSynthesisInput /// /// The prompt to generate image from. This will be chopped at max length of 500 characters. /// - public required string Prompt { get; set; } + public string Prompt { get; set; } = string.Empty; /// /// The negative prompt to generate image from. This will be chopped at max length of 500 characters. diff --git a/src/Cnblogs.DashScope.Core/ImageSynthesisParameters.cs b/src/Cnblogs.DashScope.Core/ImageSynthesisParameters.cs index 58497fe..8ca30bd 100644 --- a/src/Cnblogs.DashScope.Core/ImageSynthesisParameters.cs +++ b/src/Cnblogs.DashScope.Core/ImageSynthesisParameters.cs @@ -16,4 +16,10 @@ public class ImageSynthesisParameters : IImageSynthesisParameters /// public uint? Seed { get; set; } + + /// + public bool? PromptExtend { get; set; } + + /// + public bool? Watermark { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/Internals/Assembly.cs b/src/Cnblogs.DashScope.Core/Internals/Assembly.cs new file mode 100644 index 0000000..e628d36 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/Internals/Assembly.cs @@ -0,0 +1,5 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Cnblogs.DashScope.Sdk.UnitTests")] +[assembly: InternalsVisibleTo("Cnblogs.DashScope.Tests.Shared")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/Cnblogs.DashScope.Core/Internals/ByteArrayLiteralConvertor.cs b/src/Cnblogs.DashScope.Core/Internals/ByteArrayLiteralConvertor.cs new file mode 100644 index 0000000..509e4c1 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/Internals/ByteArrayLiteralConvertor.cs @@ -0,0 +1,43 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Cnblogs.DashScope.Core.Internals; + +internal class ByteArrayLiteralConvertor : JsonConverter +{ + /// + public override byte[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.StartArray) + { + reader.Read(); // read out start of array + var list = new List(8); // should fit most tokens + while (reader.TokenType != JsonTokenType.EndArray) + { + list.Add(reader.GetByte()); + reader.Read(); + } + + return list.ToArray(); + } + + if (reader.TokenType == JsonTokenType.Null) + { + return null; + } + + return reader.GetBytesFromBase64(); + } + + /// + public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options) + { + writer.WriteStartArray(); + foreach (var b in value) + { + writer.WriteNumberValue(b); + } + + writer.WriteEndArray(); + } +} diff --git a/src/Cnblogs.DashScope.Core/Internals/ClientWebSocketWrapper.cs b/src/Cnblogs.DashScope.Core/Internals/ClientWebSocketWrapper.cs new file mode 100644 index 0000000..71ebddb --- /dev/null +++ b/src/Cnblogs.DashScope.Core/Internals/ClientWebSocketWrapper.cs @@ -0,0 +1,47 @@ +using System.Net.WebSockets; + +namespace Cnblogs.DashScope.Core.Internals; + +internal sealed class ClientWebSocketWrapper : IClientWebSocket +{ + private readonly ClientWebSocket _socket; + + public ClientWebSocketWrapper(ClientWebSocket socket) + { + _socket = socket; + } + + /// + public void Dispose() + { + _socket.Dispose(); + } + + /// + public ClientWebSocketOptions Options => _socket.Options; + + /// + public WebSocketCloseStatus? CloseStatus => _socket.CloseStatus; + + /// + public Task ConnectAsync(Uri uri, CancellationToken cancellation) => _socket.ConnectAsync(uri, cancellation); + + /// + public Task SendAsync( + ArraySegment buffer, + WebSocketMessageType messageType, + bool endOfMessage, + CancellationToken cancellationToken) + => _socket.SendAsync(buffer, messageType, endOfMessage, cancellationToken); + + /// + public Task ReceiveAsync(ArraySegment buffer, CancellationToken cancellationToken) + => _socket.ReceiveAsync(buffer, cancellationToken); + + /// + public Task CloseAsync( + WebSocketCloseStatus closeStatus, + string? statusDescription, + CancellationToken cancellationToken) + => _socket.CloseAsync(closeStatus, statusDescription, cancellationToken); +} diff --git a/src/Cnblogs.DashScope.Core/Internals/DashScopeDateTimeConvertor.cs b/src/Cnblogs.DashScope.Core/Internals/DashScopeDateTimeConvertor.cs index c4c9987..45fc52f 100644 --- a/src/Cnblogs.DashScope.Core/Internals/DashScopeDateTimeConvertor.cs +++ b/src/Cnblogs.DashScope.Core/Internals/DashScopeDateTimeConvertor.cs @@ -6,11 +6,7 @@ namespace Cnblogs.DashScope.Core.Internals; internal class DashScopeDateTimeConvertor : JsonConverter { - private static readonly string[] DateTimeFormats = - [ - "yyyy-MM-dd HH:mm:ss.fff", - "yyyy-MM-dd HH:mm:ss.FFF" - ]; + private static readonly string[] DateTimeFormats = { "yyyy-MM-dd HH:mm:ss.fff", "yyyy-MM-dd HH:mm:ss.FFF" }; /// public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/src/Cnblogs.DashScope.Core/Internals/DashScopeDefaults.cs b/src/Cnblogs.DashScope.Core/Internals/DashScopeDefaults.cs index 5c1b537..7623c1b 100644 --- a/src/Cnblogs.DashScope.Core/Internals/DashScopeDefaults.cs +++ b/src/Cnblogs.DashScope.Core/Internals/DashScopeDefaults.cs @@ -1,6 +1,30 @@ -namespace Cnblogs.DashScope.Core.Internals; +using System.Text.Json; +using System.Text.Json.Serialization; -internal static class DashScopeDefaults +namespace Cnblogs.DashScope.Core.Internals; + +/// +/// Default values for DashScope client. +/// +public static class DashScopeDefaults { - public const string DashScopeApiBaseAddress = "https://dashscope.aliyuncs.com/api/v1/"; + /// + /// Base address for HTTP API. + /// + public const string HttpApiBaseAddress = "https://dashscope.aliyuncs.com/api/v1/"; + + /// + /// Base address for websocket API. + /// + public const string WebsocketApiBaseAddress = "wss://dashscope.aliyuncs.com/api-ws/v1/inference/"; + + /// + /// Default json serializer options. + /// + public static readonly JsonSerializerOptions SerializationOptions = + new() + { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, + }; } diff --git a/src/Cnblogs.DashScope.Core/Internals/IClientWebSocket.cs b/src/Cnblogs.DashScope.Core/Internals/IClientWebSocket.cs new file mode 100644 index 0000000..b4a3cd7 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/Internals/IClientWebSocket.cs @@ -0,0 +1,25 @@ +using System.Net.WebSockets; + +namespace Cnblogs.DashScope.Core.Internals; + +/// +/// Extract for testing purpose. +/// +internal interface IClientWebSocket : IDisposable +{ + public ClientWebSocketOptions Options { get; } + + public WebSocketCloseStatus? CloseStatus { get; } + + public Task ConnectAsync(Uri uri, CancellationToken cancellation); + + public Task SendAsync( + ArraySegment buffer, + WebSocketMessageType messageType, + bool endOfMessage, + CancellationToken cancellationToken); + + Task ReceiveAsync(ArraySegment buffer, CancellationToken cancellationToken); + + Task CloseAsync(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken); +} diff --git a/src/Cnblogs.DashScope.Core/Internals/TextGenerationStopConvertor.cs b/src/Cnblogs.DashScope.Core/Internals/TextGenerationStopConvertor.cs index 1efd6b5..5f704a8 100644 --- a/src/Cnblogs.DashScope.Core/Internals/TextGenerationStopConvertor.cs +++ b/src/Cnblogs.DashScope.Core/Internals/TextGenerationStopConvertor.cs @@ -77,21 +77,21 @@ private static TextGenerationStop ReadArray(ref Utf8JsonReader reader) case JsonTokenType.EndArray: return type switch { - DeserializationArrayType.Strings => stringList ?? [], - DeserializationArrayType.Token => intList?.ToArray() ?? [], - DeserializationArrayType.Tokens => tokenList ?? [], + DeserializationArrayType.Strings => stringList ?? new List(), + DeserializationArrayType.Token => intList?.ToArray() ?? Array.Empty(), + DeserializationArrayType.Tokens => tokenList ?? new List(), _ => throw new JsonException("Impossible deserialization type") }; case JsonTokenType.StartArray when type is DeserializationArrayType.Tokens: - tokenList ??= []; + tokenList ??= new List(); tokenList.Add(ReadTokenId(ref reader)); break; case JsonTokenType.Number when type is DeserializationArrayType.Token: - intList ??= []; + intList ??= new List(); intList.Add(reader.GetInt32()); break; case JsonTokenType.String when type is DeserializationArrayType.Strings: - stringList ??= []; + stringList ??= new List(); stringList.Add(reader.GetString()!); break; default: diff --git a/src/Cnblogs.DashScope.Core/ModelRequest.cs b/src/Cnblogs.DashScope.Core/ModelRequest.cs index 69ad50c..93fbfff 100644 --- a/src/Cnblogs.DashScope.Core/ModelRequest.cs +++ b/src/Cnblogs.DashScope.Core/ModelRequest.cs @@ -10,12 +10,12 @@ public class ModelRequest /// /// The model to use. /// - public required string Model { get; init; } + public string Model { get; init; } = string.Empty; /// /// Input of this request. /// - public required TInput Input { get; init; } + public TInput Input { get; init; } = null!; } /// diff --git a/src/Cnblogs.DashScope.Core/MultimodalInput.cs b/src/Cnblogs.DashScope.Core/MultimodalInput.cs index 775b4d5..251e0ac 100644 --- a/src/Cnblogs.DashScope.Core/MultimodalInput.cs +++ b/src/Cnblogs.DashScope.Core/MultimodalInput.cs @@ -8,5 +8,5 @@ public class MultimodalInput /// /// The messages of context, model will generate from last user message. /// - public required IEnumerable Messages { get; set; } + public IEnumerable Messages { get; set; } = Array.Empty(); } diff --git a/src/Cnblogs.DashScope.Core/MultimodalMessage.cs b/src/Cnblogs.DashScope.Core/MultimodalMessage.cs index d1034b0..48bcc44 100644 --- a/src/Cnblogs.DashScope.Core/MultimodalMessage.cs +++ b/src/Cnblogs.DashScope.Core/MultimodalMessage.cs @@ -7,7 +7,11 @@ namespace Cnblogs.DashScope.Core; /// /// The role associated with this message. /// The contents of this message. -public record MultimodalMessage(string Role, IReadOnlyList Content) +/// Thoughts from the model. +public record MultimodalMessage( + string Role, + IReadOnlyList Content, + string? ReasoningContent = null) : IMessage> { /// @@ -34,9 +38,12 @@ public static MultimodalMessage System(IReadOnlyList c /// Creates an assistant message. /// /// Message contents. + /// Thoughts from the model. /// - public static MultimodalMessage Assistant(IReadOnlyList contents) + public static MultimodalMessage Assistant( + IReadOnlyList contents, + string? reasoningContent = null) { - return new MultimodalMessage(DashScopeRoleNames.Assistant, contents); + return new MultimodalMessage(DashScopeRoleNames.Assistant, contents, reasoningContent); } } diff --git a/src/Cnblogs.DashScope.Core/MultimodalMessageContent.cs b/src/Cnblogs.DashScope.Core/MultimodalMessageContent.cs index 98fff19..aee7879 100644 --- a/src/Cnblogs.DashScope.Core/MultimodalMessageContent.cs +++ b/src/Cnblogs.DashScope.Core/MultimodalMessageContent.cs @@ -1,6 +1,4 @@ -using System.Diagnostics.CodeAnalysis; - -namespace Cnblogs.DashScope.Core; +namespace Cnblogs.DashScope.Core; /// /// Represents one content of a . @@ -12,10 +10,8 @@ namespace Cnblogs.DashScope.Core; /// For qwen-vl-ocr only. Minimal pixels for ocr task. /// For qwen-vl-ocr only. Maximum pixels for ocr task. public record MultimodalMessageContent( - [StringSyntax(StringSyntaxAttribute.Uri)] string? Image = null, string? Text = null, - [StringSyntax(StringSyntaxAttribute.Uri)] string? Audio = null, IEnumerable? Video = null, int? MinPixels = null, diff --git a/src/Cnblogs.DashScope.Core/QWenTokenizer.cs b/src/Cnblogs.DashScope.Core/QWenTokenizer.cs index 3deec09..f114a14 100644 --- a/src/Cnblogs.DashScope.Core/QWenTokenizer.cs +++ b/src/Cnblogs.DashScope.Core/QWenTokenizer.cs @@ -1,48 +1,35 @@ -using System.Text.RegularExpressions; -using Cnblogs.DashScope.Core.Internals; -using Microsoft.ML.Tokenizers; +using Cnblogs.DashScope.Core.Internals; +using Microsoft.DeepDev; namespace Cnblogs.DashScope.Core; /// -/// Local implementation for QWen tokenizer +/// Tokenizer using QWen /// -public partial class QWenTokenizer +public class QWenTokenizer { private static readonly Dictionary SpecialTokens = - new List - { - "<|endoftext|>", - "<|im_start|>", - "<|im_end|>" - } + new[] { "<|endoftext|>", "<|im_start|>", "<|im_end|>" } .Concat(Enumerable.Range(0, 205).Select(x => $"<|extra_{x}|>")) .Select((x, i) => new KeyValuePair(x, 151643 + i)) - .ToDictionary(); - - [GeneratedRegex( - @"(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+", - RegexOptions.Compiled, - "zh-CN")] - private static partial Regex Pattern(); + .ToDictionary(x => x.Key, x => x.Value); /// - /// Created tokenizer + /// Static tokenizer /// - public static Tokenizer Tokenizer { get; } = TiktokenTokenizer.Create( + public static readonly ITokenizer Tokenizer = TokenizerBuilder.CreateTokenizer( DashScopeEmbeddedResource.ReadBpeFile(), - new RegexPreTokenizer(Pattern(), SpecialTokens), - null, - SpecialTokens); + SpecialTokens, + @"(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"); /// - /// Encode text to tokens. + /// Encode text. /// - /// The text to encode. + /// The text to be encoded. /// - public static IReadOnlyList Encode(string text) + public static List Encode(string text) { - return Tokenizer.EncodeToIds(text); + return Tokenizer.Encode(text, false); } /// @@ -56,25 +43,42 @@ public static string Decode(int[] tokens) } /// - /// Get token count for text. + /// Count tokens. + /// + /// Input text. + /// + public int CountTokens(string text) + { + return Tokenizer.Encode(text).Count; + } + + /// + /// Split text to string tokens. + /// + /// Input text. + /// + public IReadOnlyList GetTokens(string text) + { + return Tokenizer.Encode(text).Select(x => Tokenizer.Decode(new[] { x })).ToList(); + } + + /// + /// Count tokens. /// - /// The text to tokenize. + /// The text to be tokenized. /// - public static int CountTokens(string text) + public static int CountTokensStatic(string text) { - return Tokenizer.CountTokens(text); + return Tokenizer.Encode(text).Count; } /// - /// Find the index of the maximum encoding capacity without surpassing the token limit. + /// Get tokens /// - /// The input text. - /// The maximum number of tokens to encode. - /// If the tokenizer's normalization is enabled or is , this will be set to in its normalized form; otherwise, this value will be set to . - /// The token count can be generated which should be smaller than the maximum token count. + /// The text to tokenizers. /// - public static int GetIndexByTokenCount(string text, int maxTokenCount, out string? normalizedText, out int tokenCount) + public static IReadOnlyList GetTokensStatic(string text) { - return Tokenizer.GetIndexByTokenCount(text, maxTokenCount, out normalizedText, out tokenCount); + return Tokenizer.Encode(text).Select(x => Tokenizer.Decode(new[] { x })).ToList(); } } diff --git a/src/Cnblogs.DashScope.Core/SpeechSynthesizerInput.cs b/src/Cnblogs.DashScope.Core/SpeechSynthesizerInput.cs new file mode 100644 index 0000000..8421fe2 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/SpeechSynthesizerInput.cs @@ -0,0 +1,12 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Input for TTS task. +/// +public class SpeechSynthesizerInput +{ + /// + /// Input text, can be null for run-task command. + /// + public string? Text { get; set; } +} diff --git a/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutput.cs b/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutput.cs new file mode 100644 index 0000000..11a000d --- /dev/null +++ b/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutput.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Output for TTS task. +/// +/// The output sentences. +public record SpeechSynthesizerOutput(SpeechSynthesizerOutputSentences? Sentence); diff --git a/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutputSentences.cs b/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutputSentences.cs new file mode 100644 index 0000000..0698aba --- /dev/null +++ b/src/Cnblogs.DashScope.Core/SpeechSynthesizerOutputSentences.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Sentences for TTS output. +/// +/// Output words. +public record SpeechSynthesizerOutputSentences(string[]? Words); diff --git a/src/Cnblogs.DashScope.Core/SpeechSynthesizerParameters.cs b/src/Cnblogs.DashScope.Core/SpeechSynthesizerParameters.cs new file mode 100644 index 0000000..8e59c19 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/SpeechSynthesizerParameters.cs @@ -0,0 +1,47 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Parameters for TTS task. +/// +public class SpeechSynthesizerParameters +{ + /// + /// Fixed to "PlainText" + /// + public string TextType { get; set; } = "PlainText"; + + /// + /// The voice to use. + /// + public string Voice { get; set; } = string.Empty; + + /// + /// Output file format, can be pcm, wav or mp3. + /// + public string? Format { get; set; } + + /// + /// Output audio sample rate. + /// + public int? SampleRate { get; set; } + + /// + /// Output audio volume, range between 0-100, defaults to 50. + /// + public int? Volume { get; set; } + + /// + /// Speech speed, range between 0.5~2.0, defaults to 1.0. + /// + public float? Rate { get; set; } + + /// + /// Pitch of the voice, range between 0.5~2, defaults to 1.0. + /// + public float? Pitch { get; set; } + + /// + /// Enable SSML, you can only send text once if enabled. + /// + public bool? EnableSsml { get; set; } +} diff --git a/src/Cnblogs.DashScope.Core/SpeechSynthesizerSocketSession.cs b/src/Cnblogs.DashScope.Core/SpeechSynthesizerSocketSession.cs new file mode 100644 index 0000000..a3ed0e4 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/SpeechSynthesizerSocketSession.cs @@ -0,0 +1,156 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Represents a socket-based TTS session. +/// +public sealed class SpeechSynthesizerSocketSession + : IDisposable +{ + private readonly DashScopeClientWebSocketWrapper _socket; + private readonly string _modelId; + + /// + /// Represents a socket-based TTS session. + /// + /// Underlying websocket. + /// Model name to use. + public SpeechSynthesizerSocketSession(DashScopeClientWebSocketWrapper socket, string modelId) + { + _socket = socket; + _modelId = modelId; + } + + /// + /// Send a run-task command, use random GUID as taskId. + /// + /// Input parameters. + /// Input text. + /// The cancellation token to use. + /// The generated taskId. + public Task RunTaskAsync( + SpeechSynthesizerParameters parameters, + string? text = null, + CancellationToken cancellationToken = default) + { + return RunTaskAsync(Guid.NewGuid().ToString(), parameters, text, cancellationToken); + } + + /// + /// Send a run-task command. + /// + /// Unique taskId. + /// Input parameters. + /// Input text. + /// The cancellation token to use. + /// . + public async Task RunTaskAsync( + string taskId, + SpeechSynthesizerParameters parameters, + string? text = null, + CancellationToken cancellationToken = default) + { + var command = new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + Action = "run-task", TaskId = taskId, + }, + Payload = new DashScopeWebSocketRequestPayload + { + Input = new SpeechSynthesizerInput { Text = text, }, + TaskGroup = "audio", + Task = "tts", + Function = "SpeechSynthesizer", + Model = _modelId, + Parameters = parameters + } + }; + + _socket.ResetTask(); + await _socket.SendMessageAsync(command, cancellationToken); + await _socket.TaskStarted; + return taskId; + } + + /// + /// Append input text to task. + /// + /// TaskId to append. + /// Text to append. + /// Cancellation token to use. + public async Task ContinueTaskAsync(string taskId, string input, CancellationToken cancellationToken = default) + { + var command = new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + Action = "continue-task", + TaskId = taskId, + Streaming = null + }, + Payload = new DashScopeWebSocketRequestPayload + { + Input = new SpeechSynthesizerInput { Text = input } + } + }; + await _socket.SendMessageAsync(command, cancellationToken); + } + + /// + /// Send finish-task command. + /// + /// Unique id of the task. + /// The cancellation token to use. + public async Task FinishTaskAsync(string taskId, CancellationToken cancellationToken = default) + { + var command = new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + TaskId = taskId, + Action = "finish-task", + Streaming = null + }, + Payload = new DashScopeWebSocketRequestPayload + { + Input = new SpeechSynthesizerInput() + } + }; + await _socket.SendMessageAsync(command, cancellationToken); + } + + /// + /// Get the audio stream. + /// + /// + public IAsyncEnumerable GetAudioAsync() + { + return _socket.BinaryOutput; + } + + /// + /// Get the message stream. + /// + /// + public async IAsyncEnumerable> GetMessagesAsync() + { + await foreach (var response in _socket.JsonOutput) + { + yield return response.DeserializeOutput(); + } + } + + private void Dispose(bool disposing) + { + if (disposing) + { + _socket.Dispose(); + } + } + + /// + public void Dispose() + { + Dispose(true); + } +} diff --git a/src/Cnblogs.DashScope.Core/TextChatMessage.cs b/src/Cnblogs.DashScope.Core/TextChatMessage.cs index 7191191..3a3bfa2 100644 --- a/src/Cnblogs.DashScope.Core/TextChatMessage.cs +++ b/src/Cnblogs.DashScope.Core/TextChatMessage.cs @@ -6,20 +6,7 @@ namespace Cnblogs.DashScope.Core; /// /// Represents a chat message between the user and the model. /// -/// The role of this message. -/// The content of this message. -/// Used when role is tool, represents the function name of this message generated by. -/// Notify model that next message should use this message as prefix. -/// Reasoning content for reasoning model. -/// Calls to the function. -[method: JsonConstructor] -public record TextChatMessage( - string Role, - string Content, - string? Name = null, - bool? Partial = null, - string? ReasoningContent = null, - List? ToolCalls = null) : IMessage +public record TextChatMessage : IMessage { /// /// Create chat message from an uploaded DashScope file. @@ -39,6 +26,50 @@ public TextChatMessage(IEnumerable fileIds) { } + /// + /// Represents a chat message between the user and the model. + /// + /// The role of this message. + /// The content of this message. + /// Used when role is tool, represents the function name of this message generated by. + /// Notify model that next message should use this message as prefix. + /// Reasoning content for reasoning model. + /// Calls to the function. + [JsonConstructor] + public TextChatMessage( + string role, + string content, + string? name = null, + bool? partial = null, + string? reasoningContent = null, + List? toolCalls = null) + { + Role = role; + Content = content; + Name = name; + Partial = partial; + ReasoningContent = reasoningContent; + ToolCalls = toolCalls; + } + + /// The role of this message. + public string Role { get; init; } + + /// The content of this message. + public string Content { get; init; } + + /// Used when role is tool, represents the function name of this message generated by. + public string? Name { get; init; } + + /// Notify model that next message should use this message as prefix. + public bool? Partial { get; init; } + + /// Reasoning content for reasoning model. + public string? ReasoningContent { get; init; } + + /// Calls to the function. + public List? ToolCalls { get; init; } + /// /// Creates a file message. /// diff --git a/src/Cnblogs.DashScope.Core/TextEmbeddingInput.cs b/src/Cnblogs.DashScope.Core/TextEmbeddingInput.cs index 41295eb..fb884a2 100644 --- a/src/Cnblogs.DashScope.Core/TextEmbeddingInput.cs +++ b/src/Cnblogs.DashScope.Core/TextEmbeddingInput.cs @@ -8,5 +8,5 @@ public class TextEmbeddingInput /// /// The texts to be computed. /// - public required IEnumerable Texts { get; set; } + public IEnumerable Texts { get; set; } = Array.Empty(); } diff --git a/src/Cnblogs.DashScope.Core/TextGenerationChoice.cs b/src/Cnblogs.DashScope.Core/TextGenerationChoice.cs index 6f5d7ab..faca9b9 100644 --- a/src/Cnblogs.DashScope.Core/TextGenerationChoice.cs +++ b/src/Cnblogs.DashScope.Core/TextGenerationChoice.cs @@ -13,5 +13,10 @@ public class TextGenerationChoice /// /// The generated message. /// - public required TextChatMessage Message { get; set; } + public TextChatMessage Message { get; set; } = new(Array.Empty()); + + /// + /// Token array with log possibility info. + /// + public TextGenerationLogprobs? Logprobs { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/TextGenerationLogprobContent.cs b/src/Cnblogs.DashScope.Core/TextGenerationLogprobContent.cs new file mode 100644 index 0000000..c8b8b7d --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationLogprobContent.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Core; + +/// +/// Represents a possible choice of token. +/// +/// Token content. +/// Token content in UTF-8 byte array. +/// Possibility, null when it's too low. +/// The most possible alternatives. +public record TextGenerationLogprobContent( + string Token, + [property: JsonConverter(typeof(ByteArrayLiteralConvertor))] + byte[] Bytes, + float? Logprob, + List TopLogprobs); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationLogprobs.cs b/src/Cnblogs.DashScope.Core/TextGenerationLogprobs.cs new file mode 100644 index 0000000..ba4a107 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationLogprobs.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Possibilities of token choices. +/// +/// The choices with their possibility. +public record TextGenerationLogprobs(List Content); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationOutput.cs b/src/Cnblogs.DashScope.Core/TextGenerationOutput.cs index 7288b8a..d0d43d8 100644 --- a/src/Cnblogs.DashScope.Core/TextGenerationOutput.cs +++ b/src/Cnblogs.DashScope.Core/TextGenerationOutput.cs @@ -19,4 +19,9 @@ public class TextGenerationOutput /// Not null when . is "message". /// public List? Choices { get; set; } + + /// + /// Not null when . configured to show source. + /// + public TextGenerationWebSearchInfo? SearchInfo { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/TextGenerationOutputTokenDetails.cs b/src/Cnblogs.DashScope.Core/TextGenerationOutputTokenDetails.cs new file mode 100644 index 0000000..8e3f49b --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationOutputTokenDetails.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Output details for text generation api. +/// +/// Token count of reasoning content. +public record TextGenerationOutputTokenDetails(int ReasoningTokens); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationParameters.cs b/src/Cnblogs.DashScope.Core/TextGenerationParameters.cs index c5151f3..fc2fee9 100644 --- a/src/Cnblogs.DashScope.Core/TextGenerationParameters.cs +++ b/src/Cnblogs.DashScope.Core/TextGenerationParameters.cs @@ -1,4 +1,4 @@ -namespace Cnblogs.DashScope.Core; +namespace Cnblogs.DashScope.Core; /// /// The text generation options. @@ -38,12 +38,33 @@ public class TextGenerationParameters : ITextGenerationParameters /// public bool? EnableSearch { get; set; } + /// + public TextGenerationSearchOptions? SearchOptions { get; set; } + + /// + public bool? EnableThinking { get; set; } + + /// + public int? ThinkingBudget { get; set; } + + /// + public bool? Logprobs { get; set; } + + /// + public int? TopLogprobs { get; set; } + /// public IEnumerable? Tools { get; set; } /// public ToolChoice? ToolChoice { get; set; } + /// + public bool? ParallelToolCalls { get; set; } + + /// + public TextGenerationTranslationOptions? TranslationOptions { get; set; } + /// public bool? IncrementalOutput { get; set; } } diff --git a/src/Cnblogs.DashScope.Core/TextGenerationPromptTokenDetails.cs b/src/Cnblogs.DashScope.Core/TextGenerationPromptTokenDetails.cs new file mode 100644 index 0000000..0b4cef6 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationPromptTokenDetails.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Token usage details. +/// +/// Token count of cached input. +public record TextGenerationPromptTokenDetails(int CachedTokens); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationSearchOptions.cs b/src/Cnblogs.DashScope.Core/TextGenerationSearchOptions.cs new file mode 100644 index 0000000..d0d8cb4 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationSearchOptions.cs @@ -0,0 +1,32 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Web search options +/// +public class TextGenerationSearchOptions +{ + /// + /// Show search result in response. Defaults to false. + /// + public bool? EnableSource { get; set; } + + /// + /// Include citation in output. Defaults to false. + /// + public bool? EnableCitation { get; set; } + + /// + /// Citation format. Defaults to "[<number>]" + /// + public string? CitationFormat { get; set; } + + /// + /// Force model to use web search. Defaults to false. + /// + public bool? ForcedSearch { get; set; } + + /// + /// How many search records should be provided to model. "standard" - 5 records. "pro" - 10 records. + /// + public string? SearchStrategy { get; set; } +} diff --git a/src/Cnblogs.DashScope.Core/TextGenerationTokenDetails.cs b/src/Cnblogs.DashScope.Core/TextGenerationTokenDetails.cs deleted file mode 100644 index d8e5b18..0000000 --- a/src/Cnblogs.DashScope.Core/TextGenerationTokenDetails.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Cnblogs.DashScope.Core; - -/// -/// Token usage details. -/// -/// Token count of cached input tokens -public record TextGenerationTokenDetails(int CachedTokens); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationTokenUsage.cs b/src/Cnblogs.DashScope.Core/TextGenerationTokenUsage.cs index 7662d7d..c908e55 100644 --- a/src/Cnblogs.DashScope.Core/TextGenerationTokenUsage.cs +++ b/src/Cnblogs.DashScope.Core/TextGenerationTokenUsage.cs @@ -14,7 +14,12 @@ public class TextGenerationTokenUsage /// /// Input token details. /// - public TextGenerationTokenDetails? PromptTokensDetails { get; set; } + public TextGenerationPromptTokenDetails? PromptTokensDetails { get; set; } + + /// + /// Output token details. + /// + public TextGenerationOutputTokenDetails? OutputTokensDetails { get; set; } /// /// The number of output token. diff --git a/src/Cnblogs.DashScope.Core/TextGenerationTopLogprobContent.cs b/src/Cnblogs.DashScope.Core/TextGenerationTopLogprobContent.cs new file mode 100644 index 0000000..9f19187 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationTopLogprobContent.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Core; + +/// +/// Represents one choice of most possibility alternative tokens. +/// +/// The token content. +/// The token content in UTF-8 byte array. +/// Possibility, null when possibility is too low. +public record TextGenerationTopLogprobContent( + string Token, + [property: JsonConverter(typeof(ByteArrayLiteralConvertor))] + byte[] Bytes, + float? Logprob); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationTranslationOptions.cs b/src/Cnblogs.DashScope.Core/TextGenerationTranslationOptions.cs new file mode 100644 index 0000000..d77f7c8 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationTranslationOptions.cs @@ -0,0 +1,32 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Configurations when using translation models. +/// +public class TextGenerationTranslationOptions +{ + /// + /// The language name of the input text. Use 'auto' to enable auto-detection. + /// + public string SourceLang { get; set; } = "auto"; + + /// + /// The language name of the output text. + /// + public string TargetLang { get; set; } = string.Empty; + + /// + /// Term list for translation. + /// + public IEnumerable? Terms { get; set; } + + /// + /// Sample texts for translation + /// + public IEnumerable? TmList { get; set; } + + /// + /// Domain info about the source text. Only supports English. + /// + public string? Domains { get; set; } +} diff --git a/src/Cnblogs.DashScope.Core/TextGenerationWebSearchInfo.cs b/src/Cnblogs.DashScope.Core/TextGenerationWebSearchInfo.cs new file mode 100644 index 0000000..27da418 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationWebSearchInfo.cs @@ -0,0 +1,7 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Web search information. +/// +/// Web search results. +public record TextGenerationWebSearchInfo(List SearchResults); diff --git a/src/Cnblogs.DashScope.Core/TextGenerationWebSearchResult.cs b/src/Cnblogs.DashScope.Core/TextGenerationWebSearchResult.cs new file mode 100644 index 0000000..ccdf085 --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TextGenerationWebSearchResult.cs @@ -0,0 +1,11 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// Represents one web search record. +/// +/// Source site name. +/// Source site favicon url. +/// Serial number of search records. +/// Page title. +/// Page url. +public record TextGenerationWebSearchResult(string SiteName, string Icon, int Index, string Title, string Url); diff --git a/src/Cnblogs.DashScope.Core/TranslationReference.cs b/src/Cnblogs.DashScope.Core/TranslationReference.cs new file mode 100644 index 0000000..256056a --- /dev/null +++ b/src/Cnblogs.DashScope.Core/TranslationReference.cs @@ -0,0 +1,8 @@ +namespace Cnblogs.DashScope.Core; + +/// +/// A text pair that used for translation reference. +/// +/// The text in source language. +/// The text in target language. +public record TranslationReference(string Source, string Target); diff --git a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuan2Llm.cs b/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuan2Llm.cs deleted file mode 100644 index 8ee2af3..0000000 --- a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuan2Llm.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.BaiChuan; - -/// -/// BaiChuan2 model, supports prompt and message format. -/// -public enum BaiChuan2Llm -{ - /// - /// baichuan2-7b-chat-v1 - /// - BaiChuan2_7BChatV1 = 1, - - /// - /// baichuan2-13b-chat-v1 - /// - BaiChuan2_13BChatV1 = 2 -} diff --git a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlm.cs b/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlm.cs deleted file mode 100644 index 53c5d8a..0000000 --- a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlm.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.BaiChuan; - -/// -/// Supported baichuan model: https://help.aliyun.com/zh/dashscope/developer-reference/api-details-2 -/// -public enum BaiChuanLlm -{ - /// - /// baichuan-7b-v1 - /// - BaiChuan7B = 1 -} diff --git a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlmName.cs b/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlmName.cs deleted file mode 100644 index b5ffff1..0000000 --- a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanLlmName.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.BaiChuan; - -internal static class BaiChuanLlmName -{ - public static string GetModelName(this BaiChuanLlm llm) - { - return llm switch - { - BaiChuanLlm.BaiChuan7B => "baichuan-7b-v1", - _ => ThrowHelper.UnknownModelName(nameof(llm), llm) - }; - } - - public static string GetModelName(this BaiChuan2Llm llm) - { - return llm switch - { - BaiChuan2Llm.BaiChuan2_7BChatV1 => "baichuan2-7b-chat-v1", - BaiChuan2Llm.BaiChuan2_13BChatV1 => "baichuan2-13b-chat-v1", - _ => ThrowHelper.UnknownModelName(nameof(llm), llm) - }; - } -} diff --git a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanTextGenerationApi.cs b/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanTextGenerationApi.cs deleted file mode 100644 index ef3ec60..0000000 --- a/src/Cnblogs.DashScope.Sdk/BaiChuan/BaiChuanTextGenerationApi.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.BaiChuan; - -/// -/// BaiChuan LLM generation apis, doc: https://help.aliyun.com/zh/dashscope/developer-reference/api-details-2 -/// -public static class BaiChuanTextGenerationApi -{ - /// - /// Get text completion from baichuan model. - /// - /// The . - /// The llm to use. - /// The prompt to generate completion from. - /// - public static Task> GetBaiChuanTextCompletionAsync( - this IDashScopeClient client, - BaiChuanLlm llm, - string prompt) - { - return client.GetBaiChuanTextCompletionAsync(llm.GetModelName(), prompt); - } - - /// - /// Get text completion from baichuan model. - /// - /// The . - /// The llm to use. - /// The prompt to generate completion from. - /// - public static Task> GetBaiChuanTextCompletionAsync( - this IDashScopeClient client, - string llm, - string prompt) - { - return client.GetTextCompletionAsync( - new ModelRequest - { - Model = llm, - Input = new TextGenerationInput { Prompt = prompt }, - Parameters = null - }); - } - - /// - /// Get text completion from baichuan model. - /// - /// The . - /// The model name. - /// The context messages. - /// Can be 'text' or 'message', defaults to 'text'. Call to get available options. - /// - public static Task> GetBaiChuanTextCompletionAsync( - this IDashScopeClient client, - BaiChuan2Llm llm, - IEnumerable messages, - string? resultFormat = null) - { - return client.GetBaiChuanTextCompletionAsync(llm.GetModelName(), messages, resultFormat); - } - - /// - /// Get text completion from baichuan model. - /// - /// The . - /// The model name. - /// The context messages. - /// Can be 'text' or 'message', defaults to 'text'. Call to get available options. - /// - public static Task> GetBaiChuanTextCompletionAsync( - this IDashScopeClient client, - string llm, - IEnumerable messages, - string? resultFormat = null) - { - return client.GetTextCompletionAsync( - new ModelRequest - { - Model = llm, - Input = new TextGenerationInput { Messages = messages }, - Parameters = string.IsNullOrEmpty(resultFormat) == false - ? new TextGenerationParameters { ResultFormat = resultFormat } - : null - }); - } -} diff --git a/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj b/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj index 3480ef8..68ba835 100644 --- a/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj +++ b/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj @@ -4,9 +4,6 @@ true Cnblogs;Dashscope;AI;Sdk;Embedding; - - - diff --git a/src/Cnblogs.DashScope.Sdk/FunctionDefinition.cs b/src/Cnblogs.DashScope.Sdk/FunctionDefinition.cs index 1344496..042f5c5 100644 --- a/src/Cnblogs.DashScope.Sdk/FunctionDefinition.cs +++ b/src/Cnblogs.DashScope.Sdk/FunctionDefinition.cs @@ -1,5 +1,4 @@ using Cnblogs.DashScope.Core; -using Json.Schema; namespace Cnblogs.DashScope.Sdk; @@ -13,8 +12,8 @@ public record FunctionDefinition : IFunctionDefinition /// /// The name of the function. /// Descriptions about this function for model to reference on. - /// Parameter maps of this function. - public FunctionDefinition(string name, string description, JsonSchema? parameters) + /// Parameter maps of this function, can be dictionary or JsonSchema. + public FunctionDefinition(string name, string description, object? parameters) { Name = name; Description = description; diff --git a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2Model.cs b/src/Cnblogs.DashScope.Sdk/Llama2/Llama2Model.cs deleted file mode 100644 index 827fd14..0000000 --- a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2Model.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.Llama2; - -/// -/// Supported models for LLaMa2. -/// -public enum Llama2Model -{ - /// - /// llama2-7b-chat-v2 - /// - Chat7Bv2 = 1, - - /// - /// llama2-13b-chat-v2 - /// - Chat13Bv2 = 2 -} diff --git a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2ModelNames.cs b/src/Cnblogs.DashScope.Sdk/Llama2/Llama2ModelNames.cs deleted file mode 100644 index 44357d3..0000000 --- a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2ModelNames.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Cnblogs.DashScope.Sdk.Llama2; - -internal static class Llama2ModelNames -{ - public static string GetModelName(this Llama2Model model) - { - return model switch - { - Llama2Model.Chat7Bv2 => "llama2-7b-chat-v2", - Llama2Model.Chat13Bv2 => "llama2-13b-chat-v2", - _ => ThrowHelper.UnknownModelName(nameof(model), model) - }; - } -} diff --git a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2TextGenerationApi.cs b/src/Cnblogs.DashScope.Sdk/Llama2/Llama2TextGenerationApi.cs deleted file mode 100644 index 5fa9b45..0000000 --- a/src/Cnblogs.DashScope.Sdk/Llama2/Llama2TextGenerationApi.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.Llama2; - -/// -/// Extensions for llama2 text generation, docs: https://help.aliyun.com/zh/dashscope/developer-reference/api-details-11 -/// -public static class Llama2TextGenerationApi -{ - /// - /// Get text completion from llama2 model. - /// - /// The . - /// The model name. - /// The context messages. - /// Can be 'text' or 'message'. Call to get available options. - /// - public static async Task> - GetLlama2TextCompletionAsync( - this IDashScopeClient client, - Llama2Model model, - IEnumerable messages, - string? resultFormat = null) - { - return await client.GetLlama2TextCompletionAsync(model.GetModelName(), messages, resultFormat); - } - - /// - /// Get text completion from llama2 model. - /// - /// The . - /// The model name. - /// The context messages. - /// Can be 'text' or 'message'. Call to get available options. - /// - public static async Task> - GetLlama2TextCompletionAsync( - this IDashScopeClient client, - string model, - IEnumerable messages, - string? resultFormat = null) - { - return await client.GetTextCompletionAsync( - new ModelRequest - { - Model = model, - Input = new TextGenerationInput { Messages = messages }, - Parameters = resultFormat != null - ? new TextGenerationParameters { ResultFormat = resultFormat } - : null - }); - } -} diff --git a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs index fa65480..abeeade 100644 --- a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs +++ b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModel.cs @@ -58,5 +58,25 @@ public enum QWenMultimodalModel /// /// qwen-audio-turbo-latest /// - QWenAudioTurboLatest = 11 + QWenAudioTurboLatest = 11, + + /// + /// qvq-max + /// + QvQMax = 12, + + /// + /// qvq-max-latest + /// + QvQMaxLatest = 13, + + /// + /// qvq-plus + /// + QvQPlus = 14, + + /// + /// qvq-plus-latest + /// + QvQPlusLatest = 15 } diff --git a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs index b5bd02a..e22aeda 100644 --- a/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs +++ b/src/Cnblogs.DashScope.Sdk/QWenMultimodal/QWenMultimodalModelNames.cs @@ -17,6 +17,10 @@ public static string GetModelName(this QWenMultimodalModel multimodalModel) QWenMultimodalModel.QWenVlPlusLatest => "qwen-vl-plus-latest", QWenMultimodalModel.QWenVlOcrLatest => "qwen-vl-ocr-latest", QWenMultimodalModel.QWenAudioTurboLatest => "qwen-audio-turbo-latest", + QWenMultimodalModel.QvQMax => "qvq-max", + QWenMultimodalModel.QvQMaxLatest => "qvq-max-latest", + QWenMultimodalModel.QvQPlus => "qvq-plus", + QWenMultimodalModel.QvQPlusLatest => "qvq-plus-latest", _ => ThrowHelper.UnknownModelName(nameof(multimodalModel), multimodalModel) }; } diff --git a/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModel.cs b/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModel.cs index 808db24..72af726 100644 --- a/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModel.cs +++ b/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModel.cs @@ -19,4 +19,9 @@ public enum TextEmbeddingModel /// text-embedding-v3 /// TextEmbeddingV3 = 3, + + /// + /// text-embedding-v4 + /// + TextEmbeddingV4 = 4 } diff --git a/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModelNames.cs b/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModelNames.cs index 410c33e..21d6b7d 100644 --- a/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModelNames.cs +++ b/src/Cnblogs.DashScope.Sdk/TextEmbedding/TextEmbeddingModelNames.cs @@ -9,6 +9,7 @@ public static string GetModelName(this TextEmbeddingModel model) TextEmbeddingModel.TextEmbeddingV1 => "text-embedding-v1", TextEmbeddingModel.TextEmbeddingV2 => "text-embedding-v2", TextEmbeddingModel.TextEmbeddingV3 => "text-embedding-v3", + TextEmbeddingModel.TextEmbeddingV4 => "text-embedding-v4", _ => ThrowHelper.UnknownModelName(nameof(model), model), }; } diff --git a/src/Cnblogs.DashScope.Sdk/Wanx/WanxModel.cs b/src/Cnblogs.DashScope.Sdk/Wanx/WanxModel.cs index f278eeb..3d19fdd 100644 --- a/src/Cnblogs.DashScope.Sdk/Wanx/WanxModel.cs +++ b/src/Cnblogs.DashScope.Sdk/Wanx/WanxModel.cs @@ -8,5 +8,20 @@ public enum WanxModel /// /// wanx-v1 /// - WanxV1 = 1 + WanxV1 = 1, + + /// + /// wanx2.1-t2i-plus + /// + WanxV21Plus = 2, + + /// + /// wanx2.1-t2i-turbo + /// + WanxV21Turbo = 3, + + /// + /// wanx2.0-t2i-turbo + /// + WanxV20Turbo = 4 } diff --git a/src/Cnblogs.DashScope.Sdk/Wanx/WanxModelNames.cs b/src/Cnblogs.DashScope.Sdk/Wanx/WanxModelNames.cs index ab04555..8e04751 100644 --- a/src/Cnblogs.DashScope.Sdk/Wanx/WanxModelNames.cs +++ b/src/Cnblogs.DashScope.Sdk/Wanx/WanxModelNames.cs @@ -7,6 +7,9 @@ public static string GetModelName(this WanxModel model) return model switch { WanxModel.WanxV1 => "wanx-v1", + WanxModel.WanxV21Plus => "wanx2.1-t2i-plus", + WanxModel.WanxV21Turbo => "wanx2.1-t2i-turbo", + WanxModel.WanxV20Turbo => "wanx2.0-t2i-turbo", _ => ThrowHelper.UnknownModelName(nameof(model), model) }; } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs b/test/Cnblogs.DashScope.AI.UnitTests/ChatClientTests.cs similarity index 87% rename from test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs rename to test/Cnblogs.DashScope.AI.UnitTests/ChatClientTests.cs index c1f5096..8bd80fa 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs +++ b/test/Cnblogs.DashScope.AI.UnitTests/ChatClientTests.cs @@ -1,12 +1,12 @@ using System.Text; using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; + using Microsoft.Extensions.AI; using NSubstitute; using NSubstitute.Extensions; -namespace Cnblogs.DashScope.Sdk.UnitTests; +namespace Cnblogs.DashScope.AI.UnitTests; public class ChatClientTests { @@ -28,7 +28,7 @@ public async Task ChatClient_TextCompletion_SuccessAsync() // Act var response = await client.GetResponseAsync( content, - new ChatOptions() + new ChatOptions { FrequencyPenalty = parameter?.RepetitionPenalty, PresencePenalty = parameter?.PresencePenalty, @@ -46,7 +46,7 @@ public async Task ChatClient_TextCompletion_SuccessAsync() Arg.Is>( m => m.IsEquivalent(testCase.RequestModel)), Arg.Any()); - response.Messages[0].Text.Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content); + Assert.Equal(testCase.ResponseModel.Output.Choices![0].Message.Content, response.Messages[0].Text); } [Fact] @@ -69,7 +69,7 @@ public async Task ChatClient_TextCompletionStream_SuccessAsync() // Act var response = client.GetStreamingResponseAsync( content, - new ChatOptions() + new ChatOptions { FrequencyPenalty = parameter?.RepetitionPenalty, PresencePenalty = parameter?.PresencePenalty, @@ -79,7 +79,7 @@ public async Task ChatClient_TextCompletionStream_SuccessAsync() Temperature = parameter?.Temperature, TopK = parameter?.TopK, TopP = parameter?.TopP, - StopSequences = ["你好"], + StopSequences = new List { "你好" }, ToolMode = ChatToolMode.Auto }); var text = new StringBuilder(); @@ -93,7 +93,7 @@ public async Task ChatClient_TextCompletionStream_SuccessAsync() Arg.Is>( m => m.IsEquivalent(testCase.RequestModel)), Arg.Any()); - text.ToString().Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content); + Assert.Equal(testCase.ResponseModel.Output.Choices![0].Message.Content, text.ToString()); } [Fact] @@ -113,7 +113,10 @@ public async Task ChatClient_ImageRecognition_SuccessAsync() { new( ChatRole.User, - [new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text)]) + new List + { + new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text) + }), }; var parameter = testCase.RequestModel.Parameters; @@ -136,8 +139,7 @@ public async Task ChatClient_ImageRecognition_SuccessAsync() await dashScopeClient.Received().GetMultimodalGenerationAsync( Arg.Is>(m => m.IsEquivalent(testCase.RequestModel)), Arg.Any()); - response.Messages[0].Text.Should() - .BeEquivalentTo(testCase.ResponseModel.Output.Choices[0].Message.Content[0].Text); + Assert.Equal(testCase.ResponseModel.Output.Choices[0].Message.Content[0].Text, response.Messages[0].Text); } [Fact] @@ -157,14 +159,17 @@ public async Task ChatClient_ImageRecognitionStream_SuccessAsync() { new( ChatRole.User, - [new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text)]) + new List + { + new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text) + }) }; var parameter = testCase.RequestModel.Parameters; // Act var response = client.GetStreamingResponseAsync( messages, - new ChatOptions() + new ChatOptions { FrequencyPenalty = parameter?.RepetitionPenalty, PresencePenalty = parameter?.PresencePenalty, @@ -185,6 +190,6 @@ public async Task ChatClient_ImageRecognitionStream_SuccessAsync() _ = dashScopeClient.Received().GetMultimodalGenerationStreamAsync( Arg.Is>(m => m.IsEquivalent(testCase.RequestModel)), Arg.Any()); - text.ToString().Should().Be(testCase.ResponseModel.Output.Choices.First().Message.Content[0].Text); + Assert.Equal(testCase.ResponseModel.Output.Choices.First().Message.Content[0].Text, text.ToString()); } } diff --git a/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj b/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj new file mode 100644 index 0000000..293114c --- /dev/null +++ b/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj @@ -0,0 +1,31 @@ + + + + net8.0 + enable + enable + false + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/EmbeddingClientTests.cs b/test/Cnblogs.DashScope.AI.UnitTests/EmbeddingClientTests.cs similarity index 76% rename from test/Cnblogs.DashScope.Sdk.UnitTests/EmbeddingClientTests.cs rename to test/Cnblogs.DashScope.AI.UnitTests/EmbeddingClientTests.cs index 96e21b4..b8c17e6 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/EmbeddingClientTests.cs +++ b/test/Cnblogs.DashScope.AI.UnitTests/EmbeddingClientTests.cs @@ -1,11 +1,10 @@ using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using Microsoft.Extensions.AI; using NSubstitute; using NSubstitute.Extensions; -namespace Cnblogs.DashScope.Sdk.UnitTests; +namespace Cnblogs.DashScope.AI.UnitTests; public class EmbeddingClientTests { @@ -27,17 +26,18 @@ public async Task EmbeddingClient_Text_SuccessAsync() // Act var response = await client.GenerateAsync( content, - new EmbeddingGenerationOptions() + new EmbeddingGenerationOptions { ModelId = testCase.RequestModel.Model, Dimensions = parameter?.Dimension }); // Assert _ = dashScopeClient.Received().GetEmbeddingsAsync( - Arg.Is>( - m => m.IsEquivalent(testCase.RequestModel)), + Arg.Is>(m + => m.IsEquivalent(testCase.RequestModel)), Arg.Any()); - response.Select(x => x.Vector.ToArray()).Should() - .BeEquivalentTo(testCase.ResponseModel.Output.Embeddings.Select(x => x.Embedding)); + Assert.Equivalent( + testCase.ResponseModel.Output.Embeddings.Select(x => x.Embedding), + response.Select(x => x.Vector.ToArray())); } } diff --git a/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Cnblogs.DashScope.Sdk.SnapshotGenerator.csproj b/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Cnblogs.DashScope.Sdk.SnapshotGenerator.csproj deleted file mode 100644 index 8c791ae..0000000 --- a/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Cnblogs.DashScope.Sdk.SnapshotGenerator.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - false - - - - - - - diff --git a/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Program.cs b/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Program.cs deleted file mode 100644 index 3f99f6b..0000000 --- a/test/Cnblogs.DashScope.Sdk.SnapshotGenerator/Program.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System.Net; -using System.Text; - -const string basePath = "../../../../Cnblogs.DashScope.Sdk.UnitTests/RawHttpData"; -var snapshots = new DirectoryInfo(basePath); -Console.WriteLine("Reading key from environment variable DASHSCOPE_KEY"); -var apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY"); -if (string.IsNullOrEmpty(apiKey)) -{ - Console.Write("ApiKey > "); - apiKey = Console.ReadLine(); -} - -var handler = new SocketsHttpHandler() { AutomaticDecompression = DecompressionMethods.All, }; -var client = new HttpClient(handler) { BaseAddress = new Uri("https://dashscope.aliyuncs.com/api/v1/") }; -client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); - -while (true) -{ - Console.Write("Snapshot Name > "); - var snapshotName = Console.ReadLine()?.Trim(); - if (string.IsNullOrEmpty(snapshotName)) - { - continue; - } - - var snapshot = snapshots.EnumerateFiles().Where(s => s.Name.StartsWith(snapshotName)) - .Select(s => s.Name.Split('.').First()).Distinct() - .ToList(); - if (snapshot.Count == 0) - { - Console.WriteLine($"No snapshot was found with name: {snapshotName}"); - } - - Console.WriteLine($"Updating {snapshot.Count} snapshots ..."); - foreach (var name in snapshot) - { - Console.WriteLine($"Updating {name}"); - await UpdateSnapshotsAsync(client, name); - Console.WriteLine($"{name} updated"); - } -} - -static async Task UpdateSnapshotsAsync(HttpClient client, string name) -{ - var requestHeader = await File.ReadAllLinesAsync(Path.Combine(basePath, $"{name}.request.header.txt")); - var requestBodyFile = Path.Combine(basePath, $"{name}.request.body.json"); - var requestBody = File.Exists(requestBodyFile) - ? await File.ReadAllTextAsync(Path.Combine(basePath, $"{name}.request.body.json")) - : string.Empty; - var firstLine = requestHeader[0].Split(' '); - var method = HttpMethod.Parse(firstLine[0]); - var request = new HttpRequestMessage(method, firstLine[1]); - var contentType = "application/json"; - foreach (var header in requestHeader.Skip(1)) - { - if (string.IsNullOrWhiteSpace(header)) - { - continue; - } - - var values = header.Split(':', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); - if (values[0] == "Content-Type") - { - contentType = values[1]; - continue; - } - - if (values[0] == "Content-Length") - { - continue; - } - - request.Headers.Add(values[0], values[1]); - } - - if (string.IsNullOrWhiteSpace(requestBodyFile) == false) - { - request.Content = new StringContent(requestBody, Encoding.Default, contentType); - } - - var response = await client.SendAsync(request); - var responseBody = await response.Content.ReadAsStringAsync(); - var responseHeaderFile = new StringBuilder(); - responseHeaderFile.AppendLine($"HTTP/1.1 {(int)response.StatusCode} {response.StatusCode}"); - responseHeaderFile = response.Headers.Aggregate( - responseHeaderFile, - (sb, pair) => sb.AppendLine($"{pair.Key}: {string.Join(',', pair.Value)}")); - await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.header.txt"), responseHeaderFile.ToString()); - await File.WriteAllTextAsync(Path.Combine(basePath, $"{name}.response.body.txt"), responseBody); -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ApplicationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ApplicationSerializationTests.cs index a8021a0..6552149 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ApplicationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ApplicationSerializationTests.cs @@ -1,5 +1,4 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,7 +20,7 @@ public async Task SingleCompletion_TextNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -39,7 +38,7 @@ public async Task SingleCompletion_ThoughtNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -58,11 +57,17 @@ public async Task SingleCompletion_TextSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.FinishReason.Should().Be("null")); - outputs.Last().Should().BeEquivalentTo( - testCase.ResponseModel, - o => o.Excluding(y => y.Output.Text).Excluding(x => x.Output.Thoughts)); - text.Should().Be(testCase.ResponseModel.Output.Text); + Assert.All(outputs.SkipLast(1), x => Assert.Equal("null", x.Output.FinishReason)); + Assert.Equal(testCase.ResponseModel.Output.Text, text); + var last = outputs.Last(); + last = last with + { + Output = last.Output with + { + Text = testCase.ResponseModel.Output.Text, Thoughts = testCase.ResponseModel.Output.Thoughts + } + }; + Assert.Equivalent(testCase.ResponseModel, last); } [Fact] @@ -80,7 +85,7 @@ public async Task ConversationCompletion_SessionIdNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -98,7 +103,7 @@ public async Task ConversationCompletion_MessageNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -116,7 +121,7 @@ public async Task SingleCompletion_MemoryNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -134,6 +139,6 @@ public async Task SingleCompletion_WorkflowNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/BackgroundGenerationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/BackgroundGenerationSerializationTests.cs index 6754aa2..14022b2 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/BackgroundGenerationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/BackgroundGenerationSerializationTests.cs @@ -1,5 +1,5 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; + using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,6 +21,6 @@ public async Task BackgroundGeneration_CreateTask_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/BaiChuanApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/BaiChuanApiTests.cs deleted file mode 100644 index 1184b1a..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/BaiChuanApiTests.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.BaiChuan; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using NSubstitute; - -namespace Cnblogs.DashScope.Sdk.UnitTests; - -public class BaiChuanApiTests -{ - [Fact] - public async Task BaiChuanTextGeneration_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetBaiChuanTextCompletionAsync(BaiChuanLlm.BaiChuan7B, Cases.Prompt); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Model == "baichuan-7b-v1" && s.Input.Prompt == Cases.Prompt && s.Parameters == null)); - } - - [Fact] - public async Task BaiChuanTextGeneration_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetBaiChuanTextCompletionAsync(BaiChuanLlm.BaiChuan7B, Cases.Prompt); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Model == "baichuan-7b-v1" && s.Input.Prompt == Cases.Prompt && s.Parameters == null)); - } - - [Fact] - public async Task BaiChuan2TextGeneration_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetBaiChuanTextCompletionAsync( - BaiChuan2Llm.BaiChuan2_13BChatV1, - Cases.TextMessages, - ResultFormats.Message); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Model == "baichuan2-13b-chat-v1" - && s.Input.Messages == Cases.TextMessages - && s.Parameters != null - && s.Parameters.ResultFormat == ResultFormats.Message)); - } - - [Fact] - public async Task BaiChuan2TextGeneration_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetBaiChuanTextCompletionAsync( - Cases.CustomModelName, - Cases.TextMessages, - ResultFormats.Message); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Model == Cases.CustomModelName - && s.Input.Messages == Cases.TextMessages - && s.Parameters != null - && s.Parameters.ResultFormat == ResultFormats.Message)); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj index 3f82c79..2fd5793 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -1,39 +1,37 @@ - - false - true - + + net6.0 + false + true + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + - - - + + + - - - Always - - + + + Always + + - - - - + + + + diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientTests.cs index 93f7d4d..a2317bd 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientTests.cs @@ -1,12 +1,19 @@ using System.Net.Http.Headers; using System.Reflection; using Cnblogs.DashScope.Core; -using FluentAssertions; +using Xunit.Abstractions; namespace Cnblogs.DashScope.Sdk.UnitTests; public class DashScopeClientTests { + private readonly ITestOutputHelper _output; + + public DashScopeClientTests(ITestOutputHelper output) + { + _output = output; + } + [Fact] public void DashScopeClient_Constructor_New() { @@ -14,10 +21,8 @@ public void DashScopeClient_Constructor_New() const string apiKey = "apiKey"; // Act - var act = () => new DashScopeClient(apiKey); - - // Assert - act.Should().NotThrow(); + var client = new DashScopeClient(apiKey); + _output.WriteLine("hash: " + client.GetHashCode()); // do something to avoid optimization } [Theory] @@ -37,7 +42,7 @@ public void DashScopeClient_Constructor_NotCacheableParams( var value2 = HttpClientAccessor.GetValue(client2); // Assert - value.Should().NotBe(value2); + Assert.NotSame(value2, value); } [Theory] @@ -57,7 +62,7 @@ public void DashScopeClient_Constructor_CacheableParams( var value2 = HttpClientAccessor.GetValue(client2); // Assert - value.Should().Be(value2); + Assert.Same(value2, value); } [Fact] @@ -71,8 +76,7 @@ public void DashScopeClient_Constructor_WithApiKeyHeader() var value = HttpClientAccessor.GetValue(client) as HttpClient; // Assert - value?.DefaultRequestHeaders.Authorization?.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", apiKey)); + Assert.Equivalent(new AuthenticationHeaderValue("Bearer", apiKey), value?.DefaultRequestHeaders.Authorization); } [Fact] @@ -81,13 +85,13 @@ public void DashScopeClient_Constructor_WithWorkspaceId() // Arrange const string apiKey = "key"; const string workspaceId = "workspaceId"; - var client = new DashScopeClient(apiKey, null, null, workspaceId); + var client = new DashScopeClient(apiKey, workspaceId: workspaceId); // Act var value = HttpClientAccessor.GetValue(client) as HttpClient; // Assert - value?.DefaultRequestHeaders.GetValues("X-DashScope-WorkSpace").Should().BeEquivalentTo(workspaceId); + Assert.Equal(workspaceId, value?.DefaultRequestHeaders.GetValues("X-DashScope-WorkSpace").First()); } [Fact] @@ -102,7 +106,7 @@ public void DashScopeClient_Constructor_WithPrivateEndpoint() var value = HttpClientAccessor.GetValue(client) as HttpClient; // Assert - value?.BaseAddress.Should().BeEquivalentTo(new Uri(privateEndpoint)); + Assert.Equivalent(new Uri(privateEndpoint), value?.BaseAddress); } public static TheoryData ParamsShouldNotCache diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketFactoryTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketFactoryTests.cs new file mode 100644 index 0000000..4d13328 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketFactoryTests.cs @@ -0,0 +1,41 @@ +using System.Net; +using System.Net.WebSockets; +using System.Reflection; +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Sdk.UnitTests; + +public class DashScopeClientWebSocketFactoryTests +{ + private static readonly FieldInfo ClientWebSocketWrapperGetter = + typeof(DashScopeClientWebSocket).GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance)!; + + private static readonly FieldInfo ClientWebSocketGetter = + typeof(ClientWebSocketWrapper).GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance)!; + + private static readonly PropertyInfo RequestHeaderGetter = typeof(ClientWebSocketOptions).GetProperty( + "RequestHeaders", + BindingFlags.NonPublic | BindingFlags.Instance)!; + + [Fact] + public void CreateSocket_WithWorkspaceId_SetKeyAndSpaceIdProperly() + { + // Arrange + const string apiKey = "apikey"; + const string workspaceId = "some-space"; + var factory = new DashScopeClientWebSocketFactory(); + + // Act + var socket = factory.GetClientWebSocket(apiKey, workspaceId); + var socketWrapper = ClientWebSocketWrapperGetter.GetValue(socket) as ClientWebSocketWrapper; + var clientWebSocket = ClientWebSocketGetter.GetValue(socketWrapper) as ClientWebSocket; + var headers = RequestHeaderGetter.GetValue(clientWebSocket?.Options) as WebHeaderCollection; + + // Assert + Assert.NotNull(socketWrapper); + Assert.NotNull(headers); + Assert.Equal("bearer " + apiKey, headers.Get("Authorization")); + Assert.Equal(workspaceId, headers.Get("X-DashScope-WorkspaceId")); + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketPoolTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketPoolTests.cs new file mode 100644 index 0000000..e484586 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketPoolTests.cs @@ -0,0 +1,160 @@ +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Tests.Shared.Utils; +using NSubstitute; +using NSubstitute.Extensions; + +namespace Cnblogs.DashScope.Sdk.UnitTests; + +public class DashScopeClientWebSocketPoolTests +{ + [Fact] + public async Task RentSocket_PoolIsEmpty_CreateAsync() + { + // Arrange + var option = new DashScopeOptions(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(new DashScopeClientWebSocket(new FakeClientWebSocket())); + var pool = new DashScopeClientWebSocketPool(factory, option); + + // Act + var socket = await pool.RentSocketAsync(); + + // Assert + Assert.Equal(DashScopeWebSocketState.Ready, socket.Socket.State); + } + + [Fact] + public async Task RentSocket_HasAvailableSocket_ReturnAsync() + { + // Arrange + var option = new DashScopeOptions(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(new DashScopeClientWebSocket(new FakeClientWebSocket())); + var readySocket = factory.GetClientWebSocket(string.Empty); + await readySocket.ConnectAsync(new Uri(option.WebsocketBaseAddress)); + var pool = new DashScopeClientWebSocketPool(new[] { readySocket }, factory); + + // Act + var socket = await pool.RentSocketAsync(); + + // Assert + Assert.Equal(DashScopeWebSocketState.Ready, socket.Socket.State); + Assert.StrictEqual(readySocket, socket.Socket); + } + + [Fact] + public async Task RentSocket_SocketExpired_DisposeAndMoveNext() + { + // Arrange + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(_ => new DashScopeClientWebSocket(new FakeClientWebSocket())); + + var fakeSocket = new FakeClientWebSocket(); + var closedSocket = new DashScopeClientWebSocket(fakeSocket); + await closedSocket.CloseAsync(); + var pool = new DashScopeClientWebSocketPool(new[] { closedSocket }, factory); + + // Act + var socket = await pool.RentSocketAsync(); + + // Assert + Assert.Equal(DashScopeWebSocketState.Ready, socket.Socket.State); + Assert.NotStrictEqual(closedSocket, socket.Socket); + Assert.True(fakeSocket.DisposeCalled); + } + + [Fact] + public async Task RentSocket_PoolStarvation_ThrowAsync() + { + // Arrange + var option = new DashScopeOptions { SocketPoolSize = 3 }; + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(_ => new DashScopeClientWebSocket(new FakeClientWebSocket())); + var pool = new DashScopeClientWebSocketPool(factory, option); + await Task.WhenAll(Enumerable.Range(0, option.SocketPoolSize).Select(async _ => await pool.RentSocketAsync())); + + // Act + var act = async () => await pool.RentSocketAsync(); + + // Assert + await Assert.ThrowsAsync(act); + } + + [Fact] + public async Task Dispose_ManuallyDispose_DisposeAllPooledSocketsAsync() + { + // Arrange + var option = new DashScopeOptions(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(_ => new DashScopeClientWebSocket(new FakeClientWebSocket())); + var fake1 = new FakeClientWebSocket(); + var fake2 = new FakeClientWebSocket(); + var s1 = new DashScopeClientWebSocket(fake1); + var s2 = new DashScopeClientWebSocket(fake2); + var sockets = new[] { s1, s2 }; + foreach (var socket in sockets) + { + await socket.ConnectAsync(new Uri(option.WebsocketBaseAddress)); + } + + var pool = new DashScopeClientWebSocketPool(sockets, factory); + + // Act + var active = await pool.RentSocketAsync(); + pool.Dispose(); + + // Assert + Assert.NotNull(active); + Assert.True(fake1.DisposeCalled); + Assert.True(fake2.DisposeCalled); + } + + [Fact] + public async Task ReturnSocket_SocketNotReady_DisposeAsync() + { + // Arrange + var option = new DashScopeOptions(); + var fakeSocket = new FakeClientWebSocket(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(new DashScopeClientWebSocket(fakeSocket)); + var pool = new DashScopeClientWebSocketPool(factory, option); + + // Act + var socket = await pool.RentSocketAsync(); + await fakeSocket.WriteServerCloseAsync(); + pool.ReturnSocket(socket.Socket); + + // Assert + Assert.Equal(0, pool.ActiveSocketCount); + Assert.Equal(0, pool.AvailableSocketCount); + Assert.Equal(DashScopeWebSocketState.Closed, socket.Socket.State); + Assert.True(fakeSocket.DisposeCalled); + } + + [Fact] + public async Task ReturnSocket_SocketReady_SaveAsync() + { + // Arrange + var option = new DashScopeOptions(); + var fakeSocket = new FakeClientWebSocket(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(new DashScopeClientWebSocket(fakeSocket)); + var pool = new DashScopeClientWebSocketPool(factory, option); + + // Act + var socket = await pool.RentSocketAsync(); + pool.ReturnSocket(socket.Socket); + + // Assert + Assert.Equal(1, pool.AvailableSocketCount); + Assert.Equal(0, pool.ActiveSocketCount); + Assert.False(fakeSocket.DisposeCalled); + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketTests.cs new file mode 100644 index 0000000..5f789c2 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketTests.cs @@ -0,0 +1,277 @@ +using System.Net; +using System.Net.WebSockets; +using System.Reflection; +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Core.Internals; +using Cnblogs.DashScope.Tests.Shared.Utils; +using NSubstitute; + +namespace Cnblogs.DashScope.Sdk.UnitTests; + +[Collection(nameof(SocketTestsCollection))] +public class DashScopeClientWebSocketTests +{ + private static readonly FieldInfo InnerSocketInfo = + typeof(DashScopeClientWebSocket).GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance) + ?? throw new InvalidOperationException( + $"Can not found {nameof(DashScopeClientWebSocket)}._client, please update this test after refactoring"); + + private static readonly PropertyInfo InnerRequestHeaderInfo = + typeof(ClientWebSocketOptions).GetProperty("RequestHeaders", BindingFlags.NonPublic | BindingFlags.Instance) + ?? throw new InvalidOperationException( + $"Can not found {nameof(ClientWebSocketOptions)}.RequestHeaders property, please update this test after framework change"); + + [Fact] + public void Constructor_UseApiKeyAndWorkspaceId_EnsureConfigured() + { + // Arrange + const string apiKey = "apiKey"; + const string workspaceId = "workspaceId"; + + // Act + var client = new DashScopeClientWebSocket(apiKey, workspaceId); + var headers = ExtractHeaders(client); + + // Assert + Assert.Equal($"bearer {apiKey}", headers.GetValues("Authorization")?.First()); + Assert.Equal("enable", headers.GetValues("X-DashScope-DataInspection")?.First()); + Assert.Equal(workspaceId, headers.GetValues("X-DashScope-WorkspaceId")?.First()); + } + + [Fact] + public void Constructor_UseApiKeyWithoutWorkspaceId_EnsureConfigured() + { + // Arrange + const string apiKey = "apiKey"; + + // Act + var client = new DashScopeClientWebSocket(apiKey); + var headers = ExtractHeaders(client); + + // Assert + Assert.Equal($"bearer {apiKey}", headers.GetValues("Authorization")?.First()); + Assert.Equal("enable", headers.GetValues("X-DashScope-DataInspection")?.First()); + Assert.Null(headers.GetValues("X-DashScope-WorkspaceId")); + } + + [Fact] + public void Constructor_UsePreconfiguredSocket_EnsureConfigured() + { + // Arrange + using var socket = new ClientWebSocketWrapper(new ClientWebSocket()); + + // Act + var client = new DashScopeClientWebSocket(socket); + + // Assert + Assert.StrictEqual(socket, InnerSocketInfo.GetValue(client)); + } + + [Fact] + public async Task ConnectAsync_InitialConnect_ChangeStateAsync() + { + // Arrange + var socket = Substitute.For(); + var client = new DashScopeClientWebSocket(socket); + var apiUri = new Uri("ws://test.com"); + + // Act + await client.ConnectAsync(apiUri); + + // Assert + Assert.Equal(DashScopeWebSocketState.Ready, client.State); + await socket.Received(1).ConnectAsync(Arg.Is(apiUri), Arg.Any()); + await socket.Received().ReceiveAsync(Arg.Any>(), Arg.Any()); + } + + [Fact] + public async Task ResetOutput_WithInitialOutput_CompleteThenCreateNewOutputAsync() + { + // Arrange + var socket = Substitute.For(); + var client = new DashScopeClientWebSocket(socket); + client.ResetOutput(); + var oldBinary = client.BinaryOutput; + var oldJson = client.JsonOutput; + var oldSignal = client.TaskStarted; + + // Act + client.ResetOutput(); + + // Assert + Assert.False(await oldSignal); + Assert.True(oldBinary.Completion.IsCompletedSuccessfully); + Assert.NotSame(oldBinary, client.BinaryOutput); + Assert.True(oldJson.Completion.IsCompletedSuccessfully); + Assert.NotSame(oldJson, client.JsonOutput); + Assert.NotSame(oldSignal, client.TaskStarted); + } + + [Fact] + public async Task SendMessageAsync_SocketClosed_ThrowAsync() + { + // Arrange + var socket = Substitute.For(); + var client = new DashScopeClientWebSocket(socket); + var snapshot = Snapshots.SpeechSynthesizer.RunTask; + await client.CloseAsync(); + + // Act + var act = () => client.SendMessageAsync(snapshot.Message); + + // Assert + await Assert.ThrowsAsync(act); + } + + [Fact] + public async Task SendMessageAsync_Connected_SendAsync() + { + // Arrange + var socket = Substitute.For(); + var client = new DashScopeClientWebSocket(socket); + var snapshot = Snapshots.SpeechSynthesizer.RunTask; + + // Act + await client.ConnectAsync(new Uri(DashScopeDefaults.WebsocketApiBaseAddress)); + await client.SendMessageAsync(snapshot.Message); + + // Assert + await socket.Received().SendAsync( + Arg.Is>(s => Checkers.IsJsonEquivalent(s, snapshot.GetMessageJson())), + WebSocketMessageType.Text, + true, + Arg.Any()); + } + + [Fact] + public async Task ReceiveMessageAsync_ServerClosed_CloseAsync() + { + // Arrange + var (_, dashScopeClientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + + // Act + await server.WriteServerCloseAsync(); + + // Assert + Assert.Equal(DashScopeWebSocketState.Closed, dashScopeClientWebSocket.State); + Assert.Equal(WebSocketCloseStatus.NormalClosure, server.CloseStatus); + } + + [Fact] + public async Task ReceiveMessageAsync_TaskStarted_UpdateStateToRunningAsync() + { + // Arrange + var (_, clientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + var snapshot = Snapshots.SpeechSynthesizer.TaskStarted; + var taskStarted = clientWebSocket.TaskStarted; + + // Act + await server.WriteServerMessageAsync(snapshot.GetMessageJson()); + var timeout = Task.Delay(2000); // socket handles message in other thread, wait for it. + var any = await Task.WhenAny(timeout, taskStarted); + + // Assert + Assert.Equal(any, taskStarted); + Assert.Equal(DashScopeWebSocketState.RunningTask, clientWebSocket.State); + } + + [Fact] + public async Task ReceiveMessageAsync_TaskFinished_UpdateStateToReadyAsync() + { + // Arrange + var (_, clientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + await server.WriteServerMessageAsync(Snapshots.SpeechSynthesizer.TaskStarted.GetMessageJson()); + await clientWebSocket.TaskStarted; + var snapshot = Snapshots.SpeechSynthesizer.TaskFinished; + var binaryOutput = clientWebSocket.BinaryOutput; + var jsonOutput = clientWebSocket.JsonOutput; + + // Act + await server.WriteServerMessageAsync(snapshot.GetMessageJson()); + var json = await jsonOutput.ReadAllAsync().ToListAsync(); + + // Assert + Assert.True(binaryOutput.Completion.IsCompleted); + Assert.True(jsonOutput.Completion.IsCompleted); + Assert.Equal(2, json.Count); + Assert.Equal(DashScopeWebSocketState.Ready, clientWebSocket.State); + } + + [Fact] + public async Task ReceiveMessageAsync_TaskFailed_CloseAndThrowAsync() + { + // Arrange + var (_, clientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + await server.WriteServerMessageAsync(Snapshots.SpeechSynthesizer.TaskStarted.GetMessageJson()); + await clientWebSocket.TaskStarted; + var taskFailed = Snapshots.SpeechSynthesizer.TaskFailed; + var binary = clientWebSocket.BinaryOutput; + var json = clientWebSocket.JsonOutput; + + // Act + await server.WriteServerMessageAsync(taskFailed.GetMessageJson()); + await server.WriteServerCloseAsync(); + var messages = await json.ReadAllAsync().ToListAsync(); + + // Assert + Assert.True(binary.Completion.IsCompleted); + Assert.True(json.Completion.IsCompleted); + Assert.Equal(2, messages.Count); + Assert.Equal(DashScopeWebSocketState.Closed, clientWebSocket.State); + } + + [Fact] + public async Task ReceiveMessageAsync_ReceiveBinary_WriteToBinaryOutputAsync() + { + // Arrange + var (_, clientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + await server.WriteServerMessageAsync(Snapshots.SpeechSynthesizer.TaskStarted.GetMessageJson()); + await clientWebSocket.TaskStarted; + var expectedAudio = Snapshots.SpeechSynthesizer.AudioTts; + var output = clientWebSocket.BinaryOutput; + var audioTask = output.ReadAllAsync().ToArrayAsync(); + + // Act + await server.WriteServerMessageAsync(expectedAudio); + await server.WriteServerMessageAsync(Snapshots.SpeechSynthesizer.TaskFinished.GetMessageJson()); + var audio = await audioTask; + + // Assert + Assert.True(output.Completion.IsCompleted); + Assert.Equal(expectedAudio, audio); + Assert.Equal(DashScopeWebSocketState.Ready, clientWebSocket.State); + } + + [Fact] + public async Task Dispose_ManuallyCalled_DisposeSocketAndOutputTogetherAsync() + { + // Arrange + var (_, clientWebSocket, server) = await Sut.GetSocketTestClientAsync(); + var output = clientWebSocket.BinaryOutput; + + // Act + clientWebSocket.Dispose(); + + // Assert + Assert.True(output.Completion.IsCompleted); + Assert.True(server.DisposeCalled); + } + + private static WebHeaderCollection ExtractHeaders(DashScopeClientWebSocket socket) + { + var obj = InnerSocketInfo.GetValue(socket); + if (obj is not IClientWebSocket clientWebSocket) + { + throw new InvalidOperationException($"Get null when trying to fetch {InnerSocketInfo.Name}"); + } + + obj = InnerRequestHeaderInfo.GetValue(clientWebSocket.Options); + if (obj is not WebHeaderCollection headers) + { + throw new InvalidOperationException( + $"Wrong type or null when trying to fetch {InnerRequestHeaderInfo.Name}"); + } + + return headers; + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketWrapperTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketWrapperTests.cs new file mode 100644 index 0000000..5d1ce82 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DashScopeClientWebSocketWrapperTests.cs @@ -0,0 +1,31 @@ +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Tests.Shared.Utils; +using NSubstitute; +using NSubstitute.Extensions; +using Xunit.Abstractions; + +namespace Cnblogs.DashScope.Sdk.UnitTests; + +public class DashScopeClientWebSocketWrapperTests +{ + [Fact] + public async Task Dispose_CallDispose_ReturnSocketToPoolAsync() + { + // Arrange + var option = new DashScopeOptions(); + var fakeSocket = new FakeClientWebSocket(); + var factory = Substitute.For(); + factory.Configure().GetClientWebSocket(Arg.Any(), Arg.Any()) + .Returns(new DashScopeClientWebSocket(fakeSocket)); + var pool = new DashScopeClientWebSocketPool(factory, option); + + // Act + var socket = await pool.RentSocketAsync(); + socket.Dispose(); + + // Assert + Assert.Equal(1, pool.AvailableSocketCount); + Assert.Equal(0, pool.ActiveSocketCount); + Assert.False(fakeSocket.DisposeCalled); + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs index 5bc1956..87643dd 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/DeepSeekTextGenerationApiTests.cs @@ -13,12 +13,29 @@ public async Task TextCompletion_UseEnum_SuccessAsync() var client = Substitute.For(); // Act - await client.GetDeepSeekChatCompletionAsync(DeepSeekLlm.DeepSeekR1, [TextChatMessage.User("你好")]); + await client.GetDeepSeekChatCompletionAsync( + DeepSeekLlm.DeepSeekR1, + new List { TextChatMessage.User("你好") }.AsReadOnly()); // Assert await client.Received().GetTextCompletionAsync( - Arg.Is>( - x => x.Model == "deepseek-r1" && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); + Arg.Is>(x + => x.Model == "deepseek-r1" && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); + } + + [Fact] + public async Task TextCompletion_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + + // Act + var act = async () => await client.GetDeepSeekChatCompletionAsync( + (DeepSeekLlm)(-1), + new List { TextChatMessage.User("你好") }.AsReadOnly()); + + // Assert + await Assert.ThrowsAsync(act); } [Fact] @@ -29,12 +46,14 @@ public async Task TextCompletion_UseCustomModel_SuccessAsync() var client = Substitute.For(); // Act - await client.GetDeepSeekChatCompletionAsync(customModel, [TextChatMessage.User("你好")]); + await client.GetDeepSeekChatCompletionAsync( + customModel, + new List { TextChatMessage.User("你好") }.AsReadOnly()); // Assert await client.Received().GetTextCompletionAsync( - Arg.Is>( - x => x.Model == customModel && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); + Arg.Is>(x + => x.Model == customModel && x.Input.Messages!.First().Content == "你好" && x.Parameters == null)); } [Fact] @@ -44,14 +63,15 @@ public void StreamCompletion_UseEnum_SuccessAsync() var client = Substitute.For(); // Act - _ = client.GetDeepSeekChatCompletionStreamAsync(DeepSeekLlm.DeepSeekV3, [TextChatMessage.User("你好")]); + _ = client.GetDeepSeekChatCompletionStreamAsync( + DeepSeekLlm.DeepSeekV3, + new List { TextChatMessage.User("你好") }.AsReadOnly()); // Assert _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>( - x => x.Model == "deepseek-v3" - && x.Input.Messages!.First().Content == "你好" - && x.Parameters!.IncrementalOutput == true)); + Arg.Is>(x => x.Model == "deepseek-v3" + && x.Input.Messages!.First().Content == "你好" + && x.Parameters!.IncrementalOutput == true)); } [Fact] @@ -62,13 +82,14 @@ public void StreamCompletion_CustomModel_SuccessAsync() var client = Substitute.For(); // Act - _ = client.GetDeepSeekChatCompletionStreamAsync(customModel, [TextChatMessage.User("你好")]); + _ = client.GetDeepSeekChatCompletionStreamAsync( + customModel, + new List { TextChatMessage.User("你好") }.AsReadOnly()); // Assert _ = client.Received().GetTextCompletionStreamAsync( - Arg.Is>( - x => x.Model == customModel - && x.Input.Messages!.First().Content == "你好" - && x.Parameters!.IncrementalOutput == true)); + Arg.Is>(x => x.Model == customModel + && x.Input.Messages!.First().Content == "你好" + && x.Parameters!.IncrementalOutput == true)); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ErrorTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ErrorTests.cs index e660852..3f3d9b5 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ErrorTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ErrorTests.cs @@ -1,6 +1,5 @@ using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; using NSubstitute.ExceptionExtensions; using NSubstitute.Extensions; @@ -21,7 +20,8 @@ public async Task Error_AuthError_ExceptionAsync() var act = async () => await client.GetTextCompletionAsync(testCase.RequestModel); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeEquivalentTo(testCase.ResponseModel); + var ex = await Assert.ThrowsAsync(act); + Assert.Equivalent(testCase.ResponseModel, ex.Error); handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); @@ -39,7 +39,8 @@ public async Task Error_ParameterErrorNoSse_ExceptionAsync() var act = async () => await client.GetTextCompletionAsync(testCase.RequestModel); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeEquivalentTo(testCase.ResponseModel); + var ex = await Assert.ThrowsAsync(act); + Assert.Equivalent(testCase.ResponseModel, ex.Error); handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); @@ -58,7 +59,8 @@ public async Task Error_ParameterErrorSse_ExceptionAsync() var act = async () => await stream.LastAsync(); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeEquivalentTo(testCase.ResponseModel); + var ex = await Assert.ThrowsAsync(act); + Assert.Equivalent(testCase.ResponseModel, ex.Error); handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); @@ -71,13 +73,15 @@ public async Task Error_NetworkError_ExceptionAsync() var (client, handler) = Sut.GetTestClient(); handler.Configure().MockSend(Arg.Any(), Arg.Any()) .Throws(new InvalidOperationException("Network error!")); + var testCase = Snapshots.TextGeneration.TextFormat.SinglePrompt; // Act var act = async () - => await client.GetTextCompletionAsync(Snapshots.TextGeneration.TextFormat.SinglePrompt.RequestModel); + => await client.GetTextCompletionAsync(testCase.RequestModel); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeNull(); + var ex = await Assert.ThrowsAsync(act); + Assert.Null(ex.Error); } [Fact] @@ -94,6 +98,7 @@ public async Task Error_OpenAiCompatibleError_ExceptionAsync() "other"); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeEquivalentTo(testCase.ResponseModel); + var ex = await Assert.ThrowsAsync(act); + Assert.Equivalent(testCase.ResponseModel, ex.Error); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/FileSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/FileSerializationTests.cs index 05faa58..5a9dac0 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/FileSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/FileSerializationTests.cs @@ -1,5 +1,5 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; + using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,7 +21,7 @@ public async Task File_Upload_SuccessAsync() handler.Received().MockSend( Arg.Is(r => r.RequestUri!.AbsolutePath == "/compatible-mode/v1/files"), Arg.Any()); - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -40,7 +40,7 @@ public async Task File_Get_SuccessAsync() Arg.Is( r => r.RequestUri!.AbsolutePath == "/compatible-mode/v1/files/" + testCase.ResponseModel.Id.Value), Arg.Any()); - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -55,7 +55,7 @@ public async Task File_List_SuccessAsync() var list = await client.ListFilesAsync(); // Assert - list.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, list); } [Fact] @@ -74,6 +74,6 @@ public async Task File_Delete_SuccessAsync() Arg.Is( r => r.RequestUri!.AbsolutePath == "/compatible-mode/v1/files/" + testCase.ResponseModel.Id.Value), Arg.Any()); - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ImageGenerationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ImageGenerationSerializationTests.cs index d0d30b7..ac1b04b 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ImageGenerationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ImageGenerationSerializationTests.cs @@ -1,5 +1,5 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; + using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,6 +21,6 @@ public async Task ImageGeneration_CreateTask_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ImageSynthesisSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ImageSynthesisSerializationTests.cs index 909c6bf..f6348ca 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ImageSynthesisSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ImageSynthesisSerializationTests.cs @@ -1,5 +1,4 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,6 +20,6 @@ public async Task ImageSynThesis_CreateTask_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Llama2TextGenerationApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Llama2TextGenerationApiTests.cs deleted file mode 100644 index 29c1a8c..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Llama2TextGenerationApiTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.Llama2; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using NSubstitute; - -namespace Cnblogs.DashScope.Sdk.UnitTests; - -public class Llama2TextGenerationApiTests -{ - [Fact] - public async Task Llama2_UseEnum_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetLlama2TextCompletionAsync(Llama2Model.Chat13Bv2, Cases.TextMessages, ResultFormats.Message); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages - && s.Model == "llama2-13b-chat-v2" - && s.Parameters != null - && s.Parameters.ResultFormat == ResultFormats.Message)); - } - - [Fact] - public async Task Llama2_CustomModel_SuccessAsync() - { - // Arrange - var client = Substitute.For(); - - // Act - _ = await client.GetLlama2TextCompletionAsync(Cases.CustomModelName, Cases.TextMessages, ResultFormats.Message); - - // Assert - _ = await client.Received().GetTextCompletionAsync( - Arg.Is>( - s => s.Input.Messages == Cases.TextMessages - && s.Model == Cases.CustomModelName - && s.Parameters != null - && s.Parameters.ResultFormat == ResultFormats.Message)); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/MultimodalGenerationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/MultimodalGenerationSerializationTests.cs index 8889981..5825b14 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/MultimodalGenerationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/MultimodalGenerationSerializationTests.cs @@ -1,7 +1,6 @@ using System.Text; using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -25,7 +24,7 @@ public async Task MultimodalGeneration_NoSse_SuccessAsync( handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Theory] @@ -41,18 +40,31 @@ public async Task MultimodalGeneration_Sse_SuccessAsync( // Act var message = new StringBuilder(); var outputs = await client.GetMultimodalGenerationStreamAsync(testCase.RequestModel).ToListAsync(); - outputs.ForEach( - x => message.Append(x.Output.Choices[0].Message.Content.FirstOrDefault()?.Text ?? string.Empty)); + outputs.ForEach(x + => message.Append(x.Output.Choices[0].Message.Content.FirstOrDefault()?.Text ?? string.Empty)); // Assert handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.Choices[0].FinishReason.Should().Be("null")); - outputs.Last().Should().BeEquivalentTo( - testCase.ResponseModel, - o => o.Excluding(y => y.Output.Choices[0].Message.Content)); - message.ToString().Should().Be(testCase.ResponseModel.Output.Choices[0].Message.Content[0].Text); + Assert.All(outputs.SkipLast(1), x => Assert.Equal("null", x.Output.Choices[0].FinishReason)); + Assert.Equal(testCase.ResponseModel.Output.Choices[0].Message.Content[0].Text, message.ToString()); + var last = outputs.Last(); + last = last with + { + Output = new MultimodalOutput( + new List + { + last.Output.Choices[0] with + { + Message = last.Output.Choices[0].Message with + { + Content = testCase.ResponseModel.Output.Choices[0].Message.Content + } + } + }) + }; + Assert.Equivalent(last, testCase.ResponseModel); } public static TheoryData, diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs index e3b5424..8e7a553 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenMultimodalApiTests.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; using Cnblogs.DashScope.Sdk.QWenMultimodal; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -8,13 +8,15 @@ namespace Cnblogs.DashScope.Sdk.UnitTests; public class QWenMultimodalApiTests { private static readonly List Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent("https://cdn.example.com/image.jpg"), - MultimodalMessageContent.TextContent("说明一下这张图片的内容") - ]) - ]; + new() + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent("https://cdn.example.com/image.jpg"), + MultimodalMessageContent.TextContent("说明一下这张图片的内容") + }.AsReadOnly()) + }; [Fact] public async Task Multimodal_UseEnum_SuccessAsync() @@ -28,8 +30,23 @@ public async Task Multimodal_UseEnum_SuccessAsync() // Assert _ = client.Received().GetMultimodalGenerationAsync( - Arg.Is>( - s => s.Model == "qwen-vl-max" && s.Input.Messages == Messages && s.Parameters == parameters)); + Arg.Is>(s + => s.Model == "qwen-vl-max" && s.Input.Messages == Messages && s.Parameters == parameters)); + } + + [Fact] + public async Task Multimodal_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + var parameters = new MultimodalParameters { Seed = 6666 }; + + // Act + var act = async () + => await client.GetQWenMultimodalCompletionAsync((QWenMultimodalModel)(-1), Messages, parameters); + + // Assert + await Assert.ThrowsAsync(act); } [Fact] @@ -44,8 +61,8 @@ public async Task Multimodal_CustomModel_SuccessAsync() // Assert _ = client.Received().GetMultimodalGenerationAsync( - Arg.Is>( - s => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); + Arg.Is>(s + => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); } [Fact] @@ -60,8 +77,8 @@ public void MultimodalStream_UseEnum_Success() // Assert _ = client.Received().GetMultimodalGenerationStreamAsync( - Arg.Is>( - s => s.Model == "qwen-vl-plus" && s.Input.Messages == Messages && s.Parameters == parameters)); + Arg.Is>(s + => s.Model == "qwen-vl-plus" && s.Input.Messages == Messages && s.Parameters == parameters)); } [Fact] @@ -76,7 +93,7 @@ public void Multimodal_CustomModel_Success() // Assert _ = client.Received().GetMultimodalGenerationStreamAsync( - Arg.Is>( - s => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); + Arg.Is>(s + => s.Model == Cases.CustomModelName && s.Input.Messages == Messages && s.Parameters == parameters)); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs index ad9d5fb..5fb1f6f 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTextGenerationApiTests.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; using Cnblogs.DashScope.Sdk.QWen; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -102,6 +102,20 @@ await client.Received().GetTextCompletionAsync( s => s.Input.Messages == Cases.TextMessages && s.Parameters == parameters && s.Model == "qwen-max-1201")); } + [Fact] + public async Task QWenChatCompletion_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + var parameters = new TextGenerationParameters { EnableSearch = true, ResultFormat = ResultFormats.Message }; + + // Act + var act = async () => await client.GetQWenChatCompletionAsync((QWenLlm)(-1), Cases.TextMessages, parameters); + + // Assert + await Assert.ThrowsAsync(act); + } + [Fact] public async Task QWenChatCompletion_CustomModel_SuccessAsync() { diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs index 8f91a35..ae7615d 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs @@ -1,5 +1,4 @@ using Cnblogs.DashScope.Core; -using FluentAssertions; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -9,475 +8,42 @@ public class QWenTokenizerTests "很不错的一款产品,送人的额,非常喜欢,很不错,好评哦,以后还会多多支持的\n已经吃了,感觉不错。第二次购买,这个价格很实惠,卖家还赠送了美容器和尺子,很愉悦的一次购物。\n衣服的质量杠杠的,很漂亮,不枉我等了这么久啊,喜欢,以后还来这里买,我一次买了四件不到200块钱,真好\n用了一段时间了,感觉比传统的风扇好用,广度大,档数多,静音效果也不错,关键是还很漂亮!\n这个热量低,比意面还低,关键是口感还好,挺好吃,多煮一会一级棒,我的减脂早餐就靠它了\n整体评价:好 使用效果:好 包装与外观:好 三好商品\n电视机很好,我给老爸买的,老人很喜欢,图像清晰,音质很好,老人喜欢我满意。\n宝贝很轻巧,打的时候网弹力很足,儿子非常喜欢,五分好评,还送了羽毛球噢!\n终于装上,风很大,热的还可以,排风声音不小,安装的师傅说不能直吹,安装的时候非常满意,最后还帮忙把棚顶给擦干净了,非常感谢。\n颜色很美。就是别人的盒子都是平整的,唯独我的盒子有很严重的压痕。本来想直接用这个盒子装胶带的..现在这个样子强迫症看着实在很糟心。压成这样要么包装有问题,要么本来产品就有问题。而卖家一直在甩锅快递。由于包裹是被家里人拆开的,所以我也不知道是什么样子的,不好跟卖家掰扯。但我看别的人都是纸盒装的,想来我这个也是纸盒装的。那么排除包装的原因的话,很可能就是寄过来的就是个瑕疵品。比起同样今天到货的另一家,有个小瑕疵立马给我补寄了一个,这家的处理方式真的..换货..或者直接道歉说疏忽我都接受的。甩锅真的不能忍。本来还给好几个人推了这家店...就挺失望的 以后应该不会来了。这坚定的甩锅态度我也不点退换了..请不要给我打电话改评,谢谢。"; private static readonly int[] Tokens = - [ - 109517, - 110659, - 82700, - 3837, - 36605, - 103947, - 61191, - 3837, - 115171, - 3837, - 109517, - 3837, - 102959, - 104170, - 3837, - 103934, - 104342, - 103235, - 100143, - 9370, - 198, - 99461, - 105705, - 3837, - 100681, - 100832, - 1773, - 106309, - 103946, - 3837, - 99487, - 97480, - 99165, - 109896, - 3837, - 108602, - 97706, - 109349, - 34187, - 105157, - 31548, - 33108, - 101489, - 44729, - 3837, - 99165, - 111985, - 99774, - 32571, - 102297, - 8997, - 102214, - 108042, - 103178, - 103178, - 9370, - 3837, - 117817, - 3837, - 16530, - 119117, - 35946, - 49567, - 34187, - 113260, - 103924, - 3837, - 99729, - 3837, - 103934, - 97706, - 115217, - 99565, - 3837, - 35946, - 99796, - 105275, - 63703, - 14224, - 99828, - 17, - 15, - 15, - 106734, - 3837, - 88051, - 52801, - 198, - 11622, - 99593, - 101430, - 34187, - 3837, - 100681, - 56006, - 105062, - 117814, - 52801, - 11622, - 3837, - 80942, - 26381, - 26288, - 3837, - 100104, - 8863, - 42140, - 3837, - 99541, - 78685, - 101062, - 116006, - 3837, - 111623, - 97706, - 117817, - 6313, - 198, - 99487, - 108461, - 99285, - 3837, - 56006, - 36589, - 27091, - 97706, - 99285, - 3837, - 111623, - 107816, - 108432, - 3837, - 101174, - 106678, - 3837, - 42140, - 104783, - 102947, - 105072, - 102321, - 3837, - 97611, - 99536, - 100553, - 102589, - 80158, - 99904, - 99652, - 34187, - 198, - 101932, - 103964, - 5122, - 52801, - 85658, - 101062, - 5122, - 52801, - 94305, - 227, - 98641, - 57218, - 105502, - 5122, - 52801, - 220, - 44991, - 52801, - 45943, - 198, - 115281, - 101243, - 3837, - 35946, - 89012, - 114198, - 108850, - 3837, - 102032, - 108295, - 3837, - 107553, - 104542, - 3837, - 78685, - 99178, - 101243, - 3837, - 102032, - 99729, - 35946, - 100545, - 8997, - 105882, - 99165, - 99578, - 100084, - 3837, - 75437, - 103920, - 31139, - 100080, - 47534, - 99165, - 99336, - 3837, - 102067, - 115171, - 3837, - 75108, - 17177, - 102959, - 3837, - 97706, - 36605, - 34187, - 116140, - 118401, - 6313, - 198, - 104020, - 98641, - 17447, - 3837, - 99208, - 101235, - 3837, - 99259, - 9370, - 104468, - 3837, - 59956, - 99208, - 102274, - 112592, - 3837, - 103999, - 9370, - 105476, - 36587, - 53153, - 73145, - 102203, - 3837, - 103999, - 103920, - 99491, - 100545, - 3837, - 100161, - 97706, - 106128, - 99360, - 103031, - 99743, - 89012, - 101432, - 102466, - 34187, - 3837, - 99491, - 104305, - 8997, - 102284, - 99165, - 57566, - 1773, - 99486, - 107693, - 110792, - 100132, - 112857, - 9370, - 3837, - 100473, - 99510, - 97611, - 110792, - 18830, - 99165, - 105806, - 99451, - 101629, - 1773, - 102347, - 99172, - 101041, - 11622, - 99487, - 110792, - 98641, - 100773, - 99278, - 9370, - 496, - 99601, - 99487, - 102481, - 111057, - 99769, - 101952, - 100538, - 99165, - 103336, - 63109, - 1773, - 99451, - 12857, - 99654, - 106016, - 104184, - 110686, - 3837, - 106016, - 102347, - 82700, - 104435, - 86119, - 1773, - 68536, - 108602, - 105078, - 107001, - 101240, - 104655, - 1773, - 101887, - 108232, - 20412, - 99250, - 102078, - 17340, - 101348, - 29767, - 9370, - 3837, - 107020, - 107066, - 102021, - 102481, - 9370, - 3837, - 101132, - 99557, - 108602, - 119059, - 105948, - 1773, - 105984, - 50930, - 62922, - 100623, - 100132, - 100050, - 102307, - 98641, - 9370, - 3837, - 99172, - 36407, - 35946, - 99487, - 100000, - 100050, - 102307, - 98641, - 9370, - 1773, - 100624, - 102945, - 104184, - 104249, - 100363, - 3837, - 107093, - 99486, - 101400, - 101180, - 105729, - 18947, - 117219, - 24442, - 1773, - 107957, - 101165, - 100644, - 26939, - 81668, - 9370, - 100266, - 45629, - 3837, - 104627, - 30709, - 117219, - 108628, - 104169, - 99622, - 101400, - 104059, - 3837, - 101610, - 9370, - 54542, - 75768, - 100672, - 496, - 71134, - 81668, - 496, - 100631, - 101041, - 107961, - 36587, - 100900, - 100310, - 107108, - 100669, - 9370, - 1773, - 107001, - 101240, - 100672, - 53153, - 100292, - 1773, - 102347, - 97706, - 89012, - 52801, - 112285, - 83751, - 34187, - 101610, - 71416, - 1112, - 80158, - 101174, - 106586, - 9370, - 220, - 103934, - 99730, - 99670, - 101161, - 1773, - 43288, - 102405, - 9370, - 107001, - 101240, - 102316, - 35946, - 99744, - 27442, - 55806, - 110735, - 496, - 14880, - 100148, - 104169, - 106202, - 22418, - 63379, - 3837, - 102570, - 1773 - ]; + new[] + { + 109517, 110659, 82700, 3837, 36605, 103947, 61191, 3837, 115171, 3837, 109517, 3837, 102959, 104170, + 3837, 103934, 104342, 103235, 100143, 9370, 198, 99461, 105705, 3837, 100681, 100832, 1773, 106309, + 103946, 3837, 99487, 97480, 99165, 109896, 3837, 108602, 97706, 109349, 34187, 105157, 31548, 33108, + 101489, 44729, 3837, 99165, 111985, 99774, 32571, 102297, 8997, 102214, 108042, 103178, 103178, 9370, + 3837, 117817, 3837, 16530, 119117, 35946, 49567, 34187, 113260, 103924, 3837, 99729, 3837, 103934, + 97706, 115217, 99565, 3837, 35946, 99796, 105275, 63703, 14224, 99828, 17, 15, 15, 106734, 3837, 88051, + 52801, 198, 11622, 99593, 101430, 34187, 3837, 100681, 56006, 105062, 117814, 52801, 11622, 3837, 80942, + 26381, 26288, 3837, 100104, 8863, 42140, 3837, 99541, 78685, 101062, 116006, 3837, 111623, 97706, + 117817, 6313, 198, 99487, 108461, 99285, 3837, 56006, 36589, 27091, 97706, 99285, 3837, 111623, 107816, + 108432, 3837, 101174, 106678, 3837, 42140, 104783, 102947, 105072, 102321, 3837, 97611, 99536, 100553, + 102589, 80158, 99904, 99652, 34187, 198, 101932, 103964, 5122, 52801, 85658, 101062, 5122, 52801, 94305, + 227, 98641, 57218, 105502, 5122, 52801, 220, 44991, 52801, 45943, 198, 115281, 101243, 3837, 35946, + 89012, 114198, 108850, 3837, 102032, 108295, 3837, 107553, 104542, 3837, 78685, 99178, 101243, 3837, + 102032, 99729, 35946, 100545, 8997, 105882, 99165, 99578, 100084, 3837, 75437, 103920, 31139, 100080, + 47534, 99165, 99336, 3837, 102067, 115171, 3837, 75108, 17177, 102959, 3837, 97706, 36605, 34187, + 116140, 118401, 6313, 198, 104020, 98641, 17447, 3837, 99208, 101235, 3837, 99259, 9370, 104468, 3837, + 59956, 99208, 102274, 112592, 3837, 103999, 9370, 105476, 36587, 53153, 73145, 102203, 3837, 103999, + 103920, 99491, 100545, 3837, 100161, 97706, 106128, 99360, 103031, 99743, 89012, 101432, 102466, 34187, + 3837, 99491, 104305, 8997, 102284, 99165, 57566, 1773, 99486, 107693, 110792, 100132, 112857, 9370, + 3837, 100473, 99510, 97611, 110792, 18830, 99165, 105806, 99451, 101629, 1773, 102347, 99172, 101041, + 11622, 99487, 110792, 98641, 100773, 99278, 9370, 496, 99601, 99487, 102481, 111057, 99769, 101952, + 100538, 99165, 103336, 63109, 1773, 99451, 12857, 99654, 106016, 104184, 110686, 3837, 106016, 102347, + 82700, 104435, 86119, 1773, 68536, 108602, 105078, 107001, 101240, 104655, 1773, 101887, 108232, 20412, + 99250, 102078, 17340, 101348, 29767, 9370, 3837, 107020, 107066, 102021, 102481, 9370, 3837, 101132, + 99557, 108602, 119059, 105948, 1773, 105984, 50930, 62922, 100623, 100132, 100050, 102307, 98641, 9370, + 3837, 99172, 36407, 35946, 99487, 100000, 100050, 102307, 98641, 9370, 1773, 100624, 102945, 104184, + 104249, 100363, 3837, 107093, 99486, 101400, 101180, 105729, 18947, 117219, 24442, 1773, 107957, 101165, + 100644, 26939, 81668, 9370, 100266, 45629, 3837, 104627, 30709, 117219, 108628, 104169, 99622, 101400, + 104059, 3837, 101610, 9370, 54542, 75768, 100672, 496, 71134, 81668, 496, 100631, 101041, 107961, 36587, + 100900, 100310, 107108, 100669, 9370, 1773, 107001, 101240, 100672, 53153, 100292, 1773, 102347, 97706, + 89012, 52801, 112285, 83751, 34187, 101610, 71416, 1112, 80158, 101174, 106586, 9370, 220, 103934, + 99730, 99670, 101161, 1773, 43288, 102405, 9370, 107001, 101240, 102316, 35946, 99744, 27442, 55806, + 110735, 496, 14880, 100148, 104169, 106202, 22418, 63379, 3837, 102570, 1773 + }; [Fact] public void QWenTokenizer_Encode_SuccessAsync() @@ -486,7 +52,7 @@ public void QWenTokenizer_Encode_SuccessAsync() var embeddings = QWenTokenizer.Encode(Text); // Assert - embeddings.Should().BeEquivalentTo(Tokens); + Assert.Equivalent(Tokens, embeddings); } [Fact] @@ -496,27 +62,16 @@ public void QWenTokenizer_Decode_SuccessAsync() var text = QWenTokenizer.Decode(Tokens); // Assert - text.Should().BeEquivalentTo(Text); + Assert.Equal(Text, text); } [Fact] public void QWenTokenizer_EncodeToStrings_SuccessAsync() { // Act - var tokens = QWenTokenizer.Tokenizer.EncodeToTokens(Text, out _); + var tokens = QWenTokenizer.Tokenizer.Encode(Text); // Assert - tokens.Select(t => t.Id).Should().BeEquivalentTo(Tokens); - } - - [Fact] - public void QWenTokenizer_CountIndex_SuccessAsync() - { - // Act - var maxIndex = QWenTokenizer.GetIndexByTokenCount(Text, 100, out _, out var tokenCount); - - // Assert - maxIndex.Should().Be(155); - tokenCount.Should().BeLessThanOrEqualTo(100); + Assert.Equivalent(Tokens, tokens); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.response.body.txt deleted file mode 100644 index 75aba2c..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.response.body.txt +++ /dev/null @@ -1 +0,0 @@ -{"request_id":"8b22164d-c784-9a31-bda3-3c26259d4213","output":{"task_id":"b2e98d78-c79b-431c-b2d7-c7bcd54465da","task_status":"SUCCEEDED","submit_time":"2024-03-04 10:08:57.333","scheduled_time":"2024-03-04 10:08:57.363","end_time":"2024-03-04 10:09:07.727","text_results":{"urls":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_0_4645005c-713d-4e92-9629-b12cbe5f3671.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=kmZGXc2s8P4uI%2BVrADITyrPz82U%3D"},{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_1_b1979b75-c553-4d9b-9c9f-80f401a0d124.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=cb1Qg%2FkIuZyI7XQqWHjP712N0ak%3D"}],"params":[{"sample_idx":0,"layers":[{"color":"#521b08","top":0,"left":0,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#521b0800"},{"offset":1,"color":"#521b08ff"}],"gradient_units":"pixels","coords":{"y1":257,"x1":0,"y2":0,"x2":0}},"width":1024,"type":"text_mask","idx":0,"opacity":0.8,"radius":0,"height":257},{"font_weight":"Regular","font_size":67,"type":"text","content":"分享好时光","font_under_line":false,"line_height":1,"font_italic":false,"top":25,"sub_type":"Title","font_color":"#e6baa7","left":319,"text_stroke":"1px #fffffff0","width":385,"text_shadow":"1px 0px #80808080","font_family":"站酷文艺体","idx":1,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":77},{"color":"#e6baa7","top":118,"left":395,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#e6baa7ff"},{"offset":1,"color":"#e6baa7ff"}],"gradient_units":"pixels","coords":{"y1":0,"x1":0,"y2":50,"x2":0}},"width":233,"type":"text_mask","idx":2,"opacity":1,"radius":37,"box_shadow":"2px 1px #80808080","height":50},{"font_weight":"Medium","font_size":27,"type":"text","content":"只为不一样的你","font_under_line":false,"line_height":1,"font_italic":false,"top":118,"sub_type":"SubTitle","font_color":"#223629","left":395,"width":233,"text_shadow":0,"font_family":"阿里巴巴普惠体","idx":3,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":50}]},{"sample_idx":1,"layers":[{"color":"#efeae4","top":0,"left":0,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#efeae400"},{"offset":1,"color":"#efeae4ff"}],"gradient_units":"pixels","coords":{"y1":257,"x1":0,"y2":0,"x2":0}},"width":1024,"type":"text_mask","idx":0,"opacity":0.8,"radius":0,"height":257},{"font_weight":"Regular","font_size":67,"type":"text","content":"分享好时光","font_under_line":false,"line_height":1,"font_italic":false,"top":25,"sub_type":"Title","font_color":"#421f12","left":319,"text_stroke":"1px #fffffff0","width":385,"text_shadow":"0px 2px #80808080","font_family":"钉钉进步体","idx":1,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":77},{"color":"#421f12","top":118,"left":395,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#421f12ff"},{"offset":1,"color":"#421f12ff"}],"gradient_units":"pixels","coords":{"y1":0,"x1":0,"y2":50,"x2":0}},"width":233,"type":"text_mask","idx":2,"opacity":1,"radius":37,"box_shadow":"0px 0px #80808080","height":50},{"font_weight":"Regular","font_size":27,"type":"text","content":"只为不一样的你","font_under_line":false,"line_height":1,"font_italic":false,"top":118,"sub_type":"SubTitle","font_color":"#f1eeec","left":395,"width":233,"text_shadow":0,"font_family":"阿里巴巴普惠体","idx":3,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":50}]}]},"results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_0_02dc0bba-8b1d-4648-8b95-eb2b92fe715d.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=OYstgSxWOl%2FOxYTLa2Mx3bi2RWw%3D"},{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_1_e1af86ec-152a-4ebe-b2a0-b40a592043b2.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=p0UXTUdXfp0tFlt0K5tDsA%2Fxl1M%3D"}],"task_metrics":{"TOTAL":2,"SUCCEEDED":2,"FAILED":0}},"usage":{"image_count":2}} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt deleted file mode 100644 index 43c0bb2..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt +++ /dev/null @@ -1 +0,0 @@ -{"request_id":"6662e925-4846-9afe-a3af-0d131805d378","output":{"task_id":"9e2b6ef6-285d-4efa-8651-4dbda7d571fa","task_status":"SUCCEEDED","submit_time":"2024-03-01 17:38:24.817","scheduled_time":"2024-03-01 17:38:24.831","end_time":"2024-03-01 17:38:55.565","results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/d4/20240301/8d820c8d/4c48fa53-2907-499b-b9ac-76477fe8d299-1.png?Expires=1709372333&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=bEfLmd%2BarXgZyhxcVYOWs%2BovJb8%3D"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/79/20240301/3ab595ad/aa3e6d8d-884d-4431-b9c2-3684edeb072e-1.png?Expires=1709372333&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=fdPScmRkIXyH3TSaSaWwvVjxREQ%3D"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/0f/20240301/3ab595ad/ecfe06b3-b91c-4950-a932-49ea1619a1f9-1.png?Expires=1709372333&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=gNuVAt8iy4X8Nl2l3K4Gu4f0ydw%3D"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/3d/20240301/3ab595ad/3fca748e-d491-458a-bb72-73649af33209-1.png?Expires=1709372333&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=Mx5TueC9I9yfDno9rjzi48opHtM%3D"}],"task_metrics":{"TOTAL":4,"SUCCEEDED":4,"FAILED":0}},"usage":{"image_count":4}} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.body.txt b/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.body.txt deleted file mode 100644 index 40e024f..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.body.txt +++ /dev/null @@ -1,1975 +0,0 @@ -id:1 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"嗯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"input_tokens":11,"output_tokens":3},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:2 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"input_tokens":11,"output_tokens":4},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:3 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":16,"input_tokens":11,"output_tokens":5},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:4 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":17,"input_tokens":11,"output_tokens":6},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:5 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":18,"input_tokens":11,"output_tokens":7},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:6 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"加","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":19,"input_tokens":11,"output_tokens":8},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:7 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":20,"input_tokens":11,"output_tokens":9},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:8 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"等于","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":21,"input_tokens":11,"output_tokens":10},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:9 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"多少","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":22,"input_tokens":11,"output_tokens":11},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:10 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":23,"input_tokens":11,"output_tokens":12},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:11 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"这个问题","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":24,"input_tokens":11,"output_tokens":13},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:12 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"看起来","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":25,"input_tokens":11,"output_tokens":14},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:13 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"很简单","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":26,"input_tokens":11,"output_tokens":15},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:14 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":27,"input_tokens":11,"output_tokens":16},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:15 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"但其实","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":28,"input_tokens":11,"output_tokens":17},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:16 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":29,"input_tokens":11,"output_tokens":18},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:17 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"有很多","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":30,"input_tokens":11,"output_tokens":19},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:18 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"种","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":31,"input_tokens":11,"output_tokens":20},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:19 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"情况","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":32,"input_tokens":11,"output_tokens":21},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:20 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"需要考虑","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":33,"input_tokens":11,"output_tokens":22},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:21 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":34,"input_tokens":11,"output_tokens":23},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:22 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"首先","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":35,"input_tokens":11,"output_tokens":24},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:23 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":36,"input_tokens":11,"output_tokens":25},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:24 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"我得","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":37,"input_tokens":11,"output_tokens":26},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:25 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"确定","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":38,"input_tokens":11,"output_tokens":27},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:26 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":39,"input_tokens":11,"output_tokens":28},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:27 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"是不是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":40,"input_tokens":11,"output_tokens":29},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:28 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":41,"input_tokens":11,"output_tokens":30},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:29 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":42,"input_tokens":11,"output_tokens":31},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:30 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"数学","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":43,"input_tokens":11,"output_tokens":32},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:31 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"上的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":44,"input_tokens":11,"output_tokens":33},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:32 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"基本","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":45,"input_tokens":11,"output_tokens":34},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:33 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"加法","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":46,"input_tokens":11,"output_tokens":35},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:34 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":47,"input_tokens":11,"output_tokens":36},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:35 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"通常","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":48,"input_tokens":11,"output_tokens":37},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:36 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"来说","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":49,"input_tokens":11,"output_tokens":38},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:37 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":50,"input_tokens":11,"output_tokens":39},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:38 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":51,"input_tokens":11,"output_tokens":40},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:39 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"加","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":52,"input_tokens":11,"output_tokens":41},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:40 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":53,"input_tokens":11,"output_tokens":42},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:41 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"等于","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":54,"input_tokens":11,"output_tokens":43},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:42 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":55,"input_tokens":11,"output_tokens":44},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:43 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":56,"input_tokens":11,"output_tokens":45},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:44 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"这是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":57,"input_tokens":11,"output_tokens":46},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:45 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"数学","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":58,"input_tokens":11,"output_tokens":47},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:46 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"里的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":59,"input_tokens":11,"output_tokens":48},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:47 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"基本","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":60,"input_tokens":11,"output_tokens":49},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:48 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"事实","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":61,"input_tokens":11,"output_tokens":50},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:49 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":62,"input_tokens":11,"output_tokens":51},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:50 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"根据","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":63,"input_tokens":11,"output_tokens":52},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:51 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"皮","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":64,"input_tokens":11,"output_tokens":53},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:52 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"亚","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":65,"input_tokens":11,"output_tokens":54},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:53 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"诺","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":66,"input_tokens":11,"output_tokens":55},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:54 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"公","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":67,"input_tokens":11,"output_tokens":56},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:55 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"理","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":68,"input_tokens":11,"output_tokens":57},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:56 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或者","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":69,"input_tokens":11,"output_tokens":58},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:57 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"基本的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":70,"input_tokens":11,"output_tokens":59},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:58 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"算术","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":71,"input_tokens":11,"output_tokens":60},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:59 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"规则","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":72,"input_tokens":11,"output_tokens":61},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:60 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":73,"input_tokens":11,"output_tokens":62},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:61 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不过","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":74,"input_tokens":11,"output_tokens":63},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:62 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":75,"input_tokens":11,"output_tokens":64},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:63 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"有时候","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":76,"input_tokens":11,"output_tokens":65},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:64 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问题","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":77,"input_tokens":11,"output_tokens":66},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:65 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能有","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":78,"input_tokens":11,"output_tokens":67},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:66 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"隐藏","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":79,"input_tokens":11,"output_tokens":68},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:67 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的含义","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":80,"input_tokens":11,"output_tokens":69},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:68 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":81,"input_tokens":11,"output_tokens":70},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:69 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"特别是在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":82,"input_tokens":11,"output_tokens":71},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:70 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不同的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":83,"input_tokens":11,"output_tokens":72},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:71 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"语境","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":84,"input_tokens":11,"output_tokens":73},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:72 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"下","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":85,"input_tokens":11,"output_tokens":74},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:73 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":86,"input_tokens":11,"output_tokens":75},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:74 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":87,"input_tokens":11,"output_tokens":76},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:75 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能会","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":88,"input_tokens":11,"output_tokens":77},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:76 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不同","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":89,"input_tokens":11,"output_tokens":78},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:77 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":90,"input_tokens":11,"output_tokens":79},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:78 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"比如","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":91,"input_tokens":11,"output_tokens":80},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:79 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":92,"input_tokens":11,"output_tokens":81},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:80 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"二进制","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":93,"input_tokens":11,"output_tokens":82},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:81 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"中","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":94,"input_tokens":11,"output_tokens":83},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:82 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":95,"input_tokens":11,"output_tokens":84},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:83 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":96,"input_tokens":11,"output_tokens":85},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:84 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"+","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":97,"input_tokens":11,"output_tokens":86},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:85 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":98,"input_tokens":11,"output_tokens":87},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:86 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"等于","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":99,"input_tokens":11,"output_tokens":88},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:87 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"10","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":100,"input_tokens":11,"output_tokens":89},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:88 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":101,"input_tokens":11,"output_tokens":90},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:89 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或者在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":102,"input_tokens":11,"output_tokens":91},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:90 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"布尔","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":103,"input_tokens":11,"output_tokens":92},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:91 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"代数","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":104,"input_tokens":11,"output_tokens":93},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:92 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"中","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":105,"input_tokens":11,"output_tokens":94},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:93 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":106,"input_tokens":11,"output_tokens":95},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:94 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":107,"input_tokens":11,"output_tokens":96},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:95 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"+","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":108,"input_tokens":11,"output_tokens":97},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:96 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":109,"input_tokens":11,"output_tokens":98},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:97 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":110,"input_tokens":11,"output_tokens":99},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:98 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"等于","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":111,"input_tokens":11,"output_tokens":100},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:99 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":112,"input_tokens":11,"output_tokens":101},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:100 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":113,"input_tokens":11,"output_tokens":102},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:101 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"如果是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":114,"input_tokens":11,"output_tokens":103},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:102 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"逻辑","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":115,"input_tokens":11,"output_tokens":104},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:103 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":116,"input_tokens":11,"output_tokens":105},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:104 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"运算","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":117,"input_tokens":11,"output_tokens":106},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:105 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的话","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":118,"input_tokens":11,"output_tokens":107},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:106 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":119,"input_tokens":11,"output_tokens":108},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:107 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不过","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":120,"input_tokens":11,"output_tokens":109},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:108 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"大部分","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":121,"input_tokens":11,"output_tokens":110},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:109 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"情况下","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":122,"input_tokens":11,"output_tokens":111},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:110 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":123,"input_tokens":11,"output_tokens":112},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:111 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"尤其是在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":124,"input_tokens":11,"output_tokens":113},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:112 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"日常","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":125,"input_tokens":11,"output_tokens":114},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:113 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"交流","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":126,"input_tokens":11,"output_tokens":115},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:114 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"中","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":127,"input_tokens":11,"output_tokens":116},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:115 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":128,"input_tokens":11,"output_tokens":117},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:116 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"人们","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":129,"input_tokens":11,"output_tokens":118},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:117 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"提到","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":130,"input_tokens":11,"output_tokens":119},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:118 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":131,"input_tokens":11,"output_tokens":120},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:119 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"+","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":132,"input_tokens":11,"output_tokens":121},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:120 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":133,"input_tokens":11,"output_tokens":122},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:121 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的时候","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":134,"input_tokens":11,"output_tokens":123},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:122 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"都是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":135,"input_tokens":11,"output_tokens":124},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:123 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"指","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":136,"input_tokens":11,"output_tokens":125},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:124 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"十进制","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":137,"input_tokens":11,"output_tokens":126},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:125 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"加法","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":138,"input_tokens":11,"output_tokens":127},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:126 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":139,"input_tokens":11,"output_tokens":128},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:127 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"结果","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":140,"input_tokens":11,"output_tokens":129},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:128 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"自然是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":141,"input_tokens":11,"output_tokens":130},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:129 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":142,"input_tokens":11,"output_tokens":131},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:130 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":143,"input_tokens":11,"output_tokens":132},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:131 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不过","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":144,"input_tokens":11,"output_tokens":133},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:132 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"也有可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":145,"input_tokens":11,"output_tokens":134},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:133 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":146,"input_tokens":11,"output_tokens":135},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:134 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"是在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":147,"input_tokens":11,"output_tokens":136},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:135 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"测试","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":148,"input_tokens":11,"output_tokens":137},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:136 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"我的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":149,"input_tokens":11,"output_tokens":138},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:137 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"反应","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":150,"input_tokens":11,"output_tokens":139},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:138 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":151,"input_tokens":11,"output_tokens":140},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:139 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或者","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":152,"input_tokens":11,"output_tokens":141},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:140 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"想","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":153,"input_tokens":11,"output_tokens":142},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:141 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"看看","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":154,"input_tokens":11,"output_tokens":143},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:142 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"我会","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":155,"input_tokens":11,"output_tokens":144},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:143 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不会","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":156,"input_tokens":11,"output_tokens":145},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:144 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"考虑","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":157,"input_tokens":11,"output_tokens":146},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:145 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"其他","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":158,"input_tokens":11,"output_tokens":147},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:146 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能性","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":159,"input_tokens":11,"output_tokens":148},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:147 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":160,"input_tokens":11,"output_tokens":149},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:148 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"比如","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":161,"input_tokens":11,"output_tokens":150},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:149 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":162,"input_tokens":11,"output_tokens":151},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:150 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"特定的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":163,"input_tokens":11,"output_tokens":152},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:151 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"谜","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":164,"input_tokens":11,"output_tokens":153},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:152 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"语","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":165,"input_tokens":11,"output_tokens":154},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:153 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":166,"input_tokens":11,"output_tokens":155},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:154 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"笑话","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":167,"input_tokens":11,"output_tokens":156},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:155 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"中","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":168,"input_tokens":11,"output_tokens":157},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:156 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":169,"input_tokens":11,"output_tokens":158},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:157 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":170,"input_tokens":11,"output_tokens":159},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:158 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":171,"input_tokens":11,"output_tokens":160},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:159 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":172,"input_tokens":11,"output_tokens":161},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:160 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":173,"input_tokens":11,"output_tokens":162},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:161 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":174,"input_tokens":11,"output_tokens":163},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:162 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"比如","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":175,"input_tokens":11,"output_tokens":164},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:163 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"“","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":176,"input_tokens":11,"output_tokens":165},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:164 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":177,"input_tokens":11,"output_tokens":166},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:165 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"滴水","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":178,"input_tokens":11,"output_tokens":167},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:166 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"加","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":179,"input_tokens":11,"output_tokens":168},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:167 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":180,"input_tokens":11,"output_tokens":169},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:168 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"滴水","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":181,"input_tokens":11,"output_tokens":170},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:169 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"还是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":182,"input_tokens":11,"output_tokens":171},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:170 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":183,"input_tokens":11,"output_tokens":172},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:171 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"滴水","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":184,"input_tokens":11,"output_tokens":173},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:172 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"”,","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":185,"input_tokens":11,"output_tokens":174},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:173 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或者","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":186,"input_tokens":11,"output_tokens":175},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:174 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"类似的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":187,"input_tokens":11,"output_tokens":176},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:175 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"文字","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":188,"input_tokens":11,"output_tokens":177},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:176 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"游戏","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":189,"input_tokens":11,"output_tokens":178},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:177 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":190,"input_tokens":11,"output_tokens":179},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:178 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"但","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":191,"input_tokens":11,"output_tokens":180},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:179 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"根据","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":192,"input_tokens":11,"output_tokens":181},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:180 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"常规","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":193,"input_tokens":11,"output_tokens":182},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:181 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问题","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":194,"input_tokens":11,"output_tokens":183},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:182 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":195,"input_tokens":11,"output_tokens":184},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:183 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"我应该","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":196,"input_tokens":11,"output_tokens":185},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:184 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"先","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":197,"input_tokens":11,"output_tokens":186},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:185 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"给出","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":198,"input_tokens":11,"output_tokens":187},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:186 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"正确的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":199,"input_tokens":11,"output_tokens":188},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:187 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"数学","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":200,"input_tokens":11,"output_tokens":189},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:188 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":201,"input_tokens":11,"output_tokens":190},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:189 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":202,"input_tokens":11,"output_tokens":191},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:190 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"再","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":203,"input_tokens":11,"output_tokens":192},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:191 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"补充","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":204,"input_tokens":11,"output_tokens":193},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:192 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":205,"input_tokens":11,"output_tokens":194},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:193 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"其他","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":206,"input_tokens":11,"output_tokens":195},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:194 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"情况","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":207,"input_tokens":11,"output_tokens":196},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:195 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":208,"input_tokens":11,"output_tokens":197},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:196 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"这样","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":209,"input_tokens":11,"output_tokens":198},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:197 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"既","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":210,"input_tokens":11,"output_tokens":199},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:198 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"准确","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":211,"input_tokens":11,"output_tokens":200},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:199 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"又","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":212,"input_tokens":11,"output_tokens":201},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:200 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"全面","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":213,"input_tokens":11,"output_tokens":202},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:201 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":214,"input_tokens":11,"output_tokens":203},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:202 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"所以","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":215,"input_tokens":11,"output_tokens":204},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:203 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":216,"input_tokens":11,"output_tokens":205},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:204 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"先","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":217,"input_tokens":11,"output_tokens":206},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:205 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"回答","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":218,"input_tokens":11,"output_tokens":207},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:206 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":219,"input_tokens":11,"output_tokens":208},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:207 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":220,"input_tokens":11,"output_tokens":209},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:208 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"然后","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":221,"input_tokens":11,"output_tokens":210},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:209 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"解释","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":222,"input_tokens":11,"output_tokens":211},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:210 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"其他","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":223,"input_tokens":11,"output_tokens":212},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:211 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能性","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":224,"input_tokens":11,"output_tokens":213},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:212 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":225,"input_tokens":11,"output_tokens":214},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:213 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不过","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":226,"input_tokens":11,"output_tokens":215},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:214 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":227,"input_tokens":11,"output_tokens":216},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:215 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的问题","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":228,"input_tokens":11,"output_tokens":217},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:216 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"看起来","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":229,"input_tokens":11,"output_tokens":218},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:217 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"直接","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":230,"input_tokens":11,"output_tokens":219},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:218 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":231,"input_tokens":11,"output_tokens":220},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:219 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":232,"input_tokens":11,"output_tokens":221},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:220 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"不需要","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":233,"input_tokens":11,"output_tokens":222},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:221 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"太","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":234,"input_tokens":11,"output_tokens":223},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:222 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"复杂的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":235,"input_tokens":11,"output_tokens":224},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:223 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"解释","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":236,"input_tokens":11,"output_tokens":225},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:224 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":237,"input_tokens":11,"output_tokens":226},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:225 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"但","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":238,"input_tokens":11,"output_tokens":227},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:226 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"为了","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":239,"input_tokens":11,"output_tokens":228},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:227 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"保险","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":240,"input_tokens":11,"output_tokens":229},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:228 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"起见","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":241,"input_tokens":11,"output_tokens":230},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:229 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":242,"input_tokens":11,"output_tokens":231},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:230 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"还是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":243,"input_tokens":11,"output_tokens":232},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:231 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"确认","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":244,"input_tokens":11,"output_tokens":233},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:232 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"一下","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":245,"input_tokens":11,"output_tokens":234},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:233 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"是否有","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":246,"input_tokens":11,"output_tokens":235},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:234 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"其他","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":247,"input_tokens":11,"output_tokens":236},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:235 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"意图","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":248,"input_tokens":11,"output_tokens":237},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:236 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"比较好","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":249,"input_tokens":11,"output_tokens":238},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:237 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":250,"input_tokens":11,"output_tokens":239},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:238 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"或者","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":251,"input_tokens":11,"output_tokens":240},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:239 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":252,"input_tokens":11,"output_tokens":241},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:240 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":253,"input_tokens":11,"output_tokens":242},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:241 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"只是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":254,"input_tokens":11,"output_tokens":243},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:242 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"单纯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":255,"input_tokens":11,"output_tokens":244},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:243 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"想知道","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":256,"input_tokens":11,"output_tokens":245},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:244 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":257,"input_tokens":11,"output_tokens":246},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:245 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":258,"input_tokens":11,"output_tokens":247},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:246 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"所以","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":259,"input_tokens":11,"output_tokens":248},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:247 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"直接","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":260,"input_tokens":11,"output_tokens":249},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:248 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"回答","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":261,"input_tokens":11,"output_tokens":250},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:249 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":262,"input_tokens":11,"output_tokens":251},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:250 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"即可","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":263,"input_tokens":11,"output_tokens":252},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:251 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":264,"input_tokens":11,"output_tokens":253},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:252 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"需要","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":265,"input_tokens":11,"output_tokens":254},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:253 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"平衡","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":266,"input_tokens":11,"output_tokens":255},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:254 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"简洁","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":267,"input_tokens":11,"output_tokens":256},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:255 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"和","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":268,"input_tokens":11,"output_tokens":257},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:256 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"全面","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":269,"input_tokens":11,"output_tokens":258},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:257 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"性","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":270,"input_tokens":11,"output_tokens":259},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:258 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":271,"input_tokens":11,"output_tokens":260},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:259 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"可能","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":272,"input_tokens":11,"output_tokens":261},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:260 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"先","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":273,"input_tokens":11,"output_tokens":262},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:261 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"给出","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":274,"input_tokens":11,"output_tokens":263},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:262 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"直接","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":275,"input_tokens":11,"output_tokens":264},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:263 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":276,"input_tokens":11,"output_tokens":265},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:264 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":277,"input_tokens":11,"output_tokens":266},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:265 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"然后","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":278,"input_tokens":11,"output_tokens":267},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:266 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"简单","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":279,"input_tokens":11,"output_tokens":268},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:267 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"说明","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":280,"input_tokens":11,"output_tokens":269},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:268 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"其他","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":281,"input_tokens":11,"output_tokens":270},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:269 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"情况","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":282,"input_tokens":11,"output_tokens":271},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:270 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的存在","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":283,"input_tokens":11,"output_tokens":272},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:271 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":284,"input_tokens":11,"output_tokens":273},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:272 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"这样","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":285,"input_tokens":11,"output_tokens":274},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:273 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"既","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":286,"input_tokens":11,"output_tokens":275},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:274 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"满足","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":287,"input_tokens":11,"output_tokens":276},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:275 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"需求","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":288,"input_tokens":11,"output_tokens":277},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:276 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":289,"input_tokens":11,"output_tokens":278},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:277 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"又","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":290,"input_tokens":11,"output_tokens":279},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:278 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"避免","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":291,"input_tokens":11,"output_tokens":280},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:279 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"信息","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":292,"input_tokens":11,"output_tokens":281},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:280 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"过","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":293,"input_tokens":11,"output_tokens":282},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:281 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"载","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":294,"input_tokens":11,"output_tokens":283},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:282 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":295,"input_tokens":11,"output_tokens":284},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:283 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"总之","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":296,"input_tokens":11,"output_tokens":285},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:284 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":297,"input_tokens":11,"output_tokens":286},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:285 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"核心","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":298,"input_tokens":11,"output_tokens":287},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:286 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"答案","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":299,"input_tokens":11,"output_tokens":288},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:287 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"应该是","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":300,"input_tokens":11,"output_tokens":289},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:288 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"2","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":301,"input_tokens":11,"output_tokens":290},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:289 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":302,"input_tokens":11,"output_tokens":291},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:290 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"但","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":303,"input_tokens":11,"output_tokens":292},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:291 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"根据","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":304,"input_tokens":11,"output_tokens":293},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:292 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"情况","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":305,"input_tokens":11,"output_tokens":294},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:293 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"适当","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":306,"input_tokens":11,"output_tokens":295},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:294 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"扩展","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":307,"input_tokens":11,"output_tokens":296},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:295 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":308,"input_tokens":11,"output_tokens":297},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:296 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":311,"input_tokens":11,"output_tokens":300},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:297 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"+","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":312,"input_tokens":11,"output_tokens":301},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:298 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":313,"input_tokens":11,"output_tokens":302},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:299 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 在","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":315,"input_tokens":11,"output_tokens":304},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:300 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"基础","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":316,"input_tokens":11,"output_tokens":305},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:301 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"算术","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":317,"input_tokens":11,"output_tokens":306},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:302 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"中的","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":318,"input_tokens":11,"output_tokens":307},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:303 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"答案是","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":319,"input_tokens":11,"output_tokens":308},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:304 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":320,"input_tokens":11,"output_tokens":309},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:305 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"2","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":321,"input_tokens":11,"output_tokens":310},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:306 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"**","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":322,"input_tokens":11,"output_tokens":311},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:307 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":323,"input_tokens":11,"output_tokens":312},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:308 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"\n\n不过","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":325,"input_tokens":11,"output_tokens":314},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:309 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":326,"input_tokens":11,"output_tokens":315},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:310 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"根据","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":327,"input_tokens":11,"output_tokens":316},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:311 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"不同的","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":328,"input_tokens":11,"output_tokens":317},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:312 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"数学","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":329,"input_tokens":11,"output_tokens":318},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:313 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"或","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":330,"input_tokens":11,"output_tokens":319},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:314 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"逻辑","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":331,"input_tokens":11,"output_tokens":320},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:315 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"系统","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":332,"input_tokens":11,"output_tokens":321},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:316 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":333,"input_tokens":11,"output_tokens":322},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:317 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"结果","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":334,"input_tokens":11,"output_tokens":323},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:318 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"可能","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":335,"input_tokens":11,"output_tokens":324},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:319 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"不同","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":336,"input_tokens":11,"output_tokens":325},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:320 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":":","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":337,"input_tokens":11,"output_tokens":326},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:321 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"\n-","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":338,"input_tokens":11,"output_tokens":327},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:322 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":339,"input_tokens":11,"output_tokens":328},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:323 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"二进制","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":340,"input_tokens":11,"output_tokens":329},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:324 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"**","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":341,"input_tokens":11,"output_tokens":330},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:325 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":":","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":342,"input_tokens":11,"output_tokens":331},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:326 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":343,"input_tokens":11,"output_tokens":332},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:327 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"+","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":344,"input_tokens":11,"output_tokens":333},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:328 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":345,"input_tokens":11,"output_tokens":334},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:329 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" =","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":346,"input_tokens":11,"output_tokens":335},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:330 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 10","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":348,"input_tokens":11,"output_tokens":337},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:331 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"(","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":349,"input_tokens":11,"output_tokens":338},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:332 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"读","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":350,"input_tokens":11,"output_tokens":339},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:333 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"作","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":351,"input_tokens":11,"output_tokens":340},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:334 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"“","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":352,"input_tokens":11,"output_tokens":341},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:335 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"一","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":353,"input_tokens":11,"output_tokens":342},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:336 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"零","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":354,"input_tokens":11,"output_tokens":343},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:337 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"”","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":355,"input_tokens":11,"output_tokens":344},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:338 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":")。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":356,"input_tokens":11,"output_tokens":345},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:339 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"\n-","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":357,"input_tokens":11,"output_tokens":346},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:340 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":358,"input_tokens":11,"output_tokens":347},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:341 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"布尔","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":359,"input_tokens":11,"output_tokens":348},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:342 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"代数","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":360,"input_tokens":11,"output_tokens":349},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:343 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"**","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":361,"input_tokens":11,"output_tokens":350},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:344 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":":","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":362,"input_tokens":11,"output_tokens":351},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:345 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":363,"input_tokens":11,"output_tokens":352},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:346 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"+","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":364,"input_tokens":11,"output_tokens":353},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:347 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":365,"input_tokens":11,"output_tokens":354},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:348 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" =","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":366,"input_tokens":11,"output_tokens":355},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:349 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":368,"input_tokens":11,"output_tokens":357},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:350 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"(","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":369,"input_tokens":11,"output_tokens":358},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:351 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"逻辑","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":370,"input_tokens":11,"output_tokens":359},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:352 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"“","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":371,"input_tokens":11,"output_tokens":360},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:353 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"或","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":372,"input_tokens":11,"output_tokens":361},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:354 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"”","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":373,"input_tokens":11,"output_tokens":362},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:355 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"运算","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":374,"input_tokens":11,"output_tokens":363},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:356 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":")。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":375,"input_tokens":11,"output_tokens":364},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:357 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"\n-","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":376,"input_tokens":11,"output_tokens":365},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:358 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":377,"input_tokens":11,"output_tokens":366},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:359 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"抽象","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:360 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"场景","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":379,"input_tokens":11,"output_tokens":368},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:361 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"**","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":380,"input_tokens":11,"output_tokens":369},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:362 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":":","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":381,"input_tokens":11,"output_tokens":370},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:363 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"如","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":382,"input_tokens":11,"output_tokens":371},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:364 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"“","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":383,"input_tokens":11,"output_tokens":372},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:365 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":384,"input_tokens":11,"output_tokens":373},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:366 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"滴水","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":385,"input_tokens":11,"output_tokens":374},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:367 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" +","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":386,"input_tokens":11,"output_tokens":375},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:368 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":388,"input_tokens":11,"output_tokens":377},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:369 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"滴水","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":389,"input_tokens":11,"output_tokens":378},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:370 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" =","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":390,"input_tokens":11,"output_tokens":379},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:371 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":392,"input_tokens":11,"output_tokens":381},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:372 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"大","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":393,"input_tokens":11,"output_tokens":382},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:373 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"滴水","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":394,"input_tokens":11,"output_tokens":383},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:374 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"”(","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":395,"input_tokens":11,"output_tokens":384},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:375 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"非","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":396,"input_tokens":11,"output_tokens":385},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:376 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"数学","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":397,"input_tokens":11,"output_tokens":386},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:377 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"意义的","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":398,"input_tokens":11,"output_tokens":387},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:378 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"合并","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":399,"input_tokens":11,"output_tokens":388},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:379 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":")。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":400,"input_tokens":11,"output_tokens":389},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:380 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"\n\n日常","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":401,"input_tokens":11,"output_tokens":390},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:381 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"问题","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":402,"input_tokens":11,"output_tokens":391},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:382 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"中","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":403,"input_tokens":11,"output_tokens":392},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:383 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"默认","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":404,"input_tokens":11,"output_tokens":393},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:384 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"使用","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":405,"input_tokens":11,"output_tokens":394},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:385 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"十进制","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":406,"input_tokens":11,"output_tokens":395},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:386 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"算术","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":407,"input_tokens":11,"output_tokens":396},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:387 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":408,"input_tokens":11,"output_tokens":397},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:388 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"因此","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":409,"input_tokens":11,"output_tokens":398},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:389 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"答案是","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":410,"input_tokens":11,"output_tokens":399},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:390 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":411,"input_tokens":11,"output_tokens":400},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:391 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"2","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":412,"input_tokens":11,"output_tokens":401},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:392 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"**","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":413,"input_tokens":11,"output_tokens":402},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:393 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":" 😊","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":416,"input_tokens":11,"output_tokens":405},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:394 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":417,"input_tokens":11,"output_tokens":406},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - -id:395 -event:result -:HTTP_STATUS/200 -data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":417,"input_tokens":11,"output_tokens":406},"request_id":"e4ad5d0f-8019-9716-adc6-eae1411d3c9a"} - diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ServiceCollectionInjectorTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ServiceCollectionInjectorTests.cs index 02230cc..54d6870 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ServiceCollectionInjectorTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ServiceCollectionInjectorTests.cs @@ -1,6 +1,6 @@ using System.Net.Http.Headers; +using Cnblogs.DashScope.AspNetCore; using Cnblogs.DashScope.Core; -using FluentAssertions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -20,14 +20,17 @@ public void Parameter_Normal_Inject() // Act services.AddDashScopeClient(ApiKey); var provider = services.BuildServiceProvider(); - var httpClient = provider.GetRequiredService().CreateClient(nameof(IDashScopeClient)); + var httpClient = provider.GetRequiredService() + .CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName); + var client = provider.GetRequiredService(); // Assert - provider.GetRequiredService().Should().NotBeNull().And - .BeOfType(); - httpClient.Should().NotBeNull(); - httpClient.DefaultRequestHeaders.Authorization.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", ApiKey)); + Assert.NotNull(client); + Assert.IsType(client); + Assert.NotNull(httpClient); + Assert.Equivalent( + new AuthenticationHeaderValue("Bearer", ApiKey), + httpClient.DefaultRequestHeaders.Authorization); } [Fact] @@ -37,17 +40,20 @@ public void Parameter_HasProxy_Inject() var services = new ServiceCollection(); // Act - services.AddDashScopeClient(ApiKey, ProxyApi); + services.AddDashScopeClient(ApiKey, baseAddress: ProxyApi); var provider = services.BuildServiceProvider(); - var httpClient = provider.GetRequiredService().CreateClient(nameof(IDashScopeClient)); + var httpClient = provider.GetRequiredService() + .CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName); + var client = provider.GetRequiredService(); // Assert - provider.GetRequiredService().Should().NotBeNull().And - .BeOfType(); - httpClient.Should().NotBeNull(); - httpClient.DefaultRequestHeaders.Authorization.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", ApiKey)); - httpClient.BaseAddress.Should().BeEquivalentTo(new Uri(ProxyApi)); + Assert.NotNull(client); + Assert.IsType(client); + Assert.NotNull(httpClient); + Assert.Equivalent( + new AuthenticationHeaderValue("Bearer", ApiKey), + httpClient.DefaultRequestHeaders.Authorization); + Assert.Equivalent(new Uri(ProxyApi), httpClient.BaseAddress); } [Fact] @@ -66,15 +72,18 @@ public void Configuration_Normal_Inject() // Act services.AddDashScopeClient(configuration); var provider = services.BuildServiceProvider(); - var httpClient = provider.GetRequiredService().CreateClient(nameof(IDashScopeClient)); + var httpClient = provider.GetRequiredService() + .CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName); + var client = provider.GetRequiredService(); // Assert - provider.GetRequiredService().Should().NotBeNull().And - .BeOfType(); - httpClient.Should().NotBeNull(); - httpClient.DefaultRequestHeaders.Authorization.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", ApiKey)); - httpClient.BaseAddress.Should().BeEquivalentTo(new Uri(ProxyApi)); + Assert.NotNull(client); + Assert.IsType(client); + Assert.NotNull(httpClient); + Assert.Equivalent( + new AuthenticationHeaderValue("Bearer", ApiKey), + httpClient.DefaultRequestHeaders.Authorization); + Assert.Equivalent(new Uri(ProxyApi), httpClient.BaseAddress); } [Fact] @@ -93,15 +102,18 @@ public void Configuration_CustomSectionName_Inject() // Act services.AddDashScopeClient(configuration, "dashScopeCustom"); var provider = services.BuildServiceProvider(); - var httpClient = provider.GetRequiredService().CreateClient(nameof(IDashScopeClient)); + var httpClient = provider.GetRequiredService() + .CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName); + var client = provider.GetRequiredService(); // Assert - provider.GetRequiredService().Should().NotBeNull().And - .BeOfType(); - httpClient.Should().NotBeNull(); - httpClient.DefaultRequestHeaders.Authorization.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", ApiKey)); - httpClient.BaseAddress.Should().BeEquivalentTo(new Uri(ProxyApi)); + Assert.NotNull(client); + Assert.IsType(client); + Assert.NotNull(httpClient); + Assert.Equivalent( + new AuthenticationHeaderValue("Bearer", ApiKey), + httpClient.DefaultRequestHeaders.Authorization); + Assert.Equivalent(new Uri(ProxyApi), httpClient.BaseAddress); } [Fact] @@ -111,18 +123,21 @@ public void Configuration_AddMultipleTime_Replace() var services = new ServiceCollection(); // Act - services.AddDashScopeClient(ApiKey, ProxyApi); - services.AddDashScopeClient(ApiKey, ProxyApi); + services.AddDashScopeClient(ApiKey, baseAddress: ProxyApi); + services.AddDashScopeClient(ApiKey, baseAddress: ProxyApi); var provider = services.BuildServiceProvider(); - var httpClient = provider.GetRequiredService().CreateClient(nameof(IDashScopeClient)); + var httpClient = provider.GetRequiredService() + .CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName); + var client = provider.GetRequiredService(); // Assert - provider.GetRequiredService().Should().NotBeNull().And - .BeOfType(); - httpClient.Should().NotBeNull(); - httpClient.DefaultRequestHeaders.Authorization.Should() - .BeEquivalentTo(new AuthenticationHeaderValue("Bearer", ApiKey)); - httpClient.BaseAddress.Should().BeEquivalentTo(new Uri(ProxyApi)); + Assert.NotNull(client); + Assert.IsType(client); + Assert.NotNull(httpClient); + Assert.Equivalent( + new AuthenticationHeaderValue("Bearer", ApiKey), + httpClient.DefaultRequestHeaders.Authorization); + Assert.Equivalent(new Uri(ProxyApi), httpClient.BaseAddress); } [Fact] @@ -130,17 +145,13 @@ public void Configuration_NoApiKey_Throw() { // Arrange var services = new ServiceCollection(); - var config = new Dictionary - { - { "irrelevant", "irr" }, - { "dashScope:baseAddress", ProxyApi } - }; + var config = new Dictionary { { "irrelevant", "irr" }, { "dashScope:baseAddress", ProxyApi } }; var configuration = new ConfigurationBuilder().AddInMemoryCollection(config).Build(); // Act var act = () => services.AddDashScopeClient(configuration); // Assert - act.Should().Throw(); + Assert.Throws(act); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsCollection.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsCollection.cs new file mode 100644 index 0000000..29e36f6 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsCollection.cs @@ -0,0 +1,6 @@ +namespace Cnblogs.DashScope.Sdk.UnitTests; + +[CollectionDefinition(nameof(SocketTestsCollection), DisableParallelization = true)] +public class SocketTestsCollection : ICollectionFixture +{ +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsFixture.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsFixture.cs new file mode 100644 index 0000000..d4917aa --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/SocketTestsFixture.cs @@ -0,0 +1,6 @@ +namespace Cnblogs.DashScope.Sdk.UnitTests; + +public class SocketTestsFixture +{ + // leaving blank on purpose +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/SpeechSynthesizerSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/SpeechSynthesizerSerializationTests.cs new file mode 100644 index 0000000..ac20641 --- /dev/null +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/SpeechSynthesizerSerializationTests.cs @@ -0,0 +1,206 @@ +using Cnblogs.DashScope.Tests.Shared.Utils; + +namespace Cnblogs.DashScope.Sdk.UnitTests; + +[Collection(nameof(SocketTestsCollection))] +public class SpeechSynthesizerSerializationTests +{ + [Fact] + public async Task RunTask_SpecifyTaskId_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var snapshot = Snapshots.SpeechSynthesizer.RunTask; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(snapshot.Message.Payload.Model!); + var taskId = await session.RunTaskAsync(snapshot.Message.Header.TaskId, snapshot.Message.Payload.Parameters!); + + // Assert + Assert.Equal(snapshot.Message.Header.TaskId, taskId); + Assert.True(Checkers.IsJsonEquivalent(server.ServerReceivedMessages.First(), snapshot.GetMessageJson())); + } + + [Fact] + public async Task RunTask_GenerateTaskId_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var snapshot = Snapshots.SpeechSynthesizer.RunTask; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(snapshot.Message.Payload.Model!); + var taskId = await session.RunTaskAsync(snapshot.Message.Payload.Parameters!); + + // Assert + var json = snapshot.GetMessageJson().Replace(snapshot.Message.Header.TaskId, taskId); + Assert.True(Checkers.IsJsonEquivalent(server.ServerReceivedMessages.First(), json)); + } + + [Fact] + public async Task ContinueTask_WithInput_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var continueTask = Snapshots.SpeechSynthesizer.ContinueTask; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!); + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.ContinueTaskAsync(continueTask.Message.Header.TaskId, continueTask.Message.Payload.Input.Text!); + + // Assert + Assert.True(Checkers.IsJsonEquivalent(server.ServerReceivedMessages.Last(), continueTask.GetMessageJson())); + } + + [Fact] + public async Task FinishTask_NoPayload_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var continueTask = Snapshots.SpeechSynthesizer.ContinueTask; + var finishTask = Snapshots.SpeechSynthesizer.FinishTask; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!); + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.ContinueTaskAsync(continueTask.Message.Header.TaskId, continueTask.Message.Payload.Input.Text!); + await session.FinishTaskAsync(finishTask.Message.Header.TaskId); + + // Assert + Assert.True(Checkers.IsJsonEquivalent(server.ServerReceivedMessages.Last(), finishTask.GetMessageJson())); + } + + [Fact] + public async Task ResultGenerated_WithBinary_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var finishTask = Snapshots.SpeechSynthesizer.FinishTask; + var resultGenerated = Snapshots.SpeechSynthesizer.ResultGenerated; + var ttsBinary = Snapshots.SpeechSynthesizer.AudioTts; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + server.Playlist.Enqueue(async s => + { + await s.WriteServerMessageAsync(resultGenerated.GetMessageJson()); + await s.WriteServerMessageAsync(ttsBinary); + await s.WriteServerCloseAsync(); + }); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!); + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.FinishTaskAsync(finishTask.Message.Header.TaskId); + var jsonEvents = await session.GetMessagesAsync().ToListAsync(); + var binaryContent = await session.GetAudioAsync().ToArrayAsync(); + + // Assert + Assert.Equivalent(ttsBinary, binaryContent); + Assert.Equal(2, jsonEvents.Count); // task-started, result-generated + Assert.Equivalent(resultGenerated.Message, jsonEvents.Last()); + } + + [Fact] + public async Task TaskFinished_ServerClose_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var finishTask = Snapshots.SpeechSynthesizer.FinishTask; + var resultGenerated = Snapshots.SpeechSynthesizer.ResultGenerated; + var taskFinished = Snapshots.SpeechSynthesizer.TaskFinished; + var ttsBinary = Snapshots.SpeechSynthesizer.AudioTts; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + server.Playlist.Enqueue(async s => + { + await s.WriteServerMessageAsync(resultGenerated.GetMessageJson()); + await s.WriteServerMessageAsync(ttsBinary); + await s.WriteServerMessageAsync(taskFinished.GetMessageJson()); + await s.WriteServerCloseAsync(); + }); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!); + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.FinishTaskAsync(finishTask.Message.Header.TaskId); + var jsonEvents = await session.GetMessagesAsync().ToListAsync(); + var binaryContent = await session.GetAudioAsync().ToArrayAsync(); + + // Assert + Assert.Equivalent(ttsBinary, binaryContent); + Assert.Equal(3, jsonEvents.Count); // task-started, result-generated, task-finished + Assert.Equivalent(taskFinished.Message, jsonEvents.Last()); + } + + [Fact] + public async Task TaskFailed_ServerClose_SuccessAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var finishTask = Snapshots.SpeechSynthesizer.FinishTask; + var taskFailed = Snapshots.SpeechSynthesizer.TaskFailed; + var taskStarted = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStarted.GetMessageJson())); + server.Playlist.Enqueue(async s => + { + await s.WriteServerMessageAsync(taskFailed.GetMessageJson()); + await s.WriteServerCloseAsync(); + }); + + // Act + using var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!); + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.FinishTaskAsync(finishTask.Message.Header.TaskId); + var jsonEvents = await session.GetMessagesAsync().ToListAsync(); + var binaryContent = await session.GetAudioAsync().ToArrayAsync(); + + // Assert + Assert.Empty(binaryContent); + Assert.Equal(2, jsonEvents.Count); // task-started, task-failed + Assert.Equivalent(taskFailed.Message, jsonEvents.Last()); + } + + [Fact] + public async Task Dispose_DisposedByUsings_ReturnSocketAsync() + { + // Arrange + var (client, _, server) = await Sut.GetSocketTestClientAsync(); + var runTask = Snapshots.SpeechSynthesizer.RunTask; + var finishTask = Snapshots.SpeechSynthesizer.FinishTask; + var resultGenerated = Snapshots.SpeechSynthesizer.ResultGenerated; + var taskFinished = Snapshots.SpeechSynthesizer.TaskFinished; + var ttsBinary = Snapshots.SpeechSynthesizer.AudioTts; + var taskStartedEvent = Snapshots.SpeechSynthesizer.TaskStarted; + server.Playlist.Enqueue(async s => await s.WriteServerMessageAsync(taskStartedEvent.GetMessageJson())); + server.Playlist.Enqueue(async s => + { + await s.WriteServerMessageAsync(resultGenerated.GetMessageJson()); + await s.WriteServerMessageAsync(ttsBinary); + await s.WriteServerMessageAsync(taskFinished.GetMessageJson()); + }); + + // Act + using (var session = await client.CreateSpeechSynthesizerSocketSessionAsync(runTask.Message.Payload.Model!)) + { + await session.RunTaskAsync(runTask.Message.Header.TaskId, runTask.Message.Payload.Parameters!); + await session.FinishTaskAsync(finishTask.Message.Header.TaskId); + } + + // Assert + Assert.False(server.DisposeCalled); + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TaskSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TaskSerializationTests.cs index 149d2db..f98005e 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TaskSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TaskSerializationTests.cs @@ -1,6 +1,5 @@ using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -19,7 +18,7 @@ public async Task GetTask_Unknown_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -34,7 +33,8 @@ public async Task CancelTask_TaskAlreadyCompleted_FailAsync() var act = async () => await client.CancelTaskAsync(Cases.Uuid); // Assert - (await act.Should().ThrowAsync()).And.Error.Should().BeEquivalentTo(testCase.ResponseModel); + var ex = await Assert.ThrowsAsync(act); + Assert.Equivalent(testCase.ResponseModel, ex.Error); } [Fact] @@ -50,7 +50,7 @@ public async Task GetTask_BatchEmbeddings_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -66,7 +66,7 @@ public async Task GetTask_ImageSynthesis_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -82,7 +82,7 @@ public async Task GetTask_ImageGeneration_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -98,7 +98,7 @@ public async Task GetTask_BackgroundGeneration_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -114,7 +114,7 @@ public async Task GetTask_RunningTask_SuccessAsync() testCase.ResponseModel.Output.TaskId); // Assert - task.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, task); } [Fact] @@ -136,6 +136,6 @@ public async Task ListTasks_Tasks_SuccessAsync() status: DashScopeTaskStatus.Succeeded); // Assert - tasks.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, tasks); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingApiTests.cs index bbe1abb..d82d43a 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingApiTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingApiTests.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; using Cnblogs.DashScope.Sdk.TextEmbedding; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -20,8 +20,23 @@ public async Task GetEmbeddings_UseEnum_SuccessAsync() // Assert await client.Received().GetEmbeddingsAsync( - Arg.Is>( - s => s.Input.Texts == texts && s.Model == "text-embedding-v2" && s.Parameters == parameters)); + Arg.Is>(s + => s.Input.Texts == texts && s.Model == "text-embedding-v2" && s.Parameters == parameters)); + } + + [Fact] + public async Task GetEmbeddings_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + var texts = new[] { "hello" }; + var parameters = new TextEmbeddingParameters { TextType = TextTypes.Query }; + + // Act + var act = async () => await client.GetTextEmbeddingsAsync((TextEmbeddingModel)(-1), texts, parameters); + + // Assert + await Assert.ThrowsAsync(act); } [Fact] @@ -37,7 +52,7 @@ public async Task GetEmbeddings_CustomModel_SuccessAsync() // Assert await client.Received().GetEmbeddingsAsync( - Arg.Is>( - s => s.Input.Texts == texts && s.Model == Cases.CustomModelName && s.Parameters == parameters)); + Arg.Is>(s + => s.Input.Texts == texts && s.Model == Cases.CustomModelName && s.Parameters == parameters)); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingSerializationTests.cs index a662ade..49c3553 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TextEmbeddingSerializationTests.cs @@ -1,5 +1,6 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Tests.Shared.Utils; + using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,10 +22,9 @@ public async Task TextEmbedding_MultipleTexts_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Output.Embeddings[0].Embedding.Should().NotBeEmpty(); // embedding array is too large - response.Should().BeEquivalentTo( - testCase.ResponseModel, - o => o.Excluding(x => x.Output.Embeddings[0].Embedding)); + Assert.NotEmpty(response.Output.Embeddings[0].Embedding); // embedding array is too large + response = response with { Output = new TextEmbeddingOutput(response.Output.Embeddings) }; + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -42,6 +42,6 @@ public async Task BatchTextEmbedding_ReturnTask_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationSerializationTests.cs index de32581..7eb5642 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationSerializationTests.cs @@ -1,7 +1,6 @@ using System.Text; using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -23,7 +22,7 @@ public async Task SingleCompletion_TextFormatNoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Fact] @@ -43,9 +42,20 @@ public async Task SingleCompletion_TextFormatSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.FinishReason.Should().Be("null")); - outputs.Last().Should().BeEquivalentTo(testCase.ResponseModel, o => o.Excluding(y => y.Output.Text)); - message.ToString().Should().Be(testCase.ResponseModel.Output.Text); + Assert.All(outputs.SkipLast(1), x => Assert.Equal("null", x.Output.FinishReason)); + Assert.Equal(testCase.ResponseModel.Output.Text, message.ToString()); + var last = outputs.Last(); + last = last with + { + Output = new TextGenerationOutput() + { + Text = testCase.ResponseModel.Output.Text, + Choices = last.Output.Choices, + FinishReason = last.Output.FinishReason, + SearchInfo = last.Output.SearchInfo + } + }; + Assert.Equivalent(testCase.ResponseModel, last); } [Theory] @@ -65,7 +75,7 @@ public async Task SingleCompletion_MessageFormatNoSse_SuccessAsync( handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Theory] @@ -83,25 +93,33 @@ public async Task SingleCompletion_MessageFormatSse_SuccessAsync( var message = new StringBuilder(); var reasoning = new StringBuilder(); var outputs = await client.GetTextCompletionStreamAsync(testCase.RequestModel).ToListAsync(); - outputs.ForEach( - x => - { - message.Append(x.Output.Choices![0].Message.Content); - reasoning.Append(x.Output.Choices![0].Message.ReasoningContent ?? string.Empty); - }); + outputs.ForEach(x => + { + message.Append(x.Output.Choices![0].Message.Content); + reasoning.Append(x.Output.Choices![0].Message.ReasoningContent ?? string.Empty); + }); // Assert handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.Choices![0].FinishReason.Should().Be("null")); - outputs.Last().Should().BeEquivalentTo( - testCase.ResponseModel, - o => o.Excluding(y => y.Output.Choices![0].Message.Content) - .Excluding(y => y.Output.Choices![0].Message.ReasoningContent)); - message.ToString().Should().Be(testCase.ResponseModel.Output.Choices![0].Message.Content); - reasoning.ToString().Should() - .Be(testCase.ResponseModel.Output.Choices![0].Message.ReasoningContent ?? string.Empty); + Assert.All(outputs.SkipLast(1), x => Assert.Equal("null", x.Output.Choices![0].FinishReason)); + Assert.Equal(testCase.ResponseModel.Output.Choices![0].Message.Content, message.ToString()); + Assert.Equal( + testCase.ResponseModel.Output.Choices![0].Message.ReasoningContent ?? string.Empty, + reasoning.ToString()); + var last = outputs.Last(); + last.Output.Choices = new List + { + new() + { + Message = last.Output.Choices![0].Message with + { + Content = testCase.ResponseModel.Output.Choices[0].Message.Content, + ReasoningContent = testCase.ResponseModel.Output.Choices[0].Message.ReasoningContent + } + } + }; } [Theory] @@ -121,7 +139,7 @@ public async Task ConversationCompletion_MessageFormatNoSse_SuccessAsync( handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } [Theory] @@ -143,11 +161,12 @@ public async Task ConversationCompletion_MessageFormatSse_SuccessAsync( handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - outputs.SkipLast(1).Should().AllSatisfy(x => x.Output.Choices![0].FinishReason.Should().Be("null")); - outputs.Last().Should().BeEquivalentTo( - testCase.ResponseModel, - o => o.Excluding(y => y.Output.Choices![0].Message.Content)); - message.ToString().Should().Be(testCase.ResponseModel.Output.Choices![0].Message.Content); + Assert.All(outputs.SkipLast(1), x => Assert.Equal("null", x.Output.Choices![0].FinishReason)); + Assert.Equal(testCase.ResponseModel.Output.Choices![0].Message.Content, message.ToString()); + var last = outputs.Last(); + last.Output.Choices![0].Message = + TextChatMessage.Assistant(testCase.ResponseModel.Output.Choices[0].Message.Content); + Assert.Equivalent(testCase.ResponseModel, last); } public static readonly TheoryData, @@ -155,7 +174,10 @@ public async Task ConversationCompletion_MessageFormatSse_SuccessAsync( Snapshots.TextGeneration.MessageFormat.SingleMessage, Snapshots.TextGeneration.MessageFormat.SingleMessageReasoning, Snapshots.TextGeneration.MessageFormat.SingleMessageWithTools, - Snapshots.TextGeneration.MessageFormat.SingleMessageJson); + Snapshots.TextGeneration.MessageFormat.SingleMessageJson, + Snapshots.TextGeneration.MessageFormat.SingleMessageLogprobs, + Snapshots.TextGeneration.MessageFormat.SingleMessageTranslation, + Snapshots.TextGeneration.MessageFormat.SingleMessageWebSearch); public static readonly TheoryData, ModelResponse>> SingleGenerationMessageSseFormatData = new( diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationStopConverterTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationStopConverterTests.cs index 26c4af3..6afe6c5 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationStopConverterTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TextGenerationStopConverterTests.cs @@ -1,6 +1,5 @@ using System.Text.Json; using Cnblogs.DashScope.Core; -using FluentAssertions; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -20,7 +19,7 @@ public void TextGenerationStopConvertor_Serialize_Success(TextGenerationStop? st var actual = JsonSerializer.Serialize(obj, SerializerOptions); // Assert - actual.Should().Be(json); + Assert.Equal(json, actual); } [Theory] @@ -31,7 +30,7 @@ public void TextGenerationStopConvertor_Deserialize_Success(TextGenerationStop? var obj = JsonSerializer.Deserialize(json, SerializerOptions); // Assert - obj.Should().BeEquivalentTo(new TestObj(stop)); + Assert.Equivalent(new TestObj(stop), obj); } [Theory] @@ -42,7 +41,7 @@ public void TextGenerationStopConvertor_InvalidJson_Exception(string json) var act = () => JsonSerializer.Deserialize(json, SerializerOptions); // Assert - act.Should().Throw(); + Assert.Throws(act); } public record TestObj(TextGenerationStop? Stop); @@ -50,20 +49,26 @@ public record TestObj(TextGenerationStop? Stop); public static TheoryData Data => new() { - { new TextGenerationStop("hello"), """{"stop":"hello"}""" }, - { new TextGenerationStop(["hello", "world"]), """{"stop":["hello","world"]}""" }, - { new TextGenerationStop([12, 334]), """{"stop":[12,334]}""" }, - { new TextGenerationStop([[12, 334]]), """{"stop":[[12,334]]}""" }, - { null, """{"stop":null}""" } + { new TextGenerationStop("hello"), @"{""stop"":""hello""}" }, + { + new TextGenerationStop(new List { "hello", "world" }.AsReadOnly()), + "{\"stop\":[\"hello\",\"world\"]}" + }, + { new TextGenerationStop(new[] { 12, 334 }), "{\"stop\":[12,334]}" }, + { + new TextGenerationStop(new List { new[] { 12, 334 } }.AsReadOnly()), + "{\"stop\":[[12,334]]}" + }, + { null, "{\"stop\":null}" } }; public static TheoryData InvalidJson => new() { - """{"stop":{}}""", - """{"stop":[1234,"hello"]}""", - """{"stop":["hello"}}""", - """{"stop":[[34243,"hello"]]}""", - """{"stop":[[34243,123]}}""" + "{\"stop\":{}}", + "{\"stop\":[1234,\"hello\"]}", + "{\"stop\":[\"hello\"}}", + "{\"stop\":[[34243,\"hello\"]]}", + "{\"stop\":[[34243,123]}}" }; } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/TokenizationSerializationTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/TokenizationSerializationTests.cs index 08e4cae..c57e3c2 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/TokenizationSerializationTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/TokenizationSerializationTests.cs @@ -1,5 +1,5 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; -using FluentAssertions; +using Cnblogs.DashScope.Tests.Shared.Utils; + using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -21,6 +21,6 @@ public async Task Tokenization_NoSse_SuccessAsync() handler.Received().MockSend( Arg.Is(m => Checkers.IsJsonEquivalent(m.Content!, testCase.GetRequestJson(sse))), Arg.Any()); - response.Should().BeEquivalentTo(testCase.ResponseModel); + Assert.Equivalent(testCase.ResponseModel, response); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ToolChoiceJsonConverterTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ToolChoiceJsonConverterTests.cs index 077a4b0..f260c35 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ToolChoiceJsonConverterTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ToolChoiceJsonConverterTests.cs @@ -1,6 +1,5 @@ using System.Text.Json; using Cnblogs.DashScope.Core; -using FluentAssertions; namespace Cnblogs.DashScope.Sdk.UnitTests; @@ -20,7 +19,7 @@ public void TextGenerationStopConvertor_Serialize_Success(ToolChoice? choice, st var actual = JsonSerializer.Serialize(obj, SerializerOptions); // Assert - actual.Should().Be(json); + Assert.Equal(json, actual); } [Theory] @@ -31,7 +30,7 @@ public void TextGenerationStopConvertor_Deserialize_Success(ToolChoice? choice, var obj = JsonSerializer.Deserialize(json, SerializerOptions); // Assert - obj.Should().BeEquivalentTo(new TestObj(choice)); + Assert.Equivalent(new TestObj(choice), obj); } [Theory] @@ -42,7 +41,7 @@ public void TextGenerationStopConvertor_InvalidJson_Exception(string json) var act = () => JsonSerializer.Deserialize(json, SerializerOptions); // Assert - act.Should().Throw(); + Assert.Throws(act); } public record TestObj(ToolChoice? Choice); @@ -50,19 +49,19 @@ public record TestObj(ToolChoice? Choice); public static TheoryData Data => new() { - { ToolChoice.AutoChoice, """{"choice":"auto"}""" }, - { ToolChoice.NoneChoice, """{"choice":"none"}""" }, - { ToolChoice.FunctionChoice("weather"), """{"choice":{"type":"function","function":{"name":"weather"}}}""" }, - { null, """{"choice":null}""" } + { ToolChoice.AutoChoice, "{\"choice\":\"auto\"}" }, + { ToolChoice.NoneChoice, "{\"choice\":\"none\"}" }, + { ToolChoice.FunctionChoice("weather"), "{\"choice\":{\"type\":\"function\",\"function\":{\"name\":\"weather\"}}}" }, + { null, "{\"choice\":null}" } }; public static TheoryData InvalidJson => new() { - """{"choice":{}}""", - """{"choice":"other"}""", - """{"choice":{"type":"other"}}""", - """{"choice":{"type":"other", "function":{"name": "weather"}}}""", - """{"choice":{"type":"function", "function": "other"}}""" + "{\"choice\":{}}", + "{\"choice\":\"other\"}", + "{\"choice\":{\"type\":\"other\"}}", + "{\"choice\":{\"type\":\"other\", \"function\":{\"name\": \"weather\"}}}", + "{\"choice\":{\"type\":\"function\", \"function\": \"other\"}}" }; } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/EquivalentUtils.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/EquivalentUtils.cs deleted file mode 100644 index 70f6e54..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/EquivalentUtils.cs +++ /dev/null @@ -1,20 +0,0 @@ -using FluentAssertions; - -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; - -public static class EquivalentUtils -{ - internal static bool IsEquivalent(this T left, T right) - { - try - { - left.Should().BeEquivalentTo(right); - } - catch (Exception) - { - return false; - } - - return true; - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/GetCurrentWeatherParameters.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/GetCurrentWeatherParameters.cs deleted file mode 100644 index 3d606f3..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/GetCurrentWeatherParameters.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Text.Json.Serialization; -using Json.More; -using Json.Schema.Generation; - -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; - -public record GetCurrentWeatherParameters( - [property: Required] - [property: Description("要获取天气的省市名称,例如浙江省杭州市")] - string Location, - [property: JsonConverter(typeof(EnumStringConverter))] - [property: Description("温度单位")] - TemperatureUnit Unit = TemperatureUnit.Celsius); - -public enum TemperatureUnit -{ - Celsius, - Fahrenheit -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.MultimodalGeneration.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.MultimodalGeneration.cs deleted file mode 100644 index 20f17f5..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.MultimodalGeneration.cs +++ /dev/null @@ -1,517 +0,0 @@ -using Cnblogs.DashScope.Core; - -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; - -public static partial class Snapshots -{ - public static class MultimodalGeneration - { - public static readonly RequestSnapshot, - ModelResponse> VlNoSse = - new( - "multimodal-generation-vl", - new ModelRequest - { - Model = "qwen-vl-plus", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.System( - [MultimodalMessageContent.TextContent("You are a helpful assistant.")]), - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"), - MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") - ]) - ] - }, - Parameters = new MultimodalParameters - { - Seed = 1234, - TopK = 100, - TopP = 0.81f, - Temperature = 1.1f, - VlHighResolutionImages = true, - RepetitionPenalty = 1.3f, - PresencePenalty = 1.2f, - MaxTokens = 120, - Stop = "你好" - } - }, - new ModelResponse - { - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent("海滩。") - ])) - ]), - RequestId = "e81aa922-be6c-9f9d-bd4f-0f43e21fd913", - Usage = new MultimodalTokenUsage - { - OutputTokens = 3, - InputTokens = 3613, - ImageTokens = 3577 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> VlChatClientNoSse = - new( - "multimodal-generation-vl", - new ModelRequest - { - Model = "qwen-vl-plus", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="), - MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") - ]) - ] - }, - Parameters = new MultimodalParameters - { - Seed = 1234, - TopK = 100, - TopP = 0.81f, - Temperature = 1.1f, - RepetitionPenalty = 1.3f, - PresencePenalty = 1.2f, - MaxTokens = 120, - } - }, - new ModelResponse - { - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent("海滩。") - ])) - ]), - RequestId = "e81aa922-be6c-9f9d-bd4f-0f43e21fd913", - Usage = new MultimodalTokenUsage - { - OutputTokens = 3, - InputTokens = 3613, - ImageTokens = 3577 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> VlSse = - new( - "multimodal-generation-vl", - new ModelRequest - { - Model = "qwen-vl-plus", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.System( - [MultimodalMessageContent.TextContent("You are a helpful assistant.")]), - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"), - MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") - ]) - ] - }, - Parameters = new MultimodalParameters - { - IncrementalOutput = true, - Seed = 1234, - TopK = 100, - TopP = 0.81f - } - }, - new ModelResponse - { - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "这是一个海滩,有沙滩和海浪。在前景中坐着一个女人与她的宠物狗互动。背景中有海水、阳光及远处的海岸线。由于没有具体标识物或地标信息,我无法提供更精确的位置描述。这可能是一个公共海滩或是私人区域。重要的是要注意不要泄露任何个人隐私,并遵守当地的规定和法律法规。欣赏自然美景的同时请尊重环境和其他访客。") - ])) - ]), - RequestId = "13c5644d-339c-928a-a09a-e0414bfaa95c", - Usage = new MultimodalTokenUsage - { - OutputTokens = 85, - InputTokens = 1283, - ImageTokens = 1247 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> VlChatClientSse = - new( - "multimodal-generation-vl", - new ModelRequest - { - Model = "qwen-vl-plus", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="), - MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") - ]) - ] - }, - Parameters = new MultimodalParameters - { - IncrementalOutput = true, - Seed = 1234, - TopK = 100, - TopP = 0.81f, - } - }, - new ModelResponse - { - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "这是一个海滩,有沙滩和海浪。在前景中坐着一个女人与她的宠物狗互动。背景中有海水、阳光及远处的海岸线。由于没有具体标识物或地标信息,我无法提供更精确的位置描述。这可能是一个公共海滩或是私人区域。重要的是要注意不要泄露任何个人隐私,并遵守当地的规定和法律法规。欣赏自然美景的同时请尊重环境和其他访客。") - ])) - ]), - RequestId = "13c5644d-339c-928a-a09a-e0414bfaa95c", - Usage = new MultimodalTokenUsage - { - OutputTokens = 85, - InputTokens = 1283, - ImageTokens = 1247 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - OcrNoSse = new( - "multimodal-generation-vl-ocr", - new ModelRequest - { - Model = "qwen-vl-ocr", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg", - 3136, - 1003520), - MultimodalMessageContent.TextContent("Read all the text in the image.") - ]), - ] - }, - Parameters = new MultimodalParameters - { - Temperature = 0.1f, - RepetitionPenalty = 1.05f, - MaxTokens = 2000, - TopP = 0.01f - } - }, - new ModelResponse - { - RequestId = "195c98cd-4ee5-998b-b662-132b7aebc048", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "读者对象 如果你是Linux环境下的系统管理员,那么学会编写shell脚本将让你受益匪浅。本书并未细述安装 Linux系统的每个步骤,但只要系统已安装好Linux并能运行起来,你就可以开始考虑如何让一些日常 的系统管理任务实现自动化。这时shell脚本编程就能发挥作用了,这也正是本书的作用所在。本书将 演示如何使用shell脚本来自动处理系统管理任务,包括从监测系统统计数据和数据文件到为你的老板 生成报表。 如果你是家用Linux爱好者,同样能从本书中获益。现今,用户很容易在诸多部件堆积而成的图形环境 中迷失。大多数桌面Linux发行版都尽量向一般用户隐藏系统的内部细节。但有时你确实需要知道内部 发生了什么。本书将告诉你如何启动Linux命令行以及接下来要做什么。通常,如果是执行一些简单任 务(比如文件管理) , 在命令行下操作要比在华丽的图形界面下方便得多。在命令行下有大量的命令 可供使用,本书将会展示如何使用它们。") - ])) - ]), - Usage = new MultimodalTokenUsage - { - InputTokens = 1248, - OutputTokens = 225, - ImageTokens = 1219 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - OcrSse = new( - "multimodal-generation-vl-ocr", - new ModelRequest - { - Model = "qwen-vl-ocr", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.ImageContent( - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg", - 3136, - 1003520), - MultimodalMessageContent.TextContent("Read all the text in the image.") - ]), - ] - }, - Parameters = new MultimodalParameters - { - Temperature = 0.1f, - RepetitionPenalty = 1.05f, - MaxTokens = 2000, - TopP = 0.01f, - IncrementalOutput = true - } - }, - new ModelResponse - { - RequestId = "fb33a990-3826-9386-8b0a-8317dfc38c1c", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "读者对象 如果你是Linux环境下的系统管理员,那么学会编写shell脚本将让你受益匪浅。本书并未细述安装 Linux系统的每个步骤,但只要系统已安装好Linux并能运行起来,你就可以开始考虑如何让一些日常 的系统管理任务实现自动化。这时shell脚本编程就能发挥作用了,这也正是本书的作用所在。本书将 演示如何使用shell脚本来自动处理系统管理任务,包括从监测系统统计数据和数据文件到为你的老板 生成报表。 如果你是家用Linux爱好者,同样能从本书中获益。现今,用户很容易在诸多部件堆积而成的图形环境 中迷失。大多数桌面Linux发行版都尽量向一般用户隐藏系统的内部细节。但有时你确实需要知道内部 发生了什么。本书将告诉你如何启动Linux命令行以及接下来要做什么。通常,如果是执行一些简单任 务(比如文件管理) , 在命令行下操作要比在华丽的图形界面下方便得多。在命令行下有大量的命令 可供使用,本书将会展示如何使用它们。") - ])) - ]), - Usage = new MultimodalTokenUsage - { - InputTokens = 1248, - OutputTokens = 225, - ImageTokens = 1219 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - AudioNoSse = new( - "multimodal-generation-audio", - new ModelRequest - { - Model = "qwen-audio-turbo", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.System( - [MultimodalMessageContent.TextContent("You are a helpful assistant.")]), - MultimodalMessage.User( - [ - MultimodalMessageContent.AudioContent( - "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/2channel_16K.wav"), - MultimodalMessageContent.TextContent("这段音频在说什么,请用简短的语言回答") - ]) - ] - }, - Parameters = new MultimodalParameters - { - Seed = 1234, - TopK = 100, - TopP = 0.81f - } - }, - new ModelResponse - { - RequestId = "6b6738bd-dd9d-9e78-958b-02574acbda44", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "这段音频在说中文,内容是\"没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网\"。") - ])) - ]), - Usage = new MultimodalTokenUsage - { - InputTokens = 786, - OutputTokens = 38, - AudioTokens = 752 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - AudioSse = new( - "multimodal-generation-audio", - new ModelRequest - { - Model = "qwen-audio-turbo", - Input = new MultimodalInput - { - Messages = - [ - MultimodalMessage.System( - [MultimodalMessageContent.TextContent("You are a helpful assistant.")]), - MultimodalMessage.User( - [ - MultimodalMessageContent.AudioContent( - "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/2channel_16K.wav"), - MultimodalMessageContent.TextContent("这段音频的第一句话说了什么?") - ]) - ] - }, - Parameters = new MultimodalParameters - { - Seed = 1234, - TopK = 100, - TopP = 0.81f, - IncrementalOutput = true - } - }, - new ModelResponse - { - RequestId = "bb6ab962-af57-99f1-9af8-eb7016ebc18e", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent("第一句话说了没有我互联网。") - ])) - ]), - Usage = new MultimodalTokenUsage - { - InputTokens = 783, - OutputTokens = 7, - AudioTokens = 752 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - VideoNoSse = new( - "multimodal-generation-vl-video", - new ModelRequest() - { - Model = "qwen-vl-max", - Input = new MultimodalInput() - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.VideoContent( - [ - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg" - ]), - MultimodalMessageContent.TextContent("描述这个视频的具体过程") - ]), - ] - }, - Parameters = new MultimodalParameters() - { - Seed = 1234, - TopP = 0.01f, - Temperature = 0.1f, - RepetitionPenalty = 1.05f - } - }, - new ModelResponse() - { - RequestId = "d538f8cc-8048-9ca8-9e8a-d2a49985b479", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "这段视频展示了一场足球比赛的精彩瞬间。具体过程如下:\n\n1. **背景**:画面中是一个大型体育场,观众席上坐满了观众,气氛热烈。\n2. **球员位置**:球场上有两队球员,一队穿着红色球衣,另一队穿着蓝色球衣。守门员穿着绿色球衣,站在球门前准备防守。\n3. **射门动作**:一名身穿红色球衣的球员在禁区内接到队友传球后,迅速起脚射门。\n4. **守门员扑救**:守门员看到对方射门后,立即做出反应,向左侧跃出试图扑救。\n5. **进球瞬间**:尽管守门员尽力扑救,但皮球还是从他的右侧飞入了球网。\n\n整个过程充满了紧张和刺激,展示了足球比赛中的精彩时刻。") - ])) - ]), - Usage = new MultimodalTokenUsage() - { - VideoTokens = 1440, - InputTokens = 1466, - OutputTokens = 180 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - VideoSse = new( - "multimodal-generation-vl-video", - new ModelRequest() - { - Model = "qwen-vl-max", - Input = new MultimodalInput() - { - Messages = - [ - MultimodalMessage.User( - [ - MultimodalMessageContent.VideoContent( - [ - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg", - "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg" - ]), - MultimodalMessageContent.TextContent("描述这个视频的具体过程") - ]), - ] - }, - Parameters = new MultimodalParameters() - { - Seed = 1234, - TopP = 0.01f, - Temperature = 0.1f, - RepetitionPenalty = 1.05f, - IncrementalOutput = true - } - }, - new ModelResponse() - { - RequestId = "851745a1-22ba-90e2-ace2-c04e7445ec6f", - Output = new MultimodalOutput( - [ - new MultimodalChoice( - "stop", - MultimodalMessage.Assistant( - [ - MultimodalMessageContent.TextContent( - "这段视频展示了一场足球比赛的精彩瞬间。具体过程如下:\n\n1. **背景**:画面中是一个大型体育场,观众席上坐满了观众,气氛热烈。\n2. **球员位置**:场上有两队球员,一队穿着红色球衣,另一队穿着蓝色球衣。守门员穿着绿色球衣,站在球门前准备防守。\n3. **射门动作**:一名身穿红色球衣的球员在禁区内接到队友传球后,迅速起脚射门。\n4. **扑救尝试**:守门员看到射门后立即做出反应,向左侧跃出试图扑救。\n5. **进球瞬间**:尽管守门员尽力扑救,但皮球还是从他的右侧飞入了球网。\n\n整个过程充满了紧张和刺激,展示了足球比赛中的精彩时刻。") - ])) - ]), - Usage = new MultimodalTokenUsage() - { - VideoTokens = 1440, - InputTokens = 1466, - OutputTokens = 176 - } - }); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.TextGeneration.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.TextGeneration.cs deleted file mode 100644 index eca1ed8..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.TextGeneration.cs +++ /dev/null @@ -1,690 +0,0 @@ -using Cnblogs.DashScope.Core; -using Json.Schema; -using Json.Schema.Generation; - -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; - -public static partial class Snapshots -{ - public static class TextGeneration - { - public static class TextFormat - { - public static readonly RequestSnapshot, - ModelResponse> - SinglePrompt = new( - "single-generation-text", - new ModelRequest - { - Model = "qwen-max", - Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?" }, - Parameters = new TextGenerationParameters - { - ResultFormat = "text", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = false - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - FinishReason = "stop", Text = "1+1等于2。这是最基本的数学加法运算之一。" - }, - RequestId = "7e3d5586-cb70-98ce-97bf-8a2ac0091c3f", - Usage = new TextGenerationTokenUsage - { - InputTokens = 16, - OutputTokens = 14, - TotalTokens = 30, - PromptTokensDetails = new TextGenerationTokenDetails(0) - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SinglePromptIncremental = new( - "single-generation-text", - new ModelRequest - { - Model = "qwen-max", - Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?" }, - Parameters = new TextGenerationParameters - { - ResultFormat = "text", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = true - } - }, - new ModelResponse - { - Output = new TextGenerationOutput { FinishReason = "stop", Text = "1+1等于2。" }, - RequestId = "5b441aa7-0b9c-9fbc-ae0a-e2b212b71eac", - Usage = new TextGenerationTokenUsage - { - InputTokens = 16, - OutputTokens = 6, - TotalTokens = 22 - } - }); - } - - public static class MessageFormat - { - public static readonly RequestSnapshot, - ModelResponse> - SingleMessage = new( - "single-generation-message", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = false - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何两个相同的数字相加都等于该数字的二倍。") - } - ] - }, - RequestId = "e764bfe3-c0b7-97a0-ae57-cd99e1580960", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 47, - OutputTokens = 39, - InputTokens = 8 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SingleMessageReasoning = new( - "single-generation-message-reasoning", - new ModelRequest - { - Model = "deepseek-r1", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - IncrementalOutput = false - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1 + 1 等于 **2**。这是基础的算术加法,当我们将一个单位与另一个单位相加时,总和为两个单位。", - reasoningContent: "嗯,用户问1加1等于多少。这个问题看起来很简单,但可能有一些需要注意的地方。首先,我得确认用户是不是真的在问基本的数学问题,还是有其他的意图,比如测试我的反应或者开玩笑。\n\n1加1在基础算术里确实是2,但有时候可能会有不同的解释,比如在二进制中1+1等于10,或者在逻辑学中有时候表示为1,如果是布尔代数的话。不过通常情况下,用户可能只需要最直接的答案,也就是2。\n\n不过也有可能用户想考察我是否能够处理更复杂的情况,或者是否有隐藏的意思。比如,在某些情况下,1加1可能被用来比喻合作的效果,比如“1+1大于2”,但这可能超出了当前问题的范围。\n\n我需要考虑用户的背景。如果用户是小学生,那么直接回答2是正确的,并且可能需要鼓励的话。如果是成年人,可能还是同样的答案,但不需要额外的解释。如果用户来自数学或计算机领域,可能需要确认是否需要其他进制的答案,但通常默认是十进制。\n\n另外,检查是否有拼写错误或非阿拉伯数字的情况,比如罗马数字的I+I,但问题里明确写的是1+1,所以应该是阿拉伯数字。\n\n总结下来,最安全也是最正确的答案就是2。不过为了确保,可以简短地确认用户的意图,但按照常规问题处理,直接回答即可。") - } - ] - }, - RequestId = "7039d8ff-89e0-9191-b4d3-0d258a7d70e1", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 313, - OutputTokens = 302, - InputTokens = 11 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SingleChatClientMessage = new( - "single-generation-message", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - ToolChoice = ToolChoice.AutoChoice - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何两个相同的数字相加都等于该数字的二倍。") - } - ] - }, - RequestId = "e764bfe3-c0b7-97a0-ae57-cd99e1580960", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 47, - OutputTokens = 39, - InputTokens = 8 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SingleMessageJson = new( - "single-generation-message-json", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?用 JSON 格式输出。")] }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = false, - ResponseFormat = DashScopeResponseFormat.Json - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant("{\n \"result\": 2\n}") - } - ] - }, - RequestId = "6af9571b-1033-98f9-a287-c06f2e9d6f7f", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 34, - OutputTokens = 9, - InputTokens = 25 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SingleMessageIncremental = new( - "single-generation-message", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = true - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何情况下 1 加上另一个 1 的结果都是 2。") - } - ] - }, - RequestId = "d272255f-82d7-9cc7-93c5-17ff77024349", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 48, - OutputTokens = 40, - InputTokens = 8 - } - }); - public static readonly RequestSnapshot, - ModelResponse> - SingleMessageReasoningIncremental = new( - "single-generation-message-reasoning", - new ModelRequest - { - Model = "deepseek-r1", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - IncrementalOutput = true - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1+1 在基础算术中的答案是 **2**。\n\n不过,根据不同的数学或逻辑系统,结果可能不同:\n- **二进制**:1+1 = 10(读作“一零”)。\n- **布尔代数**:1+1 = 1(逻辑“或”运算)。\n- **抽象场景**:如“1滴水 + 1滴水 = 1大滴水”(非数学意义的合并)。\n\n日常问题中默认使用十进制算术,因此答案是 **2** \ud83d\ude0a。", - reasoningContent: "嗯,用户问1加1等于多少。这个问题看起来很简单,但其实可能有很多种情况需要考虑。首先,我得确定用户是不是在问数学上的基本加法。通常来说,1加1等于2,这是数学里的基本事实,根据皮亚诺公理或者基本的算术规则。不过,有时候问题可能有隐藏的含义,特别是在不同的语境下,答案可能会不同。比如在二进制中,1+1等于10,或者在布尔代数中,1+1可能等于1,如果是逻辑或运算的话。不过大部分情况下,尤其是在日常交流中,人们提到1+1的时候都是指十进制加法,结果自然是2。不过也有可能用户是在测试我的反应,或者想看看我会不会考虑其他可能性。比如在特定的谜语或笑话中,答案可能不是2,比如“1滴水加1滴水还是1滴水”,或者类似的文字游戏。但根据常规问题,我应该先给出正确的数学答案,再补充可能的其他情况,这样既准确又全面。所以可能先回答2,然后解释其他可能性。不过用户的问题看起来直接,可能不需要太复杂的解释,但为了保险起见,还是确认一下是否有其他意图比较好。或者用户可能只是单纯想知道答案,所以直接回答2即可。需要平衡简洁和全面性。可能先给出直接答案,然后简单说明其他情况的存在,这样既满足需求,又避免信息过载。总之,核心答案应该是2,但根据情况适当扩展。") - } - ] - }, - RequestId = "e4ad5d0f-8019-9716-adc6-eae1411d3c9a", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 417, - OutputTokens = 406, - InputTokens = 11 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - SingleMessageChatClientIncremental = new( - "single-generation-message", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput { Messages = [TextChatMessage.User("请问 1+1 是多少?")] }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new[] { "你好" }, - IncrementalOutput = true, - ToolChoice = ToolChoice.AutoChoice - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何情况下 1 加上另一个 1 的结果都是 2。") - } - ] - }, - RequestId = "d272255f-82d7-9cc7-93c5-17ff77024349", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 48, - OutputTokens = 40, - InputTokens = 8 - } - }); - - public static readonly - RequestSnapshot, - ModelResponse> SingleMessageWithTools = - new( - "single-generation-message-with-tools", - new ModelRequest - { - Model = "qwen-max", - Input = new TextGenerationInput { Messages = [TextChatMessage.User("杭州现在的天气如何?")] }, - Parameters = new TextGenerationParameters() - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - PresencePenalty = 1.2f, - Temperature = 0.85f, - Stop = new TextGenerationStop("你好"), - EnableSearch = false, - IncrementalOutput = false, - Tools = - [ - new ToolDefinition( - "function", - new FunctionDefinition( - "get_current_weather", - "获取现在的天气", - new JsonSchemaBuilder().FromType( - new SchemaGeneratorConfiguration - { - PropertyNameResolver = PropertyNameResolvers.LowerSnakeCase - }) - .Build())) - ], - ToolChoice = ToolChoice.FunctionChoice("get_current_weather") - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - string.Empty, - toolCalls: - [ - new ToolCall( - "call_cec4c19d27624537b583af", - ToolTypes.Function, - 0, - new FunctionCall( - "get_current_weather", - """{"location": "浙江省杭州市"}""")) - ]) - } - ] - }, - RequestId = "67300049-c108-9987-b1c1-8e0ee2de6b5d", - Usage = new TextGenerationTokenUsage - { - InputTokens = 211, - OutputTokens = 8, - TotalTokens = 219 - } - }); - - public static readonly - RequestSnapshot, - ModelResponse> SingleMessageChatClientWithTools = - new( - "single-generation-message-with-tools", - new ModelRequest - { - Model = "qwen-max", - Input = new TextGenerationInput { Messages = [TextChatMessage.User("杭州现在的天气如何?")] }, - Parameters = new TextGenerationParameters() - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - PresencePenalty = 1.2f, - Temperature = 0.85f, - Tools = - [ - new ToolDefinition( - "function", - new FunctionDefinition( - "get_current_weather", - "获取现在的天气", - new JsonSchemaBuilder().FromType( - new SchemaGeneratorConfiguration - { - PropertyNameResolver = PropertyNameResolvers.LowerSnakeCase - }) - .Build())) - ], - ToolChoice = ToolChoice.FunctionChoice("get_current_weather") - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - string.Empty, - toolCalls: - [ - new ToolCall( - "call_cec4c19d27624537b583af", - ToolTypes.Function, - 0, - new FunctionCall( - "get_current_weather", - """{"location": "浙江省杭州市"}""")) - ]) - } - ] - }, - RequestId = "67300049-c108-9987-b1c1-8e0ee2de6b5d", - Usage = new TextGenerationTokenUsage - { - InputTokens = 211, - OutputTokens = 8, - TotalTokens = 219 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - ConversationPartialMessageNoSse = new( - "conversation-generation-message-partial", - new ModelRequest() - { - Model = "qwen-max", - Input = new TextGenerationInput() - { - Messages = - [ - TextChatMessage.User("请对“春天来了,大地”这句话进行续写,来表达春天的美好和作者的喜悦之情"), - TextChatMessage.Assistant("春天来了,大地", true) - ] - }, - Parameters = new TextGenerationParameters() - { - ResultFormat = ResultFormats.Message, - Seed = 1234, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false - } - }, - new ModelResponse() - { - RequestId = "4c45d7fd-3158-9ff4-96a0-6e92c710df2c", - Output = new TextGenerationOutput() - { - Choices = - [ - new TextGenerationChoice() - { - FinishReason = "stop", - Message = - TextChatMessage.Assistant( - "仿佛从漫长的冬眠中苏醒过来,万物复苏。嫩绿的小草悄悄地探出了头,争先恐后地想要沐浴在温暖的阳光下;五彩斑斓的花朵也不甘示弱,竞相绽放着自己最美丽的姿态,将田野、山林装扮得分外妖娆。微风轻轻吹过,带来了泥土的气息与花香混合的独特香味,让人心旷神怡。小鸟们开始忙碌起来,在枝头欢快地歌唱,似乎也在庆祝这个充满希望的新季节的到来。这一切美好景象不仅让人感受到了大自然的魅力所在,更激发了人们对生活无限热爱和向往的心情。") - } - ] - }, - Usage = new TextGenerationTokenUsage() - { - TotalTokens = 165, - OutputTokens = 131, - InputTokens = 34 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - ConversationMessageIncremental = new( - "conversation-generation-message", - new ModelRequest - { - Model = "qwen-max", - Input = - new TextGenerationInput - { - Messages = - [ - TextChatMessage.User("现在请你记住一个数字,42"), - TextChatMessage.Assistant("好的,我已经记住了这个数字。"), - TextChatMessage.User("请问我刚才提到的数字是多少?") - ] - }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = true - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", Message = TextChatMessage.Assistant("您刚才提到的数字是42。") - } - ] - }, - RequestId = "9188e907-56c2-9849-97f6-23f130f7fed7", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 33, - OutputTokens = 9, - InputTokens = 24 - } - }); - - public static readonly RequestSnapshot, - ModelResponse> - ConversationMessageWithFilesIncremental = new( - "conversation-generation-message-with-files", - new ModelRequest - { - Model = "qwen-long", - Input = - new TextGenerationInput - { - Messages = - [ - TextChatMessage.File( - ["file-fe-WTTG89tIUTd4ByqP3K48R3bn", "file-fe-l92iyRvJm9vHCCfonLckf1o2"]), - TextChatMessage.User("这两个文件是相同的吗?") - ] - }, - Parameters = new TextGenerationParameters - { - ResultFormat = "message", - Seed = 1234, - MaxTokens = 1500, - TopP = 0.8f, - TopK = 100, - RepetitionPenalty = 1.1f, - Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, - EnableSearch = false, - IncrementalOutput = true - } - }, - new ModelResponse - { - Output = new TextGenerationOutput - { - Choices = - [ - new TextGenerationChoice - { - FinishReason = "stop", - Message = TextChatMessage.Assistant( - "你上传的两个文件并不相同。第一个文件`test1.txt`包含两行文本,每行都是“测试”。而第二个文件`test2.txt`只有一行文本,“测试2”。尽管它们都含有“测试”这个词,但具体内容和结构不同。") - } - ] - }, - RequestId = "7865ae43-8379-9c79-bef6-95050868bc52", - Usage = new TextGenerationTokenUsage - { - TotalTokens = 115, - OutputTokens = 57, - InputTokens = 58 - } - }); - } - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Sut.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Sut.cs deleted file mode 100644 index b6f1755..0000000 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Sut.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Cnblogs.DashScope.Core; -using NSubstitute; -using NSubstitute.Extensions; - -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; - -public static class Sut -{ - public static async Task<(IDashScopeClient Client, MockHttpMessageHandler Handler)> GetTestClientAsync( - bool sse, - RequestSnapshot testCase) - { - var pair = GetTestClient(); - var expected = await testCase.ToResponseMessageAsync(sse); - pair.Handler.Configure().MockSend(Arg.Any(), Arg.Any()) - .Returns(expected); - return pair; - } - - public static (DashScopeClientCore Client, MockHttpMessageHandler Handler) GetTestClient() - { - var handler = Substitute.ForPartsOf(); - var client = new DashScopeClientCore(new HttpClient(handler) { BaseAddress = new Uri("https://example.com") }); - return (client, handler); - } -} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/WanxApiTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/WanxApiTests.cs index 5a2c830..ad0dad0 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/WanxApiTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/WanxApiTests.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; -using Cnblogs.DashScope.Sdk.UnitTests.Utils; using Cnblogs.DashScope.Sdk.Wanx; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; using NSubstitute.Extensions; @@ -42,6 +42,27 @@ public async Task WanxImageSynthesis_UseEnum_SuccessAsync() && s.Parameters == Parameters)); } + [Fact] + public async Task WanxImageSynthesis_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + client.Configure().CreateImageSynthesisTaskAsync( + Arg.Any>(), + Arg.Any()) + .Returns(Snapshots.ImageSynthesis.CreateTask.ResponseModel); + + // Act + var act = async () => await client.CreateWanxImageSynthesisTaskAsync( + (WanxModel)(-1), + Cases.Prompt, + Cases.PromptAlter, + Parameters); + + // Assert + await Assert.ThrowsAsync(act); + } + [Fact] public async Task WanxImageSynthesis_CustomModel_SuccessAsync() { @@ -104,6 +125,25 @@ public async Task WanxImageGeneration_UseEnum_SuccessAsync() && s.Input.StyleIndex == 3)); } + [Fact] + public async Task WanxImageGeneration_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + client.Configure().CreateImageGenerationTaskAsync( + Arg.Any>(), + Arg.Any()) + .Returns(Snapshots.ImageGeneration.CreateTaskNoSse.ResponseModel); + + // Act + var act = async () => await client.CreateWanxImageGenerationTaskAsync( + (WanxStyleRepaintModel)(-1), + new ImageGenerationInput { ImageUrl = Cases.ImageUrl, StyleIndex = 3 }); + + // Assert + await Assert.ThrowsAsync(act); + } + [Fact] public async Task WanxImageGeneration_CustomModel_SuccessAsync() { @@ -162,6 +202,25 @@ public async Task WanxBackgroundImageGeneration_UseEnum_SuccessAsync() && s.Input.BaseImageUrl == Cases.ImageUrl)); } + [Fact] + public async Task WanxBackgroundImageGeneration_UseInvalidEnum_SuccessAsync() + { + // Arrange + var client = Substitute.For(); + client.Configure().CreateBackgroundGenerationTaskAsync( + Arg.Any>(), + Arg.Any()) + .Returns(Snapshots.BackgroundGeneration.CreateTaskNoSse.ResponseModel); + + // Act + var act = async () => await client.CreateWanxBackgroundGenerationTaskAsync( + (WanxBackgroundGenerationModel)(-1), + new BackgroundGenerationInput { BaseImageUrl = Cases.ImageUrl }); + + // Assert + await Assert.ThrowsAsync(act); + } + [Fact] public async Task WanxBackgroundImageGeneration_CustomModel_SuccessAsync() { diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/WorkspaceIdTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/WorkspaceIdTests.cs index c6b3a98..0c1b445 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/WorkspaceIdTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/WorkspaceIdTests.cs @@ -1,4 +1,4 @@ -using Cnblogs.DashScope.Sdk.UnitTests.Utils; +using Cnblogs.DashScope.Tests.Shared.Utils; using NSubstitute; namespace Cnblogs.DashScope.Sdk.UnitTests; diff --git a/test/Cnblogs.DashScope.Tests.Shared/Assembly.cs b/test/Cnblogs.DashScope.Tests.Shared/Assembly.cs new file mode 100644 index 0000000..7c8a352 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Assembly.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Cnblogs.DashScope.Sdk.UnitTests")] +[assembly: InternalsVisibleTo("Cnblogs.DashScope.AI.UnitTests")] diff --git a/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj new file mode 100644 index 0000000..0f05683 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + false + + + + + + + + + + + + + + + + Always + + + + diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-message-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-message-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-conversation-generation-session-id-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-conversation-generation-session-id-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-memory-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-memory-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-single-generation-text-with-thought-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-single-generation-text-with-thought-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/application-workflow-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/application-workflow-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/auth-error-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/auth-error-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/background-generation-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/background-generation-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/batch-text-embedding-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/batch-text-embedding-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/cancel-completed-task-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/cancel-completed-task-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-partial-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-partial-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/conversation-generation-message-with-files-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/conversation-generation-message-with-files-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/delete-file-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/delete-file-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-file-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-file-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.response.body.txt new file mode 100644 index 0000000..98e695b --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.response.body.txt @@ -0,0 +1 @@ +{"request_id":"8b22164d-c784-9a31-bda3-3c26259d4213","output":{"task_id":"b2e98d78-c79b-431c-b2d7-c7bcd54465da","task_status":"SUCCEEDED","submit_time":"2024-03-04 10:08:57.333","scheduled_time":"2024-03-04 10:08:57.363","end_time":"2024-03-04 10:09:07.727","text_results":{"urls":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_0_4645005c-713d-4e92-9629-b12cbe5f3671.png"},{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_1_b1979b75-c553-4d9b-9c9f-80f401a0d124.png"}],"params":[{"sample_idx":0,"layers":[{"color":"#521b08","top":0,"left":0,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#521b0800"},{"offset":1,"color":"#521b08ff"}],"gradient_units":"pixels","coords":{"y1":257,"x1":0,"y2":0,"x2":0}},"width":1024,"type":"text_mask","idx":0,"opacity":0.8,"radius":0,"height":257},{"font_weight":"Regular","font_size":67,"type":"text","content":"分享好时光","font_under_line":false,"line_height":1,"font_italic":false,"top":25,"sub_type":"Title","font_color":"#e6baa7","left":319,"text_stroke":"1px #fffffff0","width":385,"text_shadow":"1px 0px #80808080","font_family":"站酷文艺体","idx":1,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":77},{"color":"#e6baa7","top":118,"left":395,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#e6baa7ff"},{"offset":1,"color":"#e6baa7ff"}],"gradient_units":"pixels","coords":{"y1":0,"x1":0,"y2":50,"x2":0}},"width":233,"type":"text_mask","idx":2,"opacity":1,"radius":37,"box_shadow":"2px 1px #80808080","height":50},{"font_weight":"Medium","font_size":27,"type":"text","content":"只为不一样的你","font_under_line":false,"line_height":1,"font_italic":false,"top":118,"sub_type":"SubTitle","font_color":"#223629","left":395,"width":233,"text_shadow":0,"font_family":"阿里巴巴普惠体","idx":3,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":50}]},{"sample_idx":1,"layers":[{"color":"#efeae4","top":0,"left":0,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#efeae400"},{"offset":1,"color":"#efeae4ff"}],"gradient_units":"pixels","coords":{"y1":257,"x1":0,"y2":0,"x2":0}},"width":1024,"type":"text_mask","idx":0,"opacity":0.8,"radius":0,"height":257},{"font_weight":"Regular","font_size":67,"type":"text","content":"分享好时光","font_under_line":false,"line_height":1,"font_italic":false,"top":25,"sub_type":"Title","font_color":"#421f12","left":319,"text_stroke":"1px #fffffff0","width":385,"text_shadow":"0px 2px #80808080","font_family":"钉钉进步体","idx":1,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":77},{"color":"#421f12","top":118,"left":395,"gradient":{"type":"linear","color_stops":[{"offset":0,"color":"#421f12ff"},{"offset":1,"color":"#421f12ff"}],"gradient_units":"pixels","coords":{"y1":0,"x1":0,"y2":50,"x2":0}},"width":233,"type":"text_mask","idx":2,"opacity":1,"radius":37,"box_shadow":"0px 0px #80808080","height":50},{"font_weight":"Regular","font_size":27,"type":"text","content":"只为不一样的你","font_under_line":false,"line_height":1,"font_italic":false,"top":118,"sub_type":"SubTitle","font_color":"#f1eeec","left":395,"width":233,"text_shadow":0,"font_family":"阿里巴巴普惠体","idx":3,"alignment":"center","opacity":1,"font_line_through":false,"direction":"horizontal","height":50}]}]},"results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_0_02dc0bba-8b1d-4648-8b95-eb2b92fe715d.png"},{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_1_e1af86ec-152a-4ebe-b2a0-b40a592043b2.png"}],"task_metrics":{"TOTAL":2,"SUCCEEDED":2,"FAILED":0}},"usage":{"image_count":2}} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-background-generation-success-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-background-generation-success-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-batch-text-embedding-success-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-batch-text-embedding-success-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.response.body.txt similarity index 77% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.response.body.txt index 1cbff88..55681d4 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.response.body.txt +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.response.body.txt @@ -1 +1 @@ -{"request_id":"f927c766-5079-90f8-9354-6a87d2167897","output":{"task_id":"c4f94e00-5899-431b-9579-eb1ebe686379","task_status":"SUCCEEDED","submit_time":"2024-03-02 22:22:13.026","scheduled_time":"2024-03-02 22:22:13.051","end_time":"2024-03-02 22:22:21","error_message":"Success","start_time":"2024-03-02 22:22:13","style_index":3,"error_code":0,"results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/viapi-video/2024-03-02/ac5d435a-9ea9-4287-8666-e1be7bbba943/20240302222213528791_style3_jxdf6o4zwy.jpg?Expires=1709475741&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=LM26fy1Pk8rCfPzihzpUqa3Vst8%3D"}]},"usage":{"image_count":1}} +{"request_id":"f927c766-5079-90f8-9354-6a87d2167897","output":{"task_id":"c4f94e00-5899-431b-9579-eb1ebe686379","task_status":"SUCCEEDED","submit_time":"2024-03-02 22:22:13.026","scheduled_time":"2024-03-02 22:22:13.051","end_time":"2024-03-02 22:22:21","error_message":"Success","start_time":"2024-03-02 22:22:13","style_index":3,"error_code":0,"results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/viapi-video/2024-03-02/ac5d435a-9ea9-4287-8666-e1be7bbba943/20240302222213528791_style3_jxdf6o4zwy.jpg"}]},"usage":{"image_count":1}} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-generation-success-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-generation-success-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt new file mode 100644 index 0000000..f9ffba2 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.response.body.txt @@ -0,0 +1 @@ +{"request_id":"6662e925-4846-9afe-a3af-0d131805d378","output":{"task_id":"9e2b6ef6-285d-4efa-8651-4dbda7d571fa","task_status":"SUCCEEDED","submit_time":"2024-03-01 17:38:24.817","scheduled_time":"2024-03-01 17:38:24.831","end_time":"2024-03-01 17:38:55.565","results":[{"url":"https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/d4/20240301/8d820c8d/4c48fa53-2907-499b-b9ac-76477fe8d299-1.png"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/79/20240301/3ab595ad/aa3e6d8d-884d-4431-b9c2-3684edeb072e-1.png"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/79/20240301/3ab595ad/aa3e6d8d-884d-4431-b9c2-3684edeb072e-1.png"},{"url":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/3d/20240301/3ab595ad/3fca748e-d491-458a-bb72-73649af33209-1.png"}],"task_metrics":{"TOTAL":4,"SUCCEEDED":4,"FAILED":0}},"usage":{"image_count":4}} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-image-synthesis-success-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-image-synthesis-success-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-running-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-running-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/get-task-unknown-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/get-task-unknown-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-generation-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-generation-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/image-synthesis-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/image-synthesis-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-files-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-files-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/list-task-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/list-task-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-audio-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-audio-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-ocr-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-ocr-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/multimodal-generation-vl-video-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/multimodal-generation-vl-video-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/parameter-error-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/parameter-error-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-json-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-json-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.body.json new file mode 100644 index 0000000..b47b634 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.body.json @@ -0,0 +1,22 @@ +{ + "model": "qwen-max", + "input": { + "messages": [ + { + "role": "user", + "content": "请问 1+1 是多少?请直接输出结果" + } + ] + }, + "parameters": { + "result_format": "message", + "seed": 1234, + "max_tokens": 1500, + "top_p": 0.8, + "top_k": 100, + "repetition_penalty": 1.1, + "temperature": 0.85, + "logprobs": true, + "top_logprobs": 2 + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.header.txt new file mode 100644 index 0000000..0c616aa --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.request.header.txt @@ -0,0 +1,8 @@ +POST /api/v1/services/aigc/text-generation/generation HTTP/1.1 +Content-Type: application/json +Accept: */* +Cache-Control: no-cache +Host: dashscope.aliyuncs.com +Accept-Encoding: gzip, deflate, br +Connection: keep-alive +Content-Length: 592 diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.body.txt new file mode 100644 index 0000000..57dfbe9 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.body.txt @@ -0,0 +1 @@ +{"output":{"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":"2"},"logprobs":{"content":[{"top_logprobs":[{"logprob":0.0,"bytes":[50],"token":"2"}],"logprob":0.0,"bytes":[50],"token":"2"}]}}]},"usage":{"total_tokens":21,"output_tokens":1,"input_tokens":20,"prompt_tokens_details":{"cached_tokens":0}},"request_id":"1d881da5-0028-9f20-8e7f-6bc7ae891c54"} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.header.txt new file mode 100644 index 0000000..2799d49 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-logprobs-nosse.response.header.txt @@ -0,0 +1,15 @@ +HTTP/1.1 200 OK +vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding +content-type: application/json +x-request-id: 1d881da5-0028-9f20-8e7f-6bc7ae891c54 +x-dashscope-call-gateway: true +x-dashscope-finished: true +x-dashscope-timeout: 298 +req-cost-time: 261 +req-arrive-time: 1751901115333 +resp-start-time: 1751901115594 +x-envoy-upstream-service-time: 252 +content-encoding: gzip +date: Mon, 07 Jul 2025 15:11:55 GMT +server: istio-envoy +transfer-encoding: chunked diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.request.body.json similarity index 73% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.request.body.json index 1d17aaa..079da7b 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.request.body.json +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.request.body.json @@ -9,6 +9,7 @@ ] }, "parameters": { - "incremental_output": false + "incremental_output": false, + "result_format": "message" } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.request.body.json similarity index 50% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.request.body.json index 9e514e1..d44fefe 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.request.body.json +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.request.body.json @@ -1,5 +1,5 @@ { - "model": "deepseek-r1", + "model": "qwen-plus-latest", "input": { "messages": [ { @@ -9,6 +9,9 @@ ] }, "parameters": { - "incremental_output": true + "result_format": "message", + "incremental_output": true, + "enable_thinking": true, + "thinking_budget": 10 } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.body.txt new file mode 100644 index 0000000..5e0bcd0 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.body.txt @@ -0,0 +1,65 @@ + +id:1 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"嗯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":19,"output_tokens":3,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":1}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:2 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":20,"output_tokens":4,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":2}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:3 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":21,"output_tokens":5,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":3}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:4 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问的是“1","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":25,"output_tokens":9,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":7}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:5 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"+1是多少","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":31,"output_tokens":15,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:6 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"1+1","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":35,"output_tokens":19,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:7 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":" 等于 **","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":39,"output_tokens":23,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:8 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"2**。这是","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":43,"output_tokens":27,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:9 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"数学中最基本的","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":47,"output_tokens":31,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:10 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"加法运算之一","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":51,"output_tokens":35,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:11 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"。\n\n如果你有其他","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":55,"output_tokens":39,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:12 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"关于数学、科学","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":59,"output_tokens":43,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:13 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"或任何领域的问题","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":63,"output_tokens":47,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:14 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":",欢迎继续提问","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":67,"output_tokens":51,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:15 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"!😊","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":69,"output_tokens":53,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} +id:16 +event:result +:HTTP_STATUS/200 +data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":69,"output_tokens":53,"input_tokens":16,"output_tokens_details":{"reasoning_tokens":10}},"request_id":"ab9f3446-9bbf-963e-9754-2d6543343d7e"} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.header.txt similarity index 56% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.header.txt index 668bf11..6cec27f 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-reasoning-sse.response.header.txt +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-reasoning-sse.response.header.txt @@ -1,14 +1,14 @@ HTTP/1.1 200 OK vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers -x-request-id: e4ad5d0f-8019-9716-adc6-eae1411d3c9a +x-request-id: d21851a2-675b-97a3-9132-2935c31d6ee3 content-type: text/event-stream;charset=UTF-8 x-dashscope-call-gateway: true x-dashscope-timeout: 180 x-dashscope-finished: false -req-cost-time: 500 -req-arrive-time: 1742405632039 -resp-start-time: 1742405632540 -x-envoy-upstream-service-time: 490 -date: Wed, 19 Mar 2025 17:33:52 GMT +req-cost-time: 482 +req-arrive-time: 1749445556927 +resp-start-time: 1749445557410 +x-envoy-upstream-service-time: 474 +date: Mon, 09 Jun 2025 05:05:57 GMT server: istio-envoy transfer-encoding: chunked diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.body.json new file mode 100644 index 0000000..7a30117 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.body.json @@ -0,0 +1,22 @@ +{ + "model": "qwen-max", + "input": { + "messages": [ + { + "role": "user", + "content": "总结博客园 dudu 的最新博客" + } + ] + }, + "parameters": { + "result_format": "message", + "enable_search": true, + "search_options": { + "enable_source": true, + "enable_citation": true, + "citation_format": "[ref_]", + "forced_search": true, + "search_strategy": "standard" + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.header.txt new file mode 100644 index 0000000..8f77480 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.request.header.txt @@ -0,0 +1,8 @@ +POST /api/v1/services/aigc/text-generation/generation HTTP/1.1 +Content-Type: application/json +Accept: */* +Cache-Control: no-cache +Host: dashscope.aliyuncs.com +Accept-Encoding: gzip, deflate, br +Connection: keep-alive +Content-Length: 592 diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.body.txt new file mode 100644 index 0000000..ed84299 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.body.txt @@ -0,0 +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"} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.header.txt new file mode 100644 index 0000000..8349277 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-search-nosse.response.header.txt @@ -0,0 +1,15 @@ +HTTP/1.1 200 OK +vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding +content-type: application/json +x-request-id: 405d57ba-6cfc-9519-977f-0f519f712364 +x-dashscope-call-gateway: true +x-dashscope-finished: true +x-dashscope-timeout: 298 +req-cost-time: 810 +req-arrive-time: 1751899675324 +resp-start-time: 1751899676135 +x-envoy-upstream-service-time: 802 +content-encoding: gzip +date: Mon, 07 Jul 2025 14:47:55 GMT +server: istio-envoy +transfer-encoding: chunked diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.body.json new file mode 100644 index 0000000..f4ea34c --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.body.json @@ -0,0 +1,32 @@ +{ + "model": "qwen-mt-plus", + "input": { + "messages": [ + { + "role": "user", + "content": "博客园的理念是代码改变世界" + } + ] + }, + "parameters": { + "result_format": "message", + "incremental_output": false, + "translation_options": { + "source_lang": "Chinese", + "target_lang": "English", + "terms": [ + { + "source": "博客园", + "target": "cnblogs" + } + ], + "tm_list": [ + { + "source": "代码改变世界", + "target": "Coding changes world" + } + ], + "domains": "This text is a promotion." + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.header.txt new file mode 100644 index 0000000..28fb683 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.request.header.txt @@ -0,0 +1,8 @@ +POST /api/v1/services/aigc/text-generation/generation HTTP/1.1 +Content-Type: application/json +Accept: */* +Cache-Control: no-cache +Host: dashscope.aliyuncs.com +Accept-Encoding: gzip, deflate, br +Connection: keep-alive +Content-Length: 85 diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.body.txt new file mode 100644 index 0000000..10105ce --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.body.txt @@ -0,0 +1 @@ +{"output":{"finish_reason":"stop","model_name":"qwen-mt-plus","choices":[{"finish_reason":"stop","message":{"role":"assistant","content":"The concept of cnblogs is that coding changes world "}}]},"usage":{"total_tokens":122,"output_tokens":11,"input_tokens":111},"request_id":"bf86e0f9-a8a2-9b32-be8d-ea3cae47c8ea"} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.header.txt new file mode 100644 index 0000000..7fd842a --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-translation-nosse.response.header.txt @@ -0,0 +1,15 @@ +HTTP/1.1 200 OK +vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding +content-type: application/json +x-request-id: bf86e0f9-a8a2-9b32-be8d-ea3cae47c8ea +x-dashscope-call-gateway: true +x-dashscope-finished: true +x-dashscope-timeout: 180 +req-cost-time: 823 +req-arrive-time: 1751904150645 +resp-start-time: 1751904151468 +x-envoy-upstream-service-time: 812 +content-encoding: gzip +date: Mon, 07 Jul 2025 16:02:30 GMT +server: istio-envoy +transfer-encoding: chunked diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.request.body.json similarity index 85% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.request.body.json index 67f0342..7e41d14 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.request.body.json +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.request.body.json @@ -32,13 +32,6 @@ "location": { "type": "string", "description": "要获取天气的省市名称,例如浙江省杭州市" - }, - "unit": { - "description": "温度单位", - "enum": [ - "Celsius", - "Fahrenheit" - ] } }, "required": [ diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-message-with-tools-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-message-with-tools-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/single-generation-text-sse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/single-generation-text-sse.response.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.continue-task.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.continue-task.json new file mode 100644 index 0000000..20ed15f --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.continue-task.json @@ -0,0 +1,11 @@ +{ + "header": { + "action": "continue-task", + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c" + }, + "payload": { + "input": { + "text": "代码改变世界" + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.finish-task.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.finish-task.json new file mode 100644 index 0000000..2efb69a --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.finish-task.json @@ -0,0 +1,9 @@ +{ + "header": { + "action": "finish-task", + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c" + }, + "payload": { + "input": {} + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.result-generated.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.result-generated.json new file mode 100644 index 0000000..c3111db --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.result-generated.json @@ -0,0 +1,17 @@ +{ + "header": { + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c", + "event": "result-generated", + "attributes": { + "request_uuid": "c88301b4-3caa-4f15-94e2-246e84d2e648", + "x-ds-batch-queue-length": "0" + } + }, + "payload": { + "output": { + "sentence": { + "words": [] + } + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.run-task.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.run-task.json new file mode 100644 index 0000000..482a599 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.run-task.json @@ -0,0 +1,24 @@ +{ + "header": { + "action": "run-task", + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c", + "streaming": "duplex" + }, + "payload": { + "model": "cosyvoice-v1", + "task_group": "audio", + "task": "tts", + "function": "SpeechSynthesizer", + "input": {}, + "parameters": { + "voice": "longxiaochun", + "volume": 50, + "text_type": "PlainText", + "sample_rate": 0, + "rate": 1.1, + "format": "mp3", + "pitch": 1.2, + "enable_ssml": true + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-failed.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-failed.json new file mode 100644 index 0000000..27aff61 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-failed.json @@ -0,0 +1,10 @@ +{ + "header": { + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c", + "event": "task-failed", + "error_code": "InvalidParameter", + "error_message": "[tts:]Engine return error code: 418", + "attributes": {} + }, + "payload": {} +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-finished.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-finished.json new file mode 100644 index 0000000..e48f75a --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-finished.json @@ -0,0 +1,20 @@ +{ + "header": { + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c", + "event": "task-finished", + "attributes": { + "request_uuid": "c88301b4-3caa-4f15-94e2-246e84d2e648", + "x-ds-batch-queue-length": "0" + } + }, + "payload": { + "output": { + "sentence": { + "words": [] + } + }, + "usage": { + "characters": 12 + } + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-started.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-started.json new file mode 100644 index 0000000..ebcddee --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/socket-speech-synthesizer.task-started.json @@ -0,0 +1,8 @@ +{ + "header": { + "task_id": "439e0616-2f5b-44e0-8872-0002a066a49c", + "event": "task-started", + "attributes": {} + }, + "payload": {} +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/test1.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/test1.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/test1.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/test1.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/test2.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/test2.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/test2.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/test2.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/text-embedding-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/text-embedding-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.request.body.json b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.request.body.json similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.request.body.json rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.request.body.json diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/tokenization-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tokenization-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tts.mp3 b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tts.mp3 new file mode 100644 index 0000000..6d32a1b Binary files /dev/null and b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/tts.mp3 differ diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-error-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-error-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.request.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.request.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.request.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.request.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.response.body.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.response.body.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.response.body.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.response.body.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.response.header.txt b/test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.response.header.txt similarity index 100% rename from test/Cnblogs.DashScope.Sdk.UnitTests/RawHttpData/upload-file-nosse.response.header.txt rename to test/Cnblogs.DashScope.Tests.Shared/RawHttpData/upload-file-nosse.response.header.txt diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Cases.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Cases.cs similarity index 69% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Cases.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Cases.cs index 79daec6..88cef2f 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Cases.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Cases.cs @@ -1,8 +1,8 @@ using Cnblogs.DashScope.Core; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; -internal class Cases +public class Cases { public const string CustomModelName = "custom-model"; public const string Prompt = "hello"; @@ -11,5 +11,5 @@ internal class Cases public const string ImageUrl = "https://www.cnblogs.com/image.png"; public static readonly List TextMessages = - [TextChatMessage.System("you are a helpful assistant"), TextChatMessage.User("hello")]; + new() { TextChatMessage.System("you are a helpful assistant"), TextChatMessage.User("hello") }; } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Checkers.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Checkers.cs similarity index 70% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Checkers.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Checkers.cs index c7b6e36..df574e7 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Checkers.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Checkers.cs @@ -1,9 +1,16 @@ using System.Text.Json.Nodes; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public static class Checkers { + public static bool IsJsonEquivalent(ArraySegment socketBuffer, string requestSnapshot) + { + var actual = JsonNode.Parse(socketBuffer); + var expected = JsonNode.Parse(requestSnapshot); + return JsonNode.DeepEquals(actual, expected); + } + public static bool IsJsonEquivalent(HttpContent content, string requestSnapshot) { #pragma warning disable VSTHRD002 diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/EquivalentUtils.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/EquivalentUtils.cs new file mode 100644 index 0000000..d64ead5 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/EquivalentUtils.cs @@ -0,0 +1,20 @@ +using Xunit; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public static class EquivalentUtils +{ + public static bool IsEquivalent(this T left, T right) + { + try + { + Assert.Equivalent(right, left); + } + catch (Exception) + { + return false; + } + + return true; + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/FakeClientWebSocket.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/FakeClientWebSocket.cs new file mode 100644 index 0000000..1c73930 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/FakeClientWebSocket.cs @@ -0,0 +1,129 @@ +using System.Net.WebSockets; +using System.Text; +using System.Threading.Channels; +using Cnblogs.DashScope.Core.Internals; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public sealed class FakeClientWebSocket : IClientWebSocket +{ + public List> ServerReceivedMessages { get; } = new(); + + public Channel Server { get; } = + Channel.CreateUnbounded(); + + public Channel ServerBuffer { get; } = Channel.CreateUnbounded(); + + public Queue> Playlist { get; } = new(); + + public bool DisposeCalled { get; private set; } + + public async Task WriteServerCloseAsync() + { + var close = new WebSocketReceiveResult(1, WebSocketMessageType.Close, true); + await Server.Writer.WriteAsync(close); + await Server.Reader.WaitToReadAsync(); + await Task.Delay(50); + } + + public async Task WriteServerMessageAsync(string json) + { + var binary = Encoding.UTF8.GetBytes(json); + await Server.Writer.WriteAsync(new WebSocketReceiveResult(binary.Length, WebSocketMessageType.Text, true)); + + await ServerBuffer.Writer.WriteAsync(binary); + await Server.Reader.WaitToReadAsync(); + await ServerBuffer.Reader.WaitToReadAsync(); + await Task.Delay(50); + } + + public async Task WriteServerMessageAsync(byte[] binary) + { + await Server.Writer.WriteAsync(new WebSocketReceiveResult(binary.Length, WebSocketMessageType.Binary, true)); + + await ServerBuffer.Writer.WriteAsync(binary); + await Server.Reader.WaitToReadAsync(); + await ServerBuffer.Reader.WaitToReadAsync(); + await Task.Delay(50); + } + + private void Dispose(bool disposing) + { + // nothing to release. + if (disposing) + { + DisposeCalled = true; + Server.Writer.TryComplete(); + ServerBuffer.Writer.TryComplete(); + } + } + + /// + public void Dispose() + { + Dispose(true); + } + + /// + public ClientWebSocketOptions Options { get; set; } = null!; + + /// + public WebSocketCloseStatus? CloseStatus { get; set; } + + /// + public Task ConnectAsync(Uri uri, CancellationToken cancellation) + { + // do nothing. + return Task.CompletedTask; + } + + /// + public async Task SendAsync( + ArraySegment buffer, + WebSocketMessageType messageType, + bool endOfMessage, + CancellationToken cancellationToken) + { + ServerReceivedMessages.Add(buffer); + if (Playlist.Count > 0) + { + await Playlist.Dequeue().Invoke(this); + } + } + + /// + public async Task ReceiveAsync( + ArraySegment buffer, + CancellationToken cancellationToken) + { + var timeout = Task.Delay(1000, cancellationToken); + var jsonTask = Server.Reader.WaitToReadAsync(cancellationToken).AsTask(); + var binaryTask = ServerBuffer.Reader.WaitToReadAsync(cancellationToken); + var finishedTask = await Task.WhenAny(jsonTask, timeout); + if (finishedTask == timeout) + { + throw new TimeoutException("waiting for next socket message timeouts"); + } + + if (binaryTask.IsCompleted) + { + var binary = await ServerBuffer.Reader.ReadAsync(cancellationToken); + for (var i = 0; i < binary.Length; i++) + { + buffer[i] = binary[i]; + } + } + + return await Server.Reader.ReadAsync(cancellationToken); + } + + /// + public Task CloseAsync( + WebSocketCloseStatus closeStatus, + string? statusDescription, + CancellationToken cancellationToken) + { + CloseStatus = WebSocketCloseStatus.NormalClosure; + return Task.CompletedTask; + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/GetCurrentWeatherParameters.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/GetCurrentWeatherParameters.cs new file mode 100644 index 0000000..91f7524 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/GetCurrentWeatherParameters.cs @@ -0,0 +1,10 @@ +using Json.Schema.Generation; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public class GetCurrentWeatherParameters +{ + [Required] + [Description("要获取天气的省市名称,例如浙江省杭州市")] + public string Location { get; init; } = string.Empty; +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/MockHttpMessageHandler.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/MockHttpMessageHandler.cs similarity index 93% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/MockHttpMessageHandler.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/MockHttpMessageHandler.cs index 1aa1b78..bf8de9d 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/MockHttpMessageHandler.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/MockHttpMessageHandler.cs @@ -1,4 +1,4 @@ -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public class MockHttpMessageHandler : HttpMessageHandler { diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/RequestSnapshot.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/RequestSnapshot.cs similarity index 96% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/RequestSnapshot.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/RequestSnapshot.cs index 17596ff..4c01bc1 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/RequestSnapshot.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/RequestSnapshot.cs @@ -1,7 +1,7 @@ using System.Net; using System.Text; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public record RequestSnapshot(string Name, TResponse ResponseModel) { diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Application.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Application.cs similarity index 91% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Application.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Application.cs index 59cfe01..fc467e9 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Application.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Application.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public static partial class Snapshots { @@ -9,19 +9,19 @@ public static class Application public static readonly RequestSnapshot SinglePromptNoSse = new( "application-single-generation-text", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() { Prompt = "总结xUnit Test Patterns中的内容" }, - Parameters = new ApplicationParameters() + Input = new ApplicationInput { Prompt = "总结xUnit Test Patterns中的内容" }, + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, Seed = 1234, Temperature = 0.85f, - RagOptions = new ApplicationRagOptions() + RagOptions = new ApplicationRagOptions { - PipelineIds = ["thie5bysoj"], - FileIds = ["file_d129d632800c45aa9e7421b30561f447_10207234"] + PipelineIds = new List { "thie5bysoj" }.AsReadOnly(), + FileIds = new List { "file_d129d632800c45aa9e7421b30561f447_10207234" }.AsReadOnly() } } }, @@ -31,8 +31,9 @@ public static class Application "xUnit Test Patterns 提供了一套全面的指南,用于改进测试自动化和重构测试代码。以下是根据提供的文档内容总结的关键点:\n\n1. 测试自动化的目标包括帮助提高产品质量、帮助我们理解被测系统(SUT)、减少(并且不引入)风险、易于运行、编写和维护[4]。\n2. 在管理共享fixture方面,文档讨论了访问共享fixture以及触发共享fixture构造的方法[2]。\n3. 关于结果验证,文档提供了自我检查测试的方法,验证状态或行为,使用内置断言进行状态验证,以及验证直接输出和替代路径[2]。\n4. 当涉及到数据库时,文档提到了与数据库相关的测试问题、没有数据库的测试、数据库测试、存储过程测试、数据访问层测试,并强调确保开发者独立性[3]。\n5. 文档还涵盖了测试方法组织策略、测试命名约定、测试套件组织、运行测试组或单个测试、测试代码重用、测试文件组织等内容[5]。\n\n这些模式和实践旨在解决测试中的常见问题,如高测试维护成本、不可测试代码最小化、防止生产代码中的错误测试等[1]。通过应用这些模式,开发者可以创建更高效、更易于维护的自动化测试。", "stop", "b7250cba47db463ca851dfb4088e71d8", - [ - new ApplicationOutputThought( + new List + { + new( null, "agentRag", "知识检索", @@ -42,7 +43,7 @@ public static class Application "[{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:Visual Summary of the Pattern Language\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Minimize Untestable Code Buggy Tests Production Bugs Keep Test Logic Out of Production Developers Not Writing Tests Ensure Commensurate Effort and Responsibility High Test Maintenance CostKey to Visual Summary of the Pattern Language Chapter Name Chapter Name Sub-Category, Altemative Pattern Smell Pattern 1Pattern 2from Other Chapter'Cause of Smell Sub-Category variation, of Altemative Pattem十Pattem 1Smell Variation of Pattern used with Pattern leads toi Smell Variation described each other Alternative Pattem 2separatelyVISUAL SUMMARY OF THE PATTERN LANGUAGE\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_1_3\",\"images\":[\"http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742655907&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=89B%2FoauA6i4g34LikZ06Z0PUHY4%3D&x-oss-process=image%2Fcrop%2Cx_232%2Cy_610%2Cw_964%2Ch_648\",\"http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742655907&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=3VwzeegSrkzfQIcMDz2F3C2bTdg%3D&x-oss-process=image%2Fcrop%2Cx_227%2Cy_1305%2Cw_991%2Ch_302\"],\"referenceIndex\":1,\"score\":0.5756075978279114,\"title\":\"Visual Summary of the Pattern Language\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Managing Shared Fixtures...103Accessing Shared Fixtures...103Triggering Shared Fixture Construction...104What's Next?...106Chapter 10. Result Verification...107About This Chapter ...107Making Tests Self-Checking...107Verify State or Behavior?...108State Verification...109Using Built-in Assertions ...110Delta Assertions...111External Result Verification ...111Verifying Behavior...112Procedural Behavior Verification...113Expected Behavior Specification . . ...113CONTENTSReducing Test Code Duplication...114Expected Objects...115Custom Assertions...116Outcome-Describing Verification Method ...117\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_33\",\"images\":[],\"referenceIndex\":2,\"score\":0.5756075978279114,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:?...168Issues with Databases...168Testing without Databases...169Testing the Database...171Testing Stored Procedures...172Testing the Data Access Layer...172Ensuring Developer Independence...173Testing with Databases (Again!)...173What's Next? ...174Chapter 14. A Roadmap to Effective Test Automation ...175About This Chapter...175Test Automation Difficulty .. ...175Roadmap to Highly Maintainable Automated Tests...176Exercise the Happy Path Code ...177Verify Direct Outputs of the Happy Path...178CONTENTSVerify Alternative Paths...178Verify Indirect Output Behavior...179\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_37\",\"images\":[],\"referenceIndex\":3,\"score\":0.5697553753852844,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:?..17viiiCONTENTSChapter 3. Goals of Test Automation ...19About This Chapter...19Why Test?...19Economics of Test Automation20Goals of Test Automation...21Tests Should Help Us Improve Quality...22Tests Should Help Us Understand the SUT. . ...23Tests Should Reduce (and Not Introduce) Risk...23Tests Should Be Easy to Run ...25Tests Should Be Easy to Write and Maintain ...27Tests Should Require Minimal Maintenance asthe System Evolves Around Them ...29What's Next? .29Chapter 4. Philosophy of Test Automation ...31About This Chapter...31Why Is Philosophy Important?...31\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_28\",\"images\":[],\"referenceIndex\":4,\"score\":0.5639580488204956,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Testcase Class per Class... ...155Testcase Class per Feature. ...156Testcase Class per Fixture...156Choosing a Test Method Organization Strategy...158Test Naming Conventions...158Organizing Test Suites.. . ...160Running Groups of Tests ...160Running a Single Test...161Test Code Reuse...162Test Utility Method Locations ...163TestCase Inheritance and Reuse...163Test File Organization...164Built-in Self-Test...164Test Packages. ...164Test Dependencies ...165What's Next? ...165Chapter 13. Testing with Databases...167About This Chapter...167Testing with Databases...167Why Test with Databases?...168\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_36\",\"images\":[],\"referenceIndex\":5,\"score\":0.563438355922699,\"title\":\"xUnit Test Patterns\",\"webSearch\":false}]", null, "{}"), - new ApplicationOutputThought( + new( null, "api", "长期记忆检索", @@ -52,68 +53,76 @@ public static class Application "[]", null, "{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"总结xUnit Test Patterns中的内容\"}") - ], - [ - new ApplicationDocReference( + }, + new List + { + new( "1", "Visual Summary of the Pattern Language", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:Visual Summary of the Pattern Language\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:Minimize Untestable Code Buggy Tests Production Bugs Keep Test Logic Out of Production Developers Not Writing Tests Ensure Commensurate Effort and Responsibility High Test Maintenance CostKey to Visual Summary of the Pattern Language Chapter Name Chapter Name Sub-Category, Altemative Pattern Smell Pattern 1Pattern 2from Other Chapter'Cause of Smell Sub-Category variation, of Altemative Pattem十Pattem 1Smell Variation of Pattern used with Pattern leads toi Smell Variation described each other Alternative Pattem 2separatelyVISUAL SUMMARY OF THE PATTERN LANGUAGE\n", - [ + new List + { "http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742655907&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=89B%2FoauA6i4g34LikZ06Z0PUHY4%3D&x-oss-process=image%2Fcrop%2Cx_232%2Cy_610%2Cw_964%2Ch_648", "http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742655907&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=3VwzeegSrkzfQIcMDz2F3C2bTdg%3D&x-oss-process=image%2Fcrop%2Cx_227%2Cy_1305%2Cw_991%2Ch_302" - ], + }, null), - new ApplicationDocReference( + new( "2", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:Managing Shared Fixtures...103Accessing Shared Fixtures...103Triggering Shared Fixture Construction...104What's Next?...106Chapter 10. Result Verification...107About This Chapter ...107Making Tests Self-Checking...107Verify State or Behavior?...108State Verification...109Using Built-in Assertions ...110Delta Assertions...111External Result Verification ...111Verifying Behavior...112Procedural Behavior Verification...113Expected Behavior Specification . . ...113CONTENTSReducing Test Code Duplication...114Expected Objects...115Custom Assertions...116Outcome-Describing Verification Method ...117\n", - [], + new List(), null), - new ApplicationDocReference( + new( "3", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:?...168Issues with Databases...168Testing without Databases...169Testing the Database...171Testing Stored Procedures...172Testing the Data Access Layer...172Ensuring Developer Independence...173Testing with Databases (Again!)...173What's Next? ...174Chapter 14. A Roadmap to Effective Test Automation ...175About This Chapter...175Test Automation Difficulty .. ...175Roadmap to Highly Maintainable Automated Tests...176Exercise the Happy Path Code ...177Verify Direct Outputs of the Happy Path...178CONTENTSVerify Alternative Paths...178Verify Indirect Output Behavior...179\n", - [], + new List(), null), - new ApplicationDocReference( + new( "4", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:?..17viiiCONTENTSChapter 3. Goals of Test Automation ...19About This Chapter...19Why Test?...19Economics of Test Automation20Goals of Test Automation...21Tests Should Help Us Improve Quality...22Tests Should Help Us Understand the SUT. . ...23Tests Should Reduce (and Not Introduce) Risk...23Tests Should Be Easy to Run ...25Tests Should Be Easy to Write and Maintain ...27Tests Should Require Minimal Maintenance asthe System Evolves Around Them ...29What's Next? .29Chapter 4. Philosophy of Test Automation ...31About This Chapter...31Why Is Philosophy Important?...31\n", - [], + new List(), null), - new ApplicationDocReference( + new( "5", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:Testcase Class per Class... ...155Testcase Class per Feature. ...156Testcase Class per Fixture...156Choosing a Test Method Organization Strategy...158Test Naming Conventions...158Organizing Test Suites.. . ...160Running Groups of Tests ...160Running a Single Test...161Test Code Reuse...162Test Utility Method Locations ...163TestCase Inheritance and Reuse...163Test File Organization...164Built-in Self-Test...164Test Packages. ...164Test Dependencies ...165What's Next? ...165Chapter 13. Testing with Databases...167About This Chapter...167Testing with Databases...167Why Test with Databases?...168\n", - [], + new List(), null) - ]), - new ApplicationUsage([new ApplicationModelUsage("qwen-plus", 2591, 290)]))); + }), + new ApplicationUsage( + new List { new("qwen-plus", 2591, 290) }))); public static readonly RequestSnapshot SinglePromptSse = new( "application-single-generation-text", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() { Prompt = "总结xUnit Test Patterns中的内容" }, - Parameters = new ApplicationParameters() + Input = new ApplicationInput { Prompt = "总结xUnit Test Patterns中的内容" }, + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, Seed = 1234, Temperature = 0.85f, IncrementalOutput = true, - RagOptions = new ApplicationRagOptions() { PipelineIds = ["thie5bysoj"], Tags = ["xUnit"] } + RagOptions = new ApplicationRagOptions + { + PipelineIds = + new List { "thie5bysoj" }.AsReadOnly(), Tags = + new List { "xUnit" }.AsReadOnly() + } } }, new ApplicationResponse( @@ -123,58 +132,60 @@ public static class Application "stop", "069db8223d514dab91185954dc5108de", null, - [ - new ApplicationDocReference( + new List + { + new( "2", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:Managing Shared Fixtures...103Accessing Shared Fixtures...103Triggering Shared Fixture Construction...104What's Next?...106Chapter 10. Result Verification...107About This Chapter ...107Making Tests Self-Checking...107Verify State or Behavior?...108State Verification...109Using Built-in Assertions ...110Delta Assertions...111External Result Verification ...111Verifying Behavior...112Procedural Behavior Verification...113Expected Behavior Specification . . ...113CONTENTSReducing Test Code Duplication...114Expected Objects...115Custom Assertions...116Outcome-Describing Verification Method ...117\n", - [], + new List(), null), - new ApplicationDocReference( + new( "3", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:?...168Issues with Databases...168Testing without Databases...169Testing the Database...171Testing Stored Procedures...172Testing the Data Access Layer...172Ensuring Developer Independence...173Testing with Databases (Again!)...173What's Next? ...174Chapter 14. A Roadmap to Effective Test Automation ...175About This Chapter...175Test Automation Difficulty .. ...175Roadmap to Highly Maintainable Automated Tests...176Exercise the Happy Path Code ...177Verify Direct Outputs of the Happy Path...178CONTENTSVerify Alternative Paths...178Verify Indirect Output Behavior...179\n", - [], + new List(), null), - new ApplicationDocReference( + new( "4", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:?..17viiiCONTENTSChapter 3. Goals of Test Automation ...19About This Chapter...19Why Test?...19Economics of Test Automation20Goals of Test Automation...21Tests Should Help Us Improve Quality...22Tests Should Help Us Understand the SUT. . ...23Tests Should Reduce (and Not Introduce) Risk...23Tests Should Be Easy to Run ...25Tests Should Be Easy to Write and Maintain ...27Tests Should Require Minimal Maintenance asthe System Evolves Around Them ...29What's Next? .29Chapter 4. Philosophy of Test Automation ...31About This Chapter...31Why Is Philosophy Important?...31\n", - [], + new List(), null), - new ApplicationDocReference( + new( "5", "xUnit Test Patterns", "file_d129d632800c45aa9e7421b30561f447_10207234", "xUnit Test Patterns", "【文档名】:xUnit Test Patterns\n【标题】:xUnit Test Patterns\n文档类型:[\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\",\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\"]\n【正文】:Testcase Class per Class... ...155Testcase Class per Feature. ...156Testcase Class per Fixture...156Choosing a Test Method Organization Strategy...158Test Naming Conventions...158Organizing Test Suites.. . ...160Running Groups of Tests ...160Running a Single Test...161Test Code Reuse...162Test Utility Method Locations ...163TestCase Inheritance and Reuse...163Test File Organization...164Built-in Self-Test...164Test Packages. ...164Test Dependencies ...165What's Next? ...165Chapter 13. Testing with Databases...167About This Chapter...167Testing with Databases...167Why Test with Databases?...168\n", - [], + new List(), null), - ]), - new ApplicationUsage([new ApplicationModelUsage("qwen-max-latest", 2304, 244)]))); + }), + new ApplicationUsage( + new List { new("qwen-max-latest", 2304, 244) }))); public static readonly RequestSnapshot SinglePromptWithThoughtsNoSse = new( "application-single-generation-text-with-thought", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() { Prompt = "总结xUnit Test Patterns中的内容" }, - Parameters = new ApplicationParameters() + Input = new ApplicationInput { Prompt = "总结xUnit Test Patterns中的内容" }, + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, Seed = 1234, Temperature = 0.85f, - RagOptions = new ApplicationRagOptions() + RagOptions = new ApplicationRagOptions { - PipelineIds = ["thie5bysoj"], - FileIds = ["file_d129d632800c45aa9e7421b30561f447_10207234"] + PipelineIds = new List { "thie5bysoj" }.AsReadOnly(), + FileIds = new List { "file_d129d632800c45aa9e7421b30561f447_10207234" }.AsReadOnly() }, HasThoughts = true } @@ -185,8 +196,9 @@ public static class Application "《xUnit Test Patterns》是一本系统介绍单元测试模式与最佳实践的指南,主要帮助开发者设计可维护、高效且可靠的自动化测试。以下是其核心内容的总结:\n\n---\n\n### **核心主题与内容**\n1. **测试模式与反模式**\n - **关键模式**:如共享夹具管理(Shared Fixtures)、自定义断言(Custom Assertions)、预期对象(Expected Objects)等,用于解决测试代码重复、依赖管理等问题。\n - **反模式与问题**:如不可测试代码(Untestable Code)、测试逻辑混入生产代码(Test Logic in Production)、高维护成本(High Test Maintenance Cost)等,分析其成因与规避策略。\n\n2. **测试夹具管理**\n - **共享夹具**:如何构造、触发和访问共享测试环境(如数据库连接),避免测试间的副作用。\n - **数据库测试**:讨论是否依赖数据库进行测试、如何测试数据访问层、存储过程,以及确保开发者独立性的策略(如使用测试替身)。\n\n3. **测试验证策略**\n - **状态验证**:通过断言检查系统状态(如使用内置断言、Delta断言)。\n - **行为验证**:验证系统是否按预期调用方法(如模拟对象、过程式验证)。\n - **减少代码重复**:通过自定义断言、预期对象和验证方法统一结果检查逻辑。\n\n4. **测试自动化哲学与目标**\n - **目标**:提升代码质量、降低风险、易于编写和维护测试。\n - **经济性**:平衡测试投入与收益,优先覆盖关键路径(Happy Path)和替代路径(Alternative Paths)。\n\n5. **测试代码组织**\n - **结构化策略**:按类(Testcase Class per Class)、功能(Testcase Class per Feature)或夹具(Testcase Class per Fixture)组织测试用例。\n - **命名与套件管理**:使用清晰命名约定、分组测试套件(Test Suites)和依赖管理。\n\n6. **测试维护与演进**\n - **最小化维护成本**:通过模式(如测试工具方法、继承复用)适应系统变化。\n - **自检测试(Built-in Self-Test)**:确保测试本身的可信性。\n\n---\n\n### **书籍结构特点**\n- **问题驱动**:每章围绕具体问题(如“如何处理共享夹具?”)展开,提供模式、替代方案和权衡。\n- **视觉化总结**:通过图表展示模式间的关系,帮助读者理解复杂概念。\n- **实践导向**:结合代码示例与真实场景,指导如何应用模式解决测试中的常见痛点。\n\n---\n\n### **适用场景**\n- 开发中遇到测试代码重复、脆弱测试(Fragile Tests)或高维护成本时。\n- 需要设计复杂测试场景(如数据库交互、异步行为)时。\n- 团队希望建立统一的测试实践与规范时。\n\n通过遵循书中模式,开发者能构建更健壮、可维护的测试体系,最终提升软件质量和开发效率。", "stop", "9d81b84e95f844c29ee825ad8bb647bb", - [ - new ApplicationOutputThought( + new List + { + new( null, "agentRag", "知识检索", @@ -196,7 +208,7 @@ public static class Application "[{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:Visual Summary of the Pattern Language\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Minimize Untestable Code Buggy Tests Production Bugs Keep Test Logic Out of Production Developers Not Writing Tests Ensure Commensurate Effort and Responsibility High Test Maintenance CostKey to Visual Summary of the Pattern Language Chapter Name Chapter Name Sub-Category, Altemative Pattern Smell Pattern 1Pattern 2from Other Chapter'Cause of Smell Sub-Category variation, of Altemative Pattem十Pattem 1Smell Variation of Pattern used with Pattern leads toi Smell Variation described each other Alternative Pattem 2separatelyVISUAL SUMMARY OF THE PATTERN LANGUAGE\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_1_3\",\"images\":[\"http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742716762&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=4CddPVeeyxgrXe5axUspV6zXnS8%3D&x-oss-process=image%2Fcrop%2Cx_232%2Cy_610%2Cw_964%2Ch_648\",\"http://docmind-api-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/1257896666798445/publicDocStructure/docmind-20250315-ee118d3555104aba9200f6cf525bae0a/19.png?Expires=1742716762&OSSAccessKeyId=LTAI5tFEK2uEApeeYzxNMEci&Signature=hRkFcnwAiV7LSHw69WvJJ6fXEV0%3D&x-oss-process=image%2Fcrop%2Cx_227%2Cy_1305%2Cw_991%2Ch_302\"],\"referenceIndex\":1,\"score\":0.5756075978279114,\"title\":\"Visual Summary of the Pattern Language\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Managing Shared Fixtures...103Accessing Shared Fixtures...103Triggering Shared Fixture Construction...104What's Next?...106Chapter 10. Result Verification...107About This Chapter ...107Making Tests Self-Checking...107Verify State or Behavior?...108State Verification...109Using Built-in Assertions ...110Delta Assertions...111External Result Verification ...111Verifying Behavior...112Procedural Behavior Verification...113Expected Behavior Specification . . ...113CONTENTSReducing Test Code Duplication...114Expected Objects...115Custom Assertions...116Outcome-Describing Verification Method ...117\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_33\",\"images\":[],\"referenceIndex\":2,\"score\":0.5756075978279114,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:?...168Issues with Databases...168Testing without Databases...169Testing the Database...171Testing Stored Procedures...172Testing the Data Access Layer...172Ensuring Developer Independence...173Testing with Databases (Again!)...173What's Next? ...174Chapter 14. A Roadmap to Effective Test Automation ...175About This Chapter...175Test Automation Difficulty .. ...175Roadmap to Highly Maintainable Automated Tests...176Exercise the Happy Path Code ...177Verify Direct Outputs of the Happy Path...178CONTENTSVerify Alternative Paths...178Verify Indirect Output Behavior...179\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_37\",\"images\":[],\"referenceIndex\":3,\"score\":0.5697553753852844,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:?..17viiiCONTENTSChapter 3. Goals of Test Automation ...19About This Chapter...19Why Test?...19Economics of Test Automation20Goals of Test Automation...21Tests Should Help Us Improve Quality...22Tests Should Help Us Understand the SUT. . ...23Tests Should Reduce (and Not Introduce) Risk...23Tests Should Be Easy to Run ...25Tests Should Be Easy to Write and Maintain ...27Tests Should Require Minimal Maintenance asthe System Evolves Around Them ...29What's Next? .29Chapter 4. Philosophy of Test Automation ...31About This Chapter...31Why Is Philosophy Important?...31\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_28\",\"images\":[],\"referenceIndex\":4,\"score\":0.5639580488204956,\"title\":\"xUnit Test Patterns\",\"webSearch\":false},{\"content\":\"【文档名】:xUnit Test Patterns\\n【标题】:xUnit Test Patterns\\n文档类型:[\\\"xUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\",\\\"XUNIT TEST Yoog PATTERNS REFACTORING TEST CODE GERARD)1MESZAROS\\\"]\\n【正文】:Testcase Class per Class... ...155Testcase Class per Feature. ...156Testcase Class per Fixture...156Choosing a Test Method Organization Strategy...158Test Naming Conventions...158Organizing Test Suites.. . ...160Running Groups of Tests ...160Running a Single Test...161Test Code Reuse...162Test Utility Method Locations ...163TestCase Inheritance and Reuse...163Test File Organization...164Built-in Self-Test...164Test Packages. ...164Test Dependencies ...165What's Next? ...165Chapter 13. Testing with Databases...167About This Chapter...167Testing with Databases...167Why Test with Databases?...168\\n\",\"dataId\":\"file_d129d632800c45aa9e7421b30561f447_10207234\",\"dataName\":\"xUnit Test Patterns\",\"display\":true,\"id\":\"llm-lposod7dkhzvfgmy_thie5bysoj_file_d129d632800c45aa9e7421b30561f447_10207234_0_36\",\"images\":[],\"referenceIndex\":5,\"score\":0.563438355922699,\"title\":\"xUnit Test Patterns\",\"webSearch\":false}]", null, "{}"), - new ApplicationOutputThought( + new( "好的,我现在需要总结用户提供的xUnit Test Patterns中的内容。首先,用户给了几个文档片段,每个片段都来自同一本书的不同部分。我需要仔细分析这些片段,看看里面提到的关键点和主题。\n\n第一个文档提到了“Visual Summary of the Pattern Language”,里面有几个关键点,比如Minimize Untestable Code,Buggy Tests,Production Bugs,还有测试维护成本高的问题。可能这本书在讲如何设计和管理单元测试的模式,避免常见的问题,比如不可测试的代码和测试逻辑混入生产环境。\n\n第二个文档片段讲的是“Managing Shared Fixtures”和结果验证(Result Verification)。这里提到共享夹具的管理、触发构建,以及如何验证测试结果,包括状态验证和行为验证,还有减少测试代码重复的方法,比如使用Expected Objects和Custom Assertions。这说明书中详细讨论了测试夹具的设计和如何有效验证测试结果,避免重复代码。\n\n第三个文档涉及数据库测试的问题,比如如何测试数据访问层、存储过程,以及确保开发者独立性的策略。这部分可能讨论在测试中使用数据库的挑战和解决方案,例如是否使用数据库进行测试,或者如何隔离测试以避免依赖。\n\n第四个文档提到了测试自动化的目标和哲学,包括测试的经济性、提高质量、理解系统、降低风险、易于运行和维护等。这说明书中不仅提供技术模式,还强调测试策略和哲学的重要性,指导如何有效实施自动化测试。\n\n第五个文档讨论了测试用例的组织策略,比如按类、功能或夹具组织测试用例类,命名约定,测试套件的管理,以及测试代码的重用方法。这部分可能涉及如何结构化测试代码,提高可维护性和可读性。\n\n综合这些片段,xUnit Test Patterns似乎是一本关于单元测试设计和最佳实践的指南,涵盖测试模式、夹具管理、结果验证、数据库测试、测试自动化策略和测试代码组织。重点在于如何编写可维护、可靠且高效的测试,避免常见陷阱,如不可测试的代码、测试逻辑污染生产代码、高维护成本等。书中可能还讨论了如何在不同情境下选择适当的测试策略,例如是否使用共享夹具,如何处理数据库依赖,以及如何组织测试代码结构以提高复用性。\n\n现在需要将这些分析整理成一个简明扼要的总结,突出主要主题和关键点,确保涵盖各个文档片段提到的内容,并指出这本书的整体目的和结构。可能需要分点说明,让用户清晰了解书中的核心内容。", "reasoning", "思考过程", @@ -206,20 +218,21 @@ public static class Application null, "好的,我现在需要总结用户提供的xUnit Test Patterns中的内容。首先,用户给了几个文档片段,每个片段都来自同一本书的不同部分。我需要仔细分析这些片段,看看里面提到的关键点和主题。\n\n第一个文档提到了“Visual Summary of the Pattern Language”,里面有几个关键点,比如Minimize Untestable Code,Buggy Tests,Production Bugs,还有测试维护成本高的问题。可能这本书在讲如何设计和管理单元测试的模式,避免常见的问题,比如不可测试的代码和测试逻辑混入生产环境。\n\n第二个文档片段讲的是“Managing Shared Fixtures”和结果验证(Result Verification)。这里提到共享夹具的管理、触发构建,以及如何验证测试结果,包括状态验证和行为验证,还有减少测试代码重复的方法,比如使用Expected Objects和Custom Assertions。这说明书中详细讨论了测试夹具的设计和如何有效验证测试结果,避免重复代码。\n\n第三个文档涉及数据库测试的问题,比如如何测试数据访问层、存储过程,以及确保开发者独立性的策略。这部分可能讨论在测试中使用数据库的挑战和解决方案,例如是否使用数据库进行测试,或者如何隔离测试以避免依赖。\n\n第四个文档提到了测试自动化的目标和哲学,包括测试的经济性、提高质量、理解系统、降低风险、易于运行和维护等。这说明书中不仅提供技术模式,还强调测试策略和哲学的重要性,指导如何有效实施自动化测试。\n\n第五个文档讨论了测试用例的组织策略,比如按类、功能或夹具组织测试用例类,命名约定,测试套件的管理,以及测试代码的重用方法。这部分可能涉及如何结构化测试代码,提高可维护性和可读性。\n\n综合这些片段,xUnit Test Patterns似乎是一本关于单元测试设计和最佳实践的指南,涵盖测试模式、夹具管理、结果验证、数据库测试、测试自动化策略和测试代码组织。重点在于如何编写可维护、可靠且高效的测试,避免常见陷阱,如不可测试的代码、测试逻辑污染生产代码、高维护成本等。书中可能还讨论了如何在不同情境下选择适当的测试策略,例如是否使用共享夹具,如何处理数据库依赖,以及如何组织测试代码结构以提高复用性。\n\n现在需要将这些分析整理成一个简明扼要的总结,突出主要主题和关键点,确保涵盖各个文档片段提到的内容,并指出这本书的整体目的和结构。可能需要分点说明,让用户清晰了解书中的核心内容。", null) - ], + }, null), - new ApplicationUsage([new ApplicationModelUsage("deepseek-r1", 1129, 1126)]))); + new ApplicationUsage( + new List { new("deepseek-r1", 1129, 1126) }))); public static readonly RequestSnapshot SinglePromptWithMemoryNoSse = new( "application-single-generation-text-with-memory", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() + Input = new ApplicationInput { Prompt = "我爱吃面食", MemoryId = "ffd8be2352d84c6b9350e91c865b512e" }, - Parameters = new ApplicationParameters() + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, @@ -234,9 +247,10 @@ public static class Application "那您一定会对面条、馒头或者饺子这些美食很感兴趣呢!如果您有特定的面食问题或者需要推荐相关的菜品,可以告诉我,我很乐意为您提供帮助[1]。", "stop", "cd395cb8d4604db786a14555fdcffa1a", - [ - new ApplicationOutputThought(null, "agentRag", "知识检索", "rag", "{}", null, "[]", null, "{}"), - new ApplicationOutputThought( + new List + { + new(null, "agentRag", "知识检索", "rag", "{}", null, "[]", null, "{}"), + new( null, "api", "长期记忆检索", @@ -246,21 +260,22 @@ public static class Application "[\"[2025-3-16 20:47:40 周日] 用户喜欢吃面食。\"]", null, "{\"memory_id\":\"ffd8be2352d84c6b9350e91c865b512e\",\"query\":\"我爱吃面食\"}") - ], + }, null), - new ApplicationUsage([new ApplicationModelUsage("qwen-plus", 1201, 43)]))); + new ApplicationUsage( + new List { new("qwen-plus", 1201, 43) }))); public static readonly RequestSnapshot, ApplicationResponse> WorkflowNoSse = new( "application-workflow", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() + Input = new ApplicationInput { BizParams = new TestApplicationBizParam("code"), Prompt = "请你跟我这样说" }, - Parameters = new ApplicationParameters() + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, @@ -277,13 +292,13 @@ public static readonly RequestSnapshot() + new ApplicationRequest { - Input = new ApplicationInput() + Input = new ApplicationInput { BizParams = new TestApplicationBizParam("code"), Prompt = "请你跟我这样说" }, - Parameters = new ApplicationParameters() + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, @@ -300,22 +315,22 @@ public static readonly RequestSnapshot ConversationSessionIdNoSse = new( "application-conversation-generation-session-id", - new ApplicationRequest() + new ApplicationRequest { Input = - new ApplicationInput() + new ApplicationInput { Prompt = "总结一下第一本书的内容", SessionId = "9995da2046a04b448dc5a562563f4835" }, - Parameters = new ApplicationParameters() + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, Seed = 1234, Temperature = 0.85f, - RagOptions = new ApplicationRagOptions() + RagOptions = new ApplicationRagOptions { - PipelineIds = ["ll6yfcnxjg"], + PipelineIds = new List { "ll6yfcnxjg" }.AsReadOnly(), MetadataFilter = new Dictionary { { "docType", "电子书" } } }, HasThoughts = true @@ -327,8 +342,9 @@ public static readonly RequestSnapshot + { + new( null, "agentRag", "知识检索", @@ -338,7 +354,7 @@ public static readonly RequestSnapshot { new("deepseek-r1", 1283, 1081) }))); public static readonly RequestSnapshot ConversationMessageNoSse = new( "application-conversation-generation-message", - new ApplicationRequest() + new ApplicationRequest { - Input = new ApplicationInput() + Input = new ApplicationInput { Messages = - [ - ApplicationMessage.System("You are a helpful assistant."), - ApplicationMessage.User("你是谁?"), - ApplicationMessage.Assistant("我是阿里云开发的大规模语言模型,我叫通义千问。"), - ApplicationMessage.User("哪些人的主食偏好是米饭?"), - ], + new List + { + ApplicationMessage.System("You are a helpful assistant."), + ApplicationMessage.User("你是谁?"), + ApplicationMessage.Assistant("我是阿里云开发的大规模语言模型,我叫通义千问。"), + ApplicationMessage.User("哪些人的主食偏好是米饭?"), + }.AsReadOnly(), }, - Parameters = new ApplicationParameters() + Parameters = new ApplicationParameters { TopK = 100, TopP = 0.8f, Seed = 1234, Temperature = 0.85f, - RagOptions = new ApplicationRagOptions() + RagOptions = new ApplicationRagOptions { - PipelineIds = ["e6md69132k"], + PipelineIds = new List { "e6md69132k" }.AsReadOnly(), StructuredFilter = new Dictionary { { "年龄", 14 } } }, HasThoughts = true @@ -387,8 +405,9 @@ public static readonly RequestSnapshot + { + new( null, "agentRag", "知识检索", @@ -398,7 +417,7 @@ public static readonly RequestSnapshot { new("qwen-plus", 344, 311) }))); } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Error.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Error.cs similarity index 84% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Error.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Error.cs index eb4ea63..f199963 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Error.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Error.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public static partial class Snapshots { @@ -23,7 +23,7 @@ public static readonly TopK = 100, RepetitionPenalty = 1.1f, Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, + Stop = new[] { new[] { 37763, 367 } }, EnableSearch = false, IncrementalOutput = false } @@ -42,7 +42,11 @@ public static readonly new ModelRequest { Model = "qwen-max", - Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?", Messages = [] }, + Input = new TextGenerationInput + { + Prompt = "请问 1+1 是多少?", Messages = + new List().AsReadOnly() + }, Parameters = new TextGenerationParameters { ResultFormat = "text", @@ -52,7 +56,7 @@ public static readonly TopK = 100, RepetitionPenalty = 1.1f, Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, + Stop = new[] { new[] { 37763, 367 } }, EnableSearch = false, IncrementalOutput = false } @@ -71,7 +75,11 @@ public static readonly new ModelRequest { Model = "qwen-max", - Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?", Messages = [] }, + Input = new TextGenerationInput + { + Prompt = "请问 1+1 是多少?", Messages = + new List().AsReadOnly() + }, Parameters = new TextGenerationParameters { ResultFormat = "text", @@ -81,7 +89,7 @@ public static readonly TopK = 100, RepetitionPenalty = 1.1f, Temperature = 0.85f, - Stop = new int[][] { [37763, 367] }, + Stop = new[] { new[] { 37763, 367 } }, EnableSearch = false, IncrementalOutput = true } diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.MultimodalGeneration.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.MultimodalGeneration.cs new file mode 100644 index 0000000..f413959 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.MultimodalGeneration.cs @@ -0,0 +1,567 @@ +using Cnblogs.DashScope.Core; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public static partial class Snapshots +{ + public static class MultimodalGeneration + { + public static readonly RequestSnapshot, + ModelResponse> VlNoSse = + new( + "multimodal-generation-vl", + new ModelRequest + { + Model = "qwen-vl-plus", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.System( + new List + { + MultimodalMessageContent.TextContent("You are a helpful assistant.") + }.AsReadOnly()), + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"), + MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopK = 100, + TopP = 0.81f, + Temperature = 1.1f, + VlHighResolutionImages = true, + RepetitionPenalty = 1.3f, + PresencePenalty = 1.2f, + MaxTokens = 120, + Stop = "你好" + } + }, + new ModelResponse + { + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List { MultimodalMessageContent.TextContent("海滩。") } + .AsReadOnly())) + }), + RequestId = "e81aa922-be6c-9f9d-bd4f-0f43e21fd913", + Usage = new MultimodalTokenUsage + { + OutputTokens = 3, + InputTokens = 3613, + ImageTokens = 3577 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> VlChatClientNoSse = + new( + "multimodal-generation-vl", + new ModelRequest + { + Model = "qwen-vl-plus", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="), + MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopK = 100, + TopP = 0.81f, + Temperature = 1.1f, + RepetitionPenalty = 1.3f, + PresencePenalty = 1.2f, + MaxTokens = 120, + } + }, + new ModelResponse + { + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List { MultimodalMessageContent.TextContent("海滩。") } + .AsReadOnly())) + }), + RequestId = "e81aa922-be6c-9f9d-bd4f-0f43e21fd913", + Usage = new MultimodalTokenUsage + { + OutputTokens = 3, + InputTokens = 3613, + ImageTokens = 3577 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> VlSse = + new( + "multimodal-generation-vl", + new ModelRequest + { + Model = "qwen-vl-plus", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.System( + new List + { + MultimodalMessageContent.TextContent("You are a helpful assistant.") + }.AsReadOnly()), + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"), + MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + IncrementalOutput = true, + Seed = 1234, + TopK = 100, + TopP = 0.81f + } + }, + new ModelResponse + { + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "这是一个海滩,有沙滩和海浪。在前景中坐着一个女人与她的宠物狗互动。背景中有海水、阳光及远处的海岸线。由于没有具体标识物或地标信息,我无法提供更精确的位置描述。这可能是一个公共海滩或是私人区域。重要的是要注意不要泄露任何个人隐私,并遵守当地的规定和法律法规。欣赏自然美景的同时请尊重环境和其他访客。") + }.AsReadOnly())) + }), + RequestId = "13c5644d-339c-928a-a09a-e0414bfaa95c", + Usage = new MultimodalTokenUsage + { + OutputTokens = 85, + InputTokens = 1283, + ImageTokens = 1247 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> VlChatClientSse = + new( + "multimodal-generation-vl", + new ModelRequest + { + Model = "qwen-vl-plus", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="), + MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + IncrementalOutput = true, + Seed = 1234, + TopK = 100, + TopP = 0.81f, + } + }, + new ModelResponse + { + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "这是一个海滩,有沙滩和海浪。在前景中坐着一个女人与她的宠物狗互动。背景中有海水、阳光及远处的海岸线。由于没有具体标识物或地标信息,我无法提供更精确的位置描述。这可能是一个公共海滩或是私人区域。重要的是要注意不要泄露任何个人隐私,并遵守当地的规定和法律法规。欣赏自然美景的同时请尊重环境和其他访客。") + }.AsReadOnly())) + }), + RequestId = "13c5644d-339c-928a-a09a-e0414bfaa95c", + Usage = new MultimodalTokenUsage + { + OutputTokens = 85, + InputTokens = 1283, + ImageTokens = 1247 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + OcrNoSse = new( + "multimodal-generation-vl-ocr", + new ModelRequest + { + Model = "qwen-vl-ocr", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg", + 3136, + 1003520), + MultimodalMessageContent.TextContent("Read all the text in the image.") + }.AsReadOnly()), + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Temperature = 0.1f, + RepetitionPenalty = 1.05f, + MaxTokens = 2000, + TopP = 0.01f + } + }, + new ModelResponse + { + RequestId = "195c98cd-4ee5-998b-b662-132b7aebc048", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "读者对象 如果你是Linux环境下的系统管理员,那么学会编写shell脚本将让你受益匪浅。本书并未细述安装 Linux系统的每个步骤,但只要系统已安装好Linux并能运行起来,你就可以开始考虑如何让一些日常 的系统管理任务实现自动化。这时shell脚本编程就能发挥作用了,这也正是本书的作用所在。本书将 演示如何使用shell脚本来自动处理系统管理任务,包括从监测系统统计数据和数据文件到为你的老板 生成报表。 如果你是家用Linux爱好者,同样能从本书中获益。现今,用户很容易在诸多部件堆积而成的图形环境 中迷失。大多数桌面Linux发行版都尽量向一般用户隐藏系统的内部细节。但有时你确实需要知道内部 发生了什么。本书将告诉你如何启动Linux命令行以及接下来要做什么。通常,如果是执行一些简单任 务(比如文件管理) , 在命令行下操作要比在华丽的图形界面下方便得多。在命令行下有大量的命令 可供使用,本书将会展示如何使用它们。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + InputTokens = 1248, + OutputTokens = 225, + ImageTokens = 1219 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + OcrSse = new( + "multimodal-generation-vl-ocr", + new ModelRequest + { + Model = "qwen-vl-ocr", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.ImageContent( + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg", + 3136, + 1003520), + MultimodalMessageContent.TextContent("Read all the text in the image.") + }.AsReadOnly()), + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Temperature = 0.1f, + RepetitionPenalty = 1.05f, + MaxTokens = 2000, + TopP = 0.01f, + IncrementalOutput = true + } + }, + new ModelResponse + { + RequestId = "fb33a990-3826-9386-8b0a-8317dfc38c1c", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "读者对象 如果你是Linux环境下的系统管理员,那么学会编写shell脚本将让你受益匪浅。本书并未细述安装 Linux系统的每个步骤,但只要系统已安装好Linux并能运行起来,你就可以开始考虑如何让一些日常 的系统管理任务实现自动化。这时shell脚本编程就能发挥作用了,这也正是本书的作用所在。本书将 演示如何使用shell脚本来自动处理系统管理任务,包括从监测系统统计数据和数据文件到为你的老板 生成报表。 如果你是家用Linux爱好者,同样能从本书中获益。现今,用户很容易在诸多部件堆积而成的图形环境 中迷失。大多数桌面Linux发行版都尽量向一般用户隐藏系统的内部细节。但有时你确实需要知道内部 发生了什么。本书将告诉你如何启动Linux命令行以及接下来要做什么。通常,如果是执行一些简单任 务(比如文件管理) , 在命令行下操作要比在华丽的图形界面下方便得多。在命令行下有大量的命令 可供使用,本书将会展示如何使用它们。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + InputTokens = 1248, + OutputTokens = 225, + ImageTokens = 1219 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + AudioNoSse = new( + "multimodal-generation-audio", + new ModelRequest + { + Model = "qwen-audio-turbo", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.System( + new List + { + MultimodalMessageContent.TextContent("You are a helpful assistant.") + }.AsReadOnly()), + MultimodalMessage.User( + new List + { + MultimodalMessageContent.AudioContent( + "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/2channel_16K.wav"), + MultimodalMessageContent.TextContent("这段音频在说什么,请用简短的语言回答") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopK = 100, + TopP = 0.81f + } + }, + new ModelResponse + { + RequestId = "6b6738bd-dd9d-9e78-958b-02574acbda44", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "这段音频在说中文,内容是\"没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网未来没有我互联网\"。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + InputTokens = 786, + OutputTokens = 38, + AudioTokens = 752 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + AudioSse = new( + "multimodal-generation-audio", + new ModelRequest + { + Model = "qwen-audio-turbo", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.System( + new List + { + MultimodalMessageContent.TextContent("You are a helpful assistant.") + }.AsReadOnly()), + MultimodalMessage.User( + new List + { + MultimodalMessageContent.AudioContent( + "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/2channel_16K.wav"), + MultimodalMessageContent.TextContent("这段音频的第一句话说了什么?") + }.AsReadOnly()) + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopK = 100, + TopP = 0.81f, + IncrementalOutput = true + } + }, + new ModelResponse + { + RequestId = "bb6ab962-af57-99f1-9af8-eb7016ebc18e", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent("第一句话说了没有我互联网。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + InputTokens = 783, + OutputTokens = 7, + AudioTokens = 752 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + VideoNoSse = new( + "multimodal-generation-vl-video", + new ModelRequest + { + Model = "qwen-vl-max", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.VideoContent( + new List + { + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg" + }.AsReadOnly()), + MultimodalMessageContent.TextContent("描述这个视频的具体过程") + }.AsReadOnly()), + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopP = 0.01f, + Temperature = 0.1f, + RepetitionPenalty = 1.05f + } + }, + new ModelResponse + { + RequestId = "d538f8cc-8048-9ca8-9e8a-d2a49985b479", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "这段视频展示了一场足球比赛的精彩瞬间。具体过程如下:\n\n1. **背景**:画面中是一个大型体育场,观众席上坐满了观众,气氛热烈。\n2. **球员位置**:球场上有两队球员,一队穿着红色球衣,另一队穿着蓝色球衣。守门员穿着绿色球衣,站在球门前准备防守。\n3. **射门动作**:一名身穿红色球衣的球员在禁区内接到队友传球后,迅速起脚射门。\n4. **守门员扑救**:守门员看到对方射门后,立即做出反应,向左侧跃出试图扑救。\n5. **进球瞬间**:尽管守门员尽力扑救,但皮球还是从他的右侧飞入了球网。\n\n整个过程充满了紧张和刺激,展示了足球比赛中的精彩时刻。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + VideoTokens = 1440, + InputTokens = 1466, + OutputTokens = 180 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + VideoSse = new( + "multimodal-generation-vl-video", + new ModelRequest + { + Model = "qwen-vl-max", + Input = new MultimodalInput + { + Messages = + new List + { + MultimodalMessage.User( + new List + { + MultimodalMessageContent.VideoContent( + new List + { + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg", + "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg" + }.AsReadOnly()), + MultimodalMessageContent.TextContent("描述这个视频的具体过程") + }.AsReadOnly()), + }.AsReadOnly() + }, + Parameters = new MultimodalParameters + { + Seed = 1234, + TopP = 0.01f, + Temperature = 0.1f, + RepetitionPenalty = 1.05f, + IncrementalOutput = true + } + }, + new ModelResponse + { + RequestId = "851745a1-22ba-90e2-ace2-c04e7445ec6f", + Output = new MultimodalOutput( + new List + { + new( + "stop", + MultimodalMessage.Assistant( + new List + { + MultimodalMessageContent.TextContent( + "这段视频展示了一场足球比赛的精彩瞬间。具体过程如下:\n\n1. **背景**:画面中是一个大型体育场,观众席上坐满了观众,气氛热烈。\n2. **球员位置**:场上有两队球员,一队穿着红色球衣,另一队穿着蓝色球衣。守门员穿着绿色球衣,站在球门前准备防守。\n3. **射门动作**:一名身穿红色球衣的球员在禁区内接到队友传球后,迅速起脚射门。\n4. **扑救尝试**:守门员看到射门后立即做出反应,向左侧跃出试图扑救。\n5. **进球瞬间**:尽管守门员尽力扑救,但皮球还是从他的右侧飞入了球网。\n\n整个过程充满了紧张和刺激,展示了足球比赛中的精彩时刻。") + }.AsReadOnly())) + }), + Usage = new MultimodalTokenUsage + { + VideoTokens = 1440, + InputTokens = 1466, + OutputTokens = 176 + } + }); + } +} diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.SocketRequests.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.SocketRequests.cs new file mode 100644 index 0000000..79f9b92 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.SocketRequests.cs @@ -0,0 +1,142 @@ +using Cnblogs.DashScope.Core; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public partial class Snapshots +{ + public static class SpeechSynthesizer + { + private const string GroupName = "speech-synthesizer"; + + public static readonly + SocketMessageSnapshot> + RunTask = new( + GroupName, + "run-task", + new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + Action = "run-task", + Streaming = "duplex", + TaskId = "439e0616-2f5b-44e0-8872-0002a066a49c" + }, + Payload = + new DashScopeWebSocketRequestPayload + { + Task = "tts", + TaskGroup = "audio", + Function = "SpeechSynthesizer", + Model = "cosyvoice-v1", + Parameters = new SpeechSynthesizerParameters + { + EnableSsml = true, + Format = "mp3", + Pitch = 1.2f, + Voice = "longxiaochun", + Volume = 50, + SampleRate = 0, + Rate = 1.1f, + } + } + }); + + public static readonly + SocketMessageSnapshot> + ContinueTask = new( + GroupName, + "continue-task", + new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + Action = "continue-task", + TaskId = "439e0616-2f5b-44e0-8872-0002a066a49c", + Streaming = null + }, + Payload = + new DashScopeWebSocketRequestPayload + { + Input = new SpeechSynthesizerInput { Text = "代码改变世界" } + } + }); + + public static readonly + SocketMessageSnapshot> + FinishTask = + new( + GroupName, + "finish-task", + new DashScopeWebSocketRequest + { + Header = new DashScopeWebSocketRequestHeader + { + Action = "finish-task", + TaskId = "439e0616-2f5b-44e0-8872-0002a066a49c", + Streaming = null + }, + Payload = + new DashScopeWebSocketRequestPayload { Input = new SpeechSynthesizerInput() } + }); + + public static readonly SocketMessageSnapshot> TaskStarted = + new( + GroupName, + "task-started", + new DashScopeWebSocketResponse( + new DashScopeWebSocketResponseHeader( + "439e0616-2f5b-44e0-8872-0002a066a49c", + "task-started", + null, + null, + new DashScopeWebSocketResponseHeaderAttributes(null)), + new DashScopeWebSocketResponsePayload(null, null))); + + public static readonly SocketMessageSnapshot> TaskFinished = + new( + GroupName, + "task-finished", + new DashScopeWebSocketResponse( + new DashScopeWebSocketResponseHeader( + "439e0616-2f5b-44e0-8872-0002a066a49c", + "task-finished", + null, + null, + new DashScopeWebSocketResponseHeaderAttributes("c88301b4-3caa-4f15-94e2-246e84d2e648")), + new DashScopeWebSocketResponsePayload( + new SpeechSynthesizerOutput(new SpeechSynthesizerOutputSentences(Array.Empty())), + new DashScopeWebSocketResponseUsage(12)))); + + public static readonly SocketMessageSnapshot> TaskFailed = + new( + GroupName, + "task-failed", + new DashScopeWebSocketResponse( + new DashScopeWebSocketResponseHeader( + "439e0616-2f5b-44e0-8872-0002a066a49c", + "task-failed", + "InvalidParameter", + "[tts:]Engine return error code: 418", + new DashScopeWebSocketResponseHeaderAttributes(null)), + new DashScopeWebSocketResponsePayload(null, null))); + + public static readonly SocketMessageSnapshot> + ResultGenerated = new( + GroupName, + "result-generated", + new DashScopeWebSocketResponse( + new DashScopeWebSocketResponseHeader( + "439e0616-2f5b-44e0-8872-0002a066a49c", + "result-generated", + null, + null, + new DashScopeWebSocketResponseHeaderAttributes("c88301b4-3caa-4f15-94e2-246e84d2e648")), + new DashScopeWebSocketResponsePayload( + new SpeechSynthesizerOutput(new SpeechSynthesizerOutputSentences(Array.Empty())), + null))); + + public static readonly byte[] AudioTts = + System.IO.File.ReadAllBytes(Path.Combine("RawHttpData", "tts.mp3"))[..1000]; + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Tasks.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Tasks.cs similarity index 78% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Tasks.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Tasks.cs index 90b68ff..01eb965 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.Tasks.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.Tasks.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public static partial class Snapshots { @@ -58,16 +58,17 @@ public static readonly RequestSnapshot + { + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/d4/20240301/8d820c8d/4c48fa53-2907-499b-b9ac-76477fe8d299-1.png"), + new( + "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/79/20240301/3ab595ad/aa3e6d8d-884d-4431-b9c2-3684edeb072e-1.png"), + new( + "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/79/20240301/3ab595ad/aa3e6d8d-884d-4431-b9c2-3684edeb072e-1.png"), + new( + "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/3d/20240301/3ab595ad/3fca748e-d491-458a-bb72-73649af33209-1.png") + }, TaskMetrics = new DashScopeTaskMetrics(4, 4, 0) }, new ImageSynthesisUsage(4))); @@ -89,10 +90,11 @@ public static readonly RequestSnapshot + { + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/viapi-video/2024-03-02/ac5d435a-9ea9-4287-8666-e1be7bbba943/20240302222213528791_style3_jxdf6o4zwy.jpg") + } }, new ImageGenerationUsage(1))); @@ -109,26 +111,30 @@ public static readonly RequestSnapshot + { + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_0_02dc0bba-8b1d-4648-8b95-eb2b92fe715d.png"), + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100905_1_e1af86ec-152a-4ebe-b2a0-b40a592043b2.png") + }, TaskMetrics = new DashScopeTaskMetrics(2, 2, 0), TextResults = new BackgroundGenerationTextResult( - [ - new BackgroundGenerationTextResultUrl( - "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_0_4645005c-713d-4e92-9629-b12cbe5f3671.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=kmZGXc2s8P4uI%2BVrADITyrPz82U%3D"), - new BackgroundGenerationTextResultUrl( - "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_1_b1979b75-c553-4d9b-9c9f-80f401a0d124.png?Expires=1709604547&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=cb1Qg%2FkIuZyI7XQqWHjP712N0ak%3D") - ], - [ - new BackgroundGenerationTextResultParams( + new List + { + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_0_4645005c-713d-4e92-9629-b12cbe5f3671.png"), + new( + "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/466b5214/20240304/100901_1_b1979b75-c553-4d9b-9c9f-80f401a0d124.png") + }, + new List + { + new( 0, - [ - new BackgroundGenerationTextResultLayer( + new List + { + new( 0, "text_mask", 0, @@ -141,14 +147,15 @@ public static readonly RequestSnapshot + { + new( "#521b0800", 0), - new BackgroundGenerationTextResultGradientColorStop( + new( "#521b08ff", 1) - ]) + }) { Coords = new Dictionary { @@ -158,7 +165,7 @@ public static readonly RequestSnapshot + { + new( "#e6baa7ff", 0), - new BackgroundGenerationTextResultGradientColorStop( + new( "#e6baa7ff", 1) - ]) + }) { Coords = new Dictionary { @@ -211,7 +219,7 @@ public static readonly RequestSnapshot + { + new( 0, "text_mask", 0, @@ -247,14 +256,15 @@ public static readonly RequestSnapshot + { + new( "#efeae400", 0), - new BackgroundGenerationTextResultGradientColorStop( + new( "#efeae4ff", 1) - ]) + }) { Coords = new Dictionary { @@ -266,7 +276,7 @@ public static readonly RequestSnapshot + { + new( "#421f12ff", 0), - new BackgroundGenerationTextResultGradientColorStop( + new( "#421f12ff", 1) - ]) + }) { Coords = new Dictionary { @@ -319,7 +330,7 @@ public static readonly RequestSnapshot { - Input = new TextEmbeddingInput { Texts = ["代码改变世界"] }, + Input = new TextEmbeddingInput { Texts = new List { "代码改变世界" }.AsReadOnly() }, Model = "text-embedding-v2", Parameters = new TextEmbeddingParameters { TextType = "query" } }, new ModelResponse { - Output = new TextEmbeddingOutput([new TextEmbeddingItem(0, [])]), + Output = new TextEmbeddingOutput(new List { new(0, new float[0]) }), RequestId = "1773f7b2-2148-9f74-b335-b413e398a116", Usage = new TextEmbeddingTokenUsage(3) }); @@ -27,13 +27,13 @@ public static class TextEmbedding "text-embedding", new ModelRequest { - Input = new TextEmbeddingInput { Texts = ["代码改变世界"] }, + Input = new TextEmbeddingInput { Texts = new List { "代码改变世界" }.AsReadOnly() }, Model = "text-embedding-v3", Parameters = new TextEmbeddingParameters { Dimension = 1024 } }, new ModelResponse { - Output = new TextEmbeddingOutput([new TextEmbeddingItem(0, [])]), + Output = new TextEmbeddingOutput(new List { new(0, new float[0]) }), RequestId = "1773f7b2-2148-9f74-b335-b413e398a116", Usage = new TextEmbeddingTokenUsage(3) }); diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.TextGeneration.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.TextGeneration.cs new file mode 100644 index 0000000..65e5747 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.TextGeneration.cs @@ -0,0 +1,935 @@ +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Sdk; +using Json.Schema; +using Json.Schema.Generation; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public static partial class Snapshots +{ + public static class TextGeneration + { + public static class TextFormat + { + public static readonly RequestSnapshot, + ModelResponse> + SinglePrompt = new( + "single-generation-text", + new ModelRequest + { + Model = "qwen-max", + Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?" }, + Parameters = new TextGenerationParameters + { + ResultFormat = "text", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = false + } + }, + new ModelResponse + { + Output = + new TextGenerationOutput { FinishReason = "stop", Text = "1+1等于2。这是最基本的数学加法运算之一。" }, + RequestId = "7e3d5586-cb70-98ce-97bf-8a2ac0091c3f", + Usage = new TextGenerationTokenUsage + { + InputTokens = 16, + OutputTokens = 14, + TotalTokens = 30, + PromptTokensDetails = new TextGenerationPromptTokenDetails(0) + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SinglePromptIncremental = new( + "single-generation-text", + new ModelRequest + { + Model = "qwen-max", + Input = new TextGenerationInput { Prompt = "请问 1+1 是多少?" }, + Parameters = new TextGenerationParameters + { + ResultFormat = "text", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = true + } + }, + new ModelResponse + { + Output = new TextGenerationOutput { FinishReason = "stop", Text = "1+1等于2。" }, + RequestId = "5b441aa7-0b9c-9fbc-ae0a-e2b212b71eac", + Usage = new TextGenerationTokenUsage + { + InputTokens = 16, + OutputTokens = 6, + TotalTokens = 22 + } + }); + } + + public static class MessageFormat + { + public static readonly RequestSnapshot, + ModelResponse> + SingleMessage = new( + "single-generation-message", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = false + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何两个相同的数字相加都等于该数字的二倍。") + } + } + }, + RequestId = "e764bfe3-c0b7-97a0-ae57-cd99e1580960", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 47, + OutputTokens = 39, + InputTokens = 8 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageReasoning = new( + "single-generation-message-reasoning", + new ModelRequest + { + Model = "deepseek-r1", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + IncrementalOutput = false, ResultFormat = ResultFormats.Message + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = + TextChatMessage.Assistant( + "1 + 1 等于 **2**。这是基础的算术加法,当我们将一个单位与另一个单位相加时,总和为两个单位。", + null, + null, + "嗯,用户问1加1等于多少。这个问题看起来很简单,但可能有一些需要注意的地方。首先,我得确认用户是不是真的在问基本的数学问题,还是有其他的意图,比如测试我的反应或者开玩笑。\n\n1加1在基础算术里确实是2,但有时候可能会有不同的解释,比如在二进制中1+1等于10,或者在逻辑学中有时候表示为1,如果是布尔代数的话。不过通常情况下,用户可能只需要最直接的答案,也就是2。\n\n不过也有可能用户想考察我是否能够处理更复杂的情况,或者是否有隐藏的意思。比如,在某些情况下,1加1可能被用来比喻合作的效果,比如“1+1大于2”,但这可能超出了当前问题的范围。\n\n我需要考虑用户的背景。如果用户是小学生,那么直接回答2是正确的,并且可能需要鼓励的话。如果是成年人,可能还是同样的答案,但不需要额外的解释。如果用户来自数学或计算机领域,可能需要确认是否需要其他进制的答案,但通常默认是十进制。\n\n另外,检查是否有拼写错误或非阿拉伯数字的情况,比如罗马数字的I+I,但问题里明确写的是1+1,所以应该是阿拉伯数字。\n\n总结下来,最安全也是最正确的答案就是2。不过为了确保,可以简短地确认用户的意图,但按照常规问题处理,直接回答即可。") + } + } + }, + RequestId = "7039d8ff-89e0-9191-b4d3-0d258a7d70e1", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 313, + OutputTokens = 302, + InputTokens = 11 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleChatClientMessage = new( + "single-generation-message", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + ToolChoice = ToolChoice.AutoChoice + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何两个相同的数字相加都等于该数字的二倍。") + } + } + }, + RequestId = "e764bfe3-c0b7-97a0-ae57-cd99e1580960", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 47, + OutputTokens = 39, + InputTokens = 8 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageLogprobs = new( + "single-generation-message-logprobs", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?请直接输出结果") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Logprobs = true, + TopLogprobs = 2 + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant("2"), + Logprobs = new TextGenerationLogprobs( + new List() + { + new( + "2", + new byte[] { 50 }, + 0.0f, + new List() + { + new("2", new byte[] { 50 }, 0.0f) + }), + }) + } + } + }, + RequestId = "1d881da5-0028-9f20-8e7f-6bc7ae891c54", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 21, + OutputTokens = 1, + InputTokens = 20, + PromptTokensDetails = new TextGenerationPromptTokenDetails(0) + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageTranslation = new( + "single-generation-message-translation", + new ModelRequest + { + Model = "qwen-mt-plus", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("博客园的理念是代码改变世界") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + IncrementalOutput = false, + TranslationOptions = new TextGenerationTranslationOptions() + { + SourceLang = "Chinese", + TargetLang = "English", + Domains = "This text is a promotion.", + Terms = new List() { new("博客园", "cnblogs") }, + TmList = new List() { new("代码改变世界", "Coding changes world") } + } + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + FinishReason = "stop", + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "The concept of cnblogs is that coding changes world "), + } + } + }, + RequestId = "bf86e0f9-a8a2-9b32-be8d-ea3cae47c8ea", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 122, + OutputTokens = 11, + InputTokens = 111, + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageWebSearch = new( + "single-generation-message-search", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("总结博客园 dudu 的最新博客") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + EnableSearch = true, + SearchOptions = new TextGenerationSearchOptions() + { + EnableSource = true, + EnableCitation = true, + CitationFormat = "[ref_]", + ForcedSearch = true, + SearchStrategy = "standard" + } + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "截至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作为技术人员的专业知识和技术分享的热情,还反映了他对博客园这个平台的深厚感情和个人投入。如果您需要更详细的博客内容或有其他问题,请告知我以便提供进一步的帮助。"), + } + }, + SearchInfo = new TextGenerationWebSearchInfo(new List() + { + 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"), + new("博客园", "https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg", 2, "dudu - 博客园", "https://www.cnblogs.com/dudu"), + new("博客园", "https://img.alicdn.com/imgextra/i2/O1CN01FzHbv01o253A3z2Gd_!!6000000005166-55-tps-32-32.svg", 3, "dudu - 博客园", "https://www.cnblogs.com/dudu?page=36"), + new("阿里云官方网站", "https://img.alicdn.com/imgextra/i3/O1CN015NhUWq1Z1sdj3359l_!!6000000003135-55-tps-32-32.svg", 4, "玩转博客园的心路总结 - 阿里云开发者社区", "https://developer.aliyun.com/article/331235"), + 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") + }) + }, + RequestId = "80753a20-2750-9ab6-bc2a-1b851ef43efc", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 800, + OutputTokens = 304, + InputTokens = 496, + PromptTokensDetails = new TextGenerationPromptTokenDetails(0) + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageJson = new( + "single-generation-message-json", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?用 JSON 格式输出。") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = false, + ResponseFormat = DashScopeResponseFormat.Json + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant("{\n \"result\": 2\n}") + } + } + }, + RequestId = "6af9571b-1033-98f9-a287-c06f2e9d6f7f", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 34, + OutputTokens = 9, + InputTokens = 25 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageIncremental = new( + "single-generation-message", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = true + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何情况下 1 加上另一个 1 的结果都是 2。") + } + } + }, + RequestId = "d272255f-82d7-9cc7-93c5-17ff77024349", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 48, + OutputTokens = 40, + InputTokens = 8 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageReasoningIncremental = new( + "single-generation-message-reasoning", + new ModelRequest + { + Model = "qwen-plus-latest", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + IncrementalOutput = true, + ResultFormat = ResultFormats.Message, + EnableThinking = true, + ThinkingBudget = 10 + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "1+1 等于 **2**。这是数学中最基本的加法运算之一。\n\n如果你有其他关于数学、科学或任何领域的问题,欢迎继续提问!😊", + null, + null, + "嗯,用户问的是“1+1是多少") + } + } + }, + RequestId = "ab9f3446-9bbf-963e-9754-2d6543343d7e", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 69, + OutputTokens = 53, + InputTokens = 16, + OutputTokensDetails = new TextGenerationOutputTokenDetails(ReasoningTokens: 10) + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + SingleMessageChatClientIncremental = new( + "single-generation-message", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("请问 1+1 是多少?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { "你好" }, + IncrementalOutput = true, + ToolChoice = ToolChoice.AutoChoice + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "1+1 等于 2。这是最基本的数学加法之一,在十进制计数体系中,任何情况下 1 加上另一个 1 的结果都是 2。") + } + } + }, + RequestId = "d272255f-82d7-9cc7-93c5-17ff77024349", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 48, + OutputTokens = 40, + InputTokens = 8 + } + }); + + public static readonly + RequestSnapshot, + ModelResponse> SingleMessageWithTools = + new( + "single-generation-message-with-tools", + new ModelRequest + { + Model = "qwen-max", + Input = new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("杭州现在的天气如何?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + PresencePenalty = 1.2f, + Temperature = 0.85f, + Stop = new TextGenerationStop("你好"), + EnableSearch = false, + IncrementalOutput = false, + Tools = + new List + { + new( + "function", + new FunctionDefinition( + "get_current_weather", + "获取现在的天气", + new JsonSchemaBuilder().FromType( + new SchemaGeneratorConfiguration + { + PropertyNameResolver = + PropertyNameResolvers.LowerSnakeCase + }) + .Build())) + }, + ToolChoice = ToolChoice.FunctionChoice("get_current_weather") + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + string.Empty, + toolCalls: + new List + { + new( + "call_cec4c19d27624537b583af", + ToolTypes.Function, + 0, + new FunctionCall( + "get_current_weather", + "{\"location\": \"浙江省杭州市\"}")) + }) + } + } + }, + RequestId = "67300049-c108-9987-b1c1-8e0ee2de6b5d", + Usage = new TextGenerationTokenUsage + { + InputTokens = 211, + OutputTokens = 8, + TotalTokens = 219 + } + }); + + public static readonly + RequestSnapshot, + ModelResponse> SingleMessageChatClientWithTools = + new( + "single-generation-message-with-tools", + new ModelRequest + { + Model = "qwen-max", + Input = new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("杭州现在的天气如何?") } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + PresencePenalty = 1.2f, + Temperature = 0.85f, + Tools = + new List + { + new( + "function", + new FunctionDefinition( + "get_current_weather", + "获取现在的天气", + new JsonSchemaBuilder().FromType( + new SchemaGeneratorConfiguration + { + PropertyNameResolver = + PropertyNameResolvers.LowerSnakeCase + }) + .Build())) + }, + ToolChoice = ToolChoice.FunctionChoice("get_current_weather") + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + string.Empty, + toolCalls: + new List + { + new( + "call_cec4c19d27624537b583af", + ToolTypes.Function, + 0, + new FunctionCall( + "get_current_weather", + "{\"location\": \"浙江省杭州市\"}")) + }) + } + } + }, + RequestId = "67300049-c108-9987-b1c1-8e0ee2de6b5d", + Usage = new TextGenerationTokenUsage + { + InputTokens = 211, + OutputTokens = 8, + TotalTokens = 219 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + ConversationPartialMessageNoSse = new( + "conversation-generation-message-partial", + new ModelRequest + { + Model = "qwen-max", + Input = new TextGenerationInput + { + Messages = + new List + { + TextChatMessage.User("请对“春天来了,大地”这句话进行续写,来表达春天的美好和作者的喜悦之情"), + TextChatMessage.Assistant("春天来了,大地", true) + } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = ResultFormats.Message, + Seed = 1234, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false + } + }, + new ModelResponse + { + RequestId = "4c45d7fd-3158-9ff4-96a0-6e92c710df2c", + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = + TextChatMessage.Assistant( + "仿佛从漫长的冬眠中苏醒过来,万物复苏。嫩绿的小草悄悄地探出了头,争先恐后地想要沐浴在温暖的阳光下;五彩斑斓的花朵也不甘示弱,竞相绽放着自己最美丽的姿态,将田野、山林装扮得分外妖娆。微风轻轻吹过,带来了泥土的气息与花香混合的独特香味,让人心旷神怡。小鸟们开始忙碌起来,在枝头欢快地歌唱,似乎也在庆祝这个充满希望的新季节的到来。这一切美好景象不仅让人感受到了大自然的魅力所在,更激发了人们对生活无限热爱和向往的心情。") + } + } + }, + Usage = new TextGenerationTokenUsage + { + TotalTokens = 165, + OutputTokens = 131, + InputTokens = 34 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + ConversationMessageIncremental = new( + "conversation-generation-message", + new ModelRequest + { + Model = "qwen-max", + Input = + new TextGenerationInput + { + Messages = + new List + { + TextChatMessage.User("现在请你记住一个数字,42"), + TextChatMessage.Assistant("好的,我已经记住了这个数字。"), + TextChatMessage.User("请问我刚才提到的数字是多少?") + } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = true + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant("您刚才提到的数字是42。") + } + } + }, + RequestId = "9188e907-56c2-9849-97f6-23f130f7fed7", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 33, + OutputTokens = 9, + InputTokens = 24 + } + }); + + public static readonly RequestSnapshot, + ModelResponse> + ConversationMessageWithFilesIncremental = new( + "conversation-generation-message-with-files", + new ModelRequest + { + Model = "qwen-long", + Input = + new TextGenerationInput + { + Messages = + new List + { + TextChatMessage.File( + new List + { + "file-fe-WTTG89tIUTd4ByqP3K48R3bn", + "file-fe-l92iyRvJm9vHCCfonLckf1o2" + }), + TextChatMessage.User("这两个文件是相同的吗?") + } + }, + Parameters = new TextGenerationParameters + { + ResultFormat = "message", + Seed = 1234, + MaxTokens = 1500, + TopP = 0.8f, + TopK = 100, + RepetitionPenalty = 1.1f, + Temperature = 0.85f, + Stop = new[] { new[] { 37763, 367 } }, + EnableSearch = false, + IncrementalOutput = true + } + }, + new ModelResponse + { + Output = new TextGenerationOutput + { + Choices = + new List + { + new() + { + FinishReason = "stop", + Message = TextChatMessage.Assistant( + "你上传的两个文件并不相同。第一个文件`test1.txt`包含两行文本,每行都是“测试”。而第二个文件`test2.txt`只有一行文本,“测试2”。尽管它们都含有“测试”这个词,但具体内容和结构不同。") + } + } + }, + RequestId = "7865ae43-8379-9c79-bef6-95050868bc52", + Usage = new TextGenerationTokenUsage + { + TotalTokens = 115, + OutputTokens = 57, + InputTokens = 58 + } + }); + } + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.cs similarity index 87% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.cs index ab61622..fcd442d 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Snapshots.cs @@ -1,6 +1,6 @@ using Cnblogs.DashScope.Core; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public static partial class Snapshots { @@ -12,13 +12,29 @@ public static readonly "tokenization", new ModelRequest { - Input = new TextGenerationInput { Messages = [TextChatMessage.User("代码改变世界")] }, + Input = new TextGenerationInput + { + Messages = + new List { TextChatMessage.User("代码改变世界") }.AsReadOnly() + }, Model = "qwen-max", Parameters = new TextGenerationParameters { Seed = 1234 } }, new ModelResponse { - Output = new TokenizationOutput([46100, 101933, 99489], ["代码", "改变", "世界"]), + Output = new TokenizationOutput( + new List + { + 46100, + 101933, + 99489 + }, + new List + { + "代码", + "改变", + "世界" + }), Usage = new TokenizationUsage(3), RequestId = "6615ba01-081d-9147-93ff-7bd26f3adf93" }); @@ -119,7 +135,7 @@ public static readonly public static class File { - public static readonly FileInfo TestFile = new FileInfo("RawHttpData/test1.txt"); + public static readonly FileInfo TestFile = new("RawHttpData/test1.txt"); public static readonly RequestSnapshot UploadFileNoSse = new( "upload-file", @@ -134,22 +150,23 @@ public static class File new DashScopeFileList( "list", false, - [ - new DashScopeFile( + new List + { + new( "file-fe-qBKjZKfTx64R9oYmwyovNHBH", "file", 6, 1720582024, "test1.txt", "file-extract"), - new DashScopeFile( + new( "file-fe-WTTG89tIUTd4ByqP3K48R3bn", "file", 6, 1720535665, "test1.txt", "file-extract") - ])); + })); public static readonly RequestSnapshot DeleteFileNoSse = new( "delete-file", diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/SocketMessageSnapshot.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/SocketMessageSnapshot.cs new file mode 100644 index 0000000..7c94879 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/SocketMessageSnapshot.cs @@ -0,0 +1,12 @@ +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public record SocketMessageSnapshot(string GroupName, string MessageName) +{ + public string GetMessageJson() + { + return File.ReadAllText(Path.Combine("RawHttpData", $"socket-{GroupName}.{MessageName}.json")); + } +} + +public record SocketMessageSnapshot(string GroupName, string MessageName, TMessage Message) + : SocketMessageSnapshot(GroupName, MessageName); diff --git a/test/Cnblogs.DashScope.Tests.Shared/Utils/Sut.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/Sut.cs new file mode 100644 index 0000000..db1e550 --- /dev/null +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/Sut.cs @@ -0,0 +1,47 @@ +using Cnblogs.DashScope.Core; +using Cnblogs.DashScope.Core.Internals; +using NSubstitute; +using NSubstitute.Extensions; + +namespace Cnblogs.DashScope.Tests.Shared.Utils; + +public static class Sut +{ + public static async Task<(IDashScopeClient Client, MockHttpMessageHandler Handler)> GetTestClientAsync( + bool sse, + RequestSnapshot testCase) + { + var pair = GetTestClient(); + var expected = await testCase.ToResponseMessageAsync(sse); + pair.Handler.Configure().MockSend(Arg.Any(), Arg.Any()) + .Returns(expected); + return pair; + } + + public static (DashScopeClientCore Client, MockHttpMessageHandler Handler) GetTestClient() + { + var handler = Substitute.ForPartsOf(); + var client = new DashScopeClientCore( + new HttpClient(handler) { BaseAddress = new Uri("https://example.com") }, + new DashScopeClientWebSocketPool(new DashScopeClientWebSocketFactory(), new DashScopeOptions())); + return (client, handler); + } + + // IClientWebSocket is internal, use InternalVisibleToAttribute make it visible to Cnblogs.DashScope.Sdk.UnitTests + internal static async + Task<(DashScopeClientCore Client, DashScopeClientWebSocket ClientWebSocket, FakeClientWebSocket Server)> + GetSocketTestClientAsync() + { + var socket = new FakeClientWebSocket(); + var dsWebSocket = new DashScopeClientWebSocket(socket); + await dsWebSocket.ConnectAsync( + new Uri(DashScopeDefaults.WebsocketApiBaseAddress), + CancellationToken.None); + dsWebSocket.ResetOutput(); + var pool = new DashScopeClientWebSocketPool( + new List { dsWebSocket }, + new DashScopeClientWebSocketFactory()); + var client = new DashScopeClientCore(new HttpClient(), pool); + return (client, dsWebSocket, socket); + } +} diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/TestApplicationBizParam.cs b/test/Cnblogs.DashScope.Tests.Shared/Utils/TestApplicationBizParam.cs similarity index 75% rename from test/Cnblogs.DashScope.Sdk.UnitTests/Utils/TestApplicationBizParam.cs rename to test/Cnblogs.DashScope.Tests.Shared/Utils/TestApplicationBizParam.cs index a1274f4..66c6a27 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Utils/TestApplicationBizParam.cs +++ b/test/Cnblogs.DashScope.Tests.Shared/Utils/TestApplicationBizParam.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace Cnblogs.DashScope.Sdk.UnitTests.Utils; +namespace Cnblogs.DashScope.Tests.Shared.Utils; public record TestApplicationBizParam( [property: JsonPropertyName("sourceCode")]