From 00bf26326b37751b59b42aa84d03a316bd80bac3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:21:23 +0000 Subject: [PATCH 01/13] build(deps): bump JsonSchema.Net.Generation from 4.6.0 to 5.0.0 Bumps [JsonSchema.Net.Generation](https://github.com/json-everything/json-everything) from 4.6.0 to 5.0.0. - [Commits](https://github.com/json-everything/json-everything/compare/schema-gen-v4.6.0...logic-v5.0.0) --- updated-dependencies: - dependency-name: JsonSchema.Net.Generation dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj b/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj index 2d88884..3480ef8 100644 --- a/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj +++ b/src/Cnblogs.DashScope.Sdk/Cnblogs.DashScope.Sdk.csproj @@ -5,7 +5,7 @@ Cnblogs;Dashscope;AI;Sdk;Embedding; - + From cde0e9955cabd3ad3f2bef8905736f2e01054b30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:21:45 +0000 Subject: [PATCH 02/13] build(deps): bump coverlet.collector from 6.0.2 to 6.0.3 Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 6.0.2 to 6.0.3. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/compare/v6.0.2...v6.0.3) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85dc33c..8e9174b 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 8249f0672c3f163aac7129aa5a04d26e6201a033 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 01:36:33 +0000 Subject: [PATCH 03/13] build(deps): bump xunit from 2.9.2 to 2.9.3 Bumps [xunit](https://github.com/xunit/xunit) from 2.9.2 to 2.9.3. - [Commits](https://github.com/xunit/xunit/compare/v2-2.9.2...v2-2.9.3) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85dc33c..2fac3d2 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 45b663fa3f14df416b4bd69073f338f9c0465006 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 01:40:06 +0000 Subject: [PATCH 04/13] build(deps): bump xunit.runner.visualstudio from 3.0.0 to 3.0.1 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/3.0.0...3.0.1) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2fac3d2..af12904 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 2cadb79f90095f057fb97337a6d5d70e71b52a4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 01:26:36 +0000 Subject: [PATCH 05/13] build(deps): bump coverlet.collector from 6.0.3 to 6.0.4 Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 6.0.3 to 6.0.4. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/compare/v6.0.3...v6.0.4) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c842860..643aa0b 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From bbfe7c843de7fd7e853ef63a81695c5a3bccb871 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 01:27:07 +0000 Subject: [PATCH 06/13] build(deps): bump Microsoft.ML.Tokenizers from 1.0.0 to 1.0.1 Bumps [Microsoft.ML.Tokenizers](https://github.com/dotnet/machinelearning) from 1.0.0 to 1.0.1. - [Release notes](https://github.com/dotnet/machinelearning/releases) - [Commits](https://github.com/dotnet/machinelearning/commits) --- updated-dependencies: - dependency-name: Microsoft.ML.Tokenizers dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj index a9262bd..35ea530 100644 --- a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj +++ b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj @@ -8,7 +8,7 @@ - + From 49fa9e52a1ba25608f0e86470300de8718dcad49 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 01:27:22 +0000 Subject: [PATCH 07/13] build(deps): bump FluentAssertions from 7.0.0 to 8.0.1 Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 7.0.0 to 8.0.1. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/main/AcceptApiChanges.ps1) - [Commits](https://github.com/fluentassertions/fluentassertions/compare/7.0.0...8.0.1) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c842860..ae80a83 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -10,7 +10,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 5fb5a9e7b8882dc4ebbf7b17268b3a23446e36ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Mon, 27 Jan 2025 19:18:35 +0800 Subject: [PATCH 08/13] fix: migrate fluent assertion api --- test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs index 997f1d4..8f91a35 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/QWenTokenizerTests.cs @@ -517,6 +517,6 @@ public void QWenTokenizer_CountIndex_SuccessAsync() // Assert maxIndex.Should().Be(155); - tokenCount.Should().BeLessOrEqualTo(100); + tokenCount.Should().BeLessThanOrEqualTo(100); } } From 1ca448a42c1e7d69be43580c845f6e7204437d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Mon, 27 Jan 2025 19:26:38 +0800 Subject: [PATCH 09/13] feat: add qvq-72b-preview --- src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs | 5 +++++ src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs index 6a55c06..b8dbc98 100644 --- a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs +++ b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlm.cs @@ -129,4 +129,9 @@ public enum QWenLlm /// qwen-coder-turbo-latest /// QWenCoderTurboLatest = 24, + + /// + /// qvq-72b-preview + /// + QwQ72BPreview = 25 } diff --git a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs index 6e09718..8bc299e 100644 --- a/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs +++ b/src/Cnblogs.DashScope.Sdk/QWen/QWenLlmNames.cs @@ -30,6 +30,7 @@ public static string GetModelName(this QWenLlm llm) QWenLlm.QWenPlusLatest => "qwen-plus-latest", QWenLlm.QWenTurboLatest => "qwen-turbo-latest", QWenLlm.QwQ32BPreview => "qwq-32b-preview", + QWenLlm.QwQ72BPreview => "qwq-72b-preview", _ => ThrowHelper.UnknownModelName(nameof(llm), llm) }; } From 2a6a28b98ffb0dcc85d138d5b967b051109b1a9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 01:22:24 +0000 Subject: [PATCH 10/13] build(deps): bump xunit.runner.visualstudio from 3.0.1 to 3.0.2 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 3.0.1 to 3.0.2. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/3.0.1...3.0.2) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dd511be..9a5dc86 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 7448875b107b10e6e958cb24e121913e994e185f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 01:12:10 +0000 Subject: [PATCH 11/13] build(deps): bump FluentAssertions from 8.0.1 to 8.1.1 Bumps [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 8.0.1 to 8.1.1. - [Release notes](https://github.com/fluentassertions/fluentassertions/releases) - [Changelog](https://github.com/fluentassertions/fluentassertions/blob/main/AcceptApiChanges.ps1) - [Commits](https://github.com/fluentassertions/fluentassertions/compare/8.0.1...8.1.1) --- updated-dependencies: - dependency-name: FluentAssertions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dd511be..7e461a4 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -10,7 +10,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 38c65986ea5b4e6a8f58353d0bb790f2bab13a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Fri, 7 Mar 2025 14:18:00 +0800 Subject: [PATCH 12/13] chore: upgrade ms extensions ai to 9.3.0 --- sample/Cnblogs.DashScope.Sample/Program.cs | 2 +- .../ToolCallWithExtensions.cs | 2 +- .../Cnblogs.DashScope.AI.csproj | 2 +- .../DashScopeChatClient.cs | 58 +++++++++---------- .../ChatClientTests.cs | 12 ++-- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/sample/Cnblogs.DashScope.Sample/Program.cs b/sample/Cnblogs.DashScope.Sample/Program.cs index 8245f17..c5958f3 100644 --- a/sample/Cnblogs.DashScope.Sample/Program.cs +++ b/sample/Cnblogs.DashScope.Sample/Program.cs @@ -211,7 +211,7 @@ async Task ChatWithMicrosoftExtensions() new(ChatRole.System, "You are a helpful AI assistant"), new(ChatRole.User, "What is AI?") ]; - var response = await chatClient.CompleteAsync(conversation); + var response = await chatClient.GetResponseAsync(conversation); var serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web) { WriteIndented = true }; Console.WriteLine(JsonSerializer.Serialize(response, serializerOptions)); } diff --git a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs index f170c7f..ab3296a 100644 --- a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs +++ b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs @@ -15,7 +15,7 @@ public static async Task ToolCallWithExtensionAsync(this IDashScopeClient dashSc var chatOptions = new ChatOptions { Tools = [AIFunctionFactory.Create(GetWeather)] }; var client = dashScopeClient.AsChatClient("qwen-max").AsBuilder().UseFunctionInvocation().Build(); - await foreach (var message in client.CompleteStreamingAsync("What is weather today?", chatOptions)) + await foreach (var message in client.GetStreamingResponseAsync("What is weather today?", chatOptions)) { Console.WriteLine(JsonSerializer.Serialize(message)); } diff --git a/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj b/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj index 8a22a11..fe758a6 100644 --- a/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj +++ b/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs index b1c69f2..8b0012f 100644 --- a/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs +++ b/src/Cnblogs.DashScope.AI/DashScopeChatClient.cs @@ -34,7 +34,6 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId) _dashScopeClient = dashScopeClient; _modelId = modelId; - Metadata = new ChatClientMetadata("dashscope", _dashScopeClient.BaseAddress, _modelId); } /// @@ -43,7 +42,7 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId) public JsonSerializerOptions ToolCallJsonSerializerOptions { get; set; } = new(JsonSerializerDefaults.Web); /// - public async Task CompleteAsync( + public async Task GetResponseAsync( IList chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) @@ -52,7 +51,6 @@ public async Task CompleteAsync( var useVlRaw = options?.AdditionalProperties?.GetValueOrDefault("useVl")?.ToString(); var useVl = string.IsNullOrEmpty(useVlRaw) ? modelId.Contains("qwen-vl", StringComparison.OrdinalIgnoreCase) - || chatMessages.Any(c => c.Contents.Any(m => m is ImageContent)) : string.Equals(useVlRaw, "true", StringComparison.OrdinalIgnoreCase); if (useVl) { @@ -71,10 +69,10 @@ public async Task CompleteAsync( }; returnMessage.Contents.Add(new TextContent(response.Output.Choices[0].Message.Content[0].Text)); - var completion = new ChatCompletion(returnMessage) + var completion = new ChatResponse(returnMessage) { RawRepresentation = response, - CompletionId = response.RequestId, + ResponseId = response.RequestId, CreatedAt = DateTimeOffset.Now, ModelId = modelId, FinishReason = ToFinishReason(response.Output.Choices[0].FinishReason), @@ -107,10 +105,10 @@ public async Task CompleteAsync( }, cancellationToken); var returnMessage = ToChatMessage(response.Output.Choices![0].Message); - var completion = new ChatCompletion(returnMessage) + var completion = new ChatResponse(returnMessage) { RawRepresentation = response, - CompletionId = response.RequestId, + ResponseId = response.RequestId, CreatedAt = DateTimeOffset.Now, ModelId = modelId, FinishReason = ToFinishReason(response.Output.Choices[0].FinishReason), @@ -131,15 +129,14 @@ public async Task CompleteAsync( } /// - public async IAsyncEnumerable CompleteStreamingAsync( + public async IAsyncEnumerable GetStreamingResponseAsync( IList chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { var useVlRaw = options?.AdditionalProperties?.GetValueOrDefault("useVl")?.ToString(); - var useVl = string.IsNullOrEmpty(useVlRaw) - ? chatMessages.Any(c => c.Contents.Any(m => m is ImageContent)) - : string.Equals(useVlRaw, "true", StringComparison.OrdinalIgnoreCase); + var useVl = string.Equals(useVlRaw, "true", StringComparison.OrdinalIgnoreCase) + || (options?.ModelId?.Contains("qwen-vl") ?? false); var modelId = options?.ModelId ?? _modelId; ChatRole? streamedRole = null; @@ -167,9 +164,9 @@ public async IAsyncEnumerable CompleteStreamingAs : ToFinishReason(response.Output.Choices[0].FinishReason); completionId ??= response.RequestId; - var update = new StreamingChatCompletionUpdate() + var update = new ChatResponseUpdate() { - CompletionId = completionId, + ResponseId = completionId, CreatedAt = DateTimeOffset.Now, FinishReason = finishReason, ModelId = modelId, @@ -201,10 +198,10 @@ public async IAsyncEnumerable CompleteStreamingAs if (options?.Tools is { Count: > 0 }) { // qwen does not support streaming with function call, fallback to non-streaming - var completion = await CompleteAsync(chatMessages, options, cancellationToken); - yield return new StreamingChatCompletionUpdate() + var completion = await GetResponseAsync(chatMessages, options, cancellationToken); + yield return new ChatResponseUpdate() { - CompletionId = completion.CompletionId, + ResponseId = completion.ResponseId, Role = completion.Message.Role, AdditionalProperties = completion.AdditionalProperties, Contents = completion.Message.Contents, @@ -241,9 +238,9 @@ public async IAsyncEnumerable CompleteStreamingAs : ToFinishReason(response.Output.Choices[0].FinishReason); completionId ??= response.RequestId; - var update = new StreamingChatCompletionUpdate() + var update = new ChatResponseUpdate() { - CompletionId = completionId, + ResponseId = completionId, CreatedAt = DateTimeOffset.Now, FinishReason = finishReason, ModelId = modelId, @@ -289,9 +286,6 @@ public void Dispose() // nothing to dispose. } - /// - public ChatClientMetadata Metadata { get; } - private static ChatFinishReason? ToFinishReason(string? finishReason) => string.IsNullOrEmpty(finishReason) ? null @@ -398,10 +392,12 @@ private List ToMultimodalMessageContents(IList MultimodalMessageContent.TextContent(text.Text), - ImageContent { Data.Length: > 0 } image => MultimodalMessageContent.ImageContent( - image.Data.Value.Span, - image.MediaType ?? throw new InvalidOperationException("image media type should not be null")), - ImageContent { Uri: { } uri } => MultimodalMessageContent.ImageContent(uri), + DataContent { Data.Length: > 0 } data when data.MediaTypeStartsWith("image") => + MultimodalMessageContent.ImageContent( + data.Data.Value.Span, + data.MediaType ?? throw new InvalidOperationException("image media type should not be null")), + DataContent { Uri: { } uri } data when data.MediaTypeStartsWith("image") => + MultimodalMessageContent.ImageContent(uri), _ => null }; if (content is not null) @@ -513,15 +509,13 @@ RequiredChatToolMode required when string.IsNullOrEmpty(required.RequiredFunctio f => new ToolDefinition( "function", new FunctionDefinition( - f.Metadata.Name, - f.Metadata.Description, - GetParameterSchema(f.Metadata.Parameters)))); + f.Name, + f.Description, + GetParameterSchema(f.JsonSchema)))); } - private static JsonSchema GetParameterSchema(IEnumerable metadata) + private static JsonSchema GetParameterSchema(JsonElement metadata) { - return new JsonSchemaBuilder() - .Properties(metadata.Select(c => (c.Name, Schema: c.Schema as JsonSchema ?? EmptyObjectSchema)).ToArray()) - .Build(); + return metadata.Deserialize() ?? EmptyObjectSchema; } } diff --git a/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs b/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs index 9a58f70..89ac79c 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs @@ -26,7 +26,7 @@ public async Task ChatClient_TextCompletion_SuccessAsync() var parameter = testCase.RequestModel.Parameters; // Act - var response = await client.CompleteAsync( + var response = await client.GetResponseAsync( content, new ChatOptions() { @@ -67,7 +67,7 @@ public async Task ChatClient_TextCompletionStream_SuccessAsync() var parameter = testCase.RequestModel.Parameters; // Act - var response = client.CompleteStreamingAsync( + var response = client.GetStreamingResponseAsync( content, new ChatOptions() { @@ -113,12 +113,12 @@ public async Task ChatClient_ImageRecognition_SuccessAsync() { new( ChatRole.User, - [new ImageContent(contents[0].Image!), new TextContent(contents[1].Text)]) + [new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text)]) }; var parameter = testCase.RequestModel.Parameters; // Act - var response = await client.CompleteAsync( + var response = await client.GetResponseAsync( messages, new ChatOptions { @@ -157,12 +157,12 @@ public async Task ChatClient_ImageRecognitionStream_SuccessAsync() { new( ChatRole.User, - [new ImageContent(contents[0].Image!), new TextContent(contents[1].Text)]) + [new DataContent(contents[0].Image!, "image/png"), new TextContent(contents[1].Text)]) }; var parameter = testCase.RequestModel.Parameters; // Act - var response = client.CompleteStreamingAsync( + var response = client.GetStreamingResponseAsync( messages, new ChatOptions() { From ce3c707556a99669308bf27eeeb483d612276a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Fri, 7 Mar 2025 14:35:13 +0800 Subject: [PATCH 13/13] chore: upgrade sample prompt for better consistency --- .../Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj | 2 +- sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs | 4 ++-- src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj index a5cb962..a7ba2f0 100644 --- a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj +++ b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj @@ -20,7 +20,7 @@ - + diff --git a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs index ab3296a..0c30cd4 100644 --- a/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs +++ b/sample/Cnblogs.DashScope.Sample/ToolCallWithExtensions.cs @@ -10,12 +10,12 @@ public static class ToolCallWithExtensions public static async Task ToolCallWithExtensionAsync(this IDashScopeClient dashScopeClient) { [Description("Gets the weather")] - string GetWeather() => Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining"; + string GetWeather(string location) => Random.Shared.NextDouble() > 0.5 ? "It's sunny" : "It's raining"; var chatOptions = new ChatOptions { Tools = [AIFunctionFactory.Create(GetWeather)] }; var client = dashScopeClient.AsChatClient("qwen-max").AsBuilder().UseFunctionInvocation().Build(); - await foreach (var message in client.GetStreamingResponseAsync("What is weather today?", chatOptions)) + await foreach (var message in client.GetStreamingResponseAsync("What is weather of LA today?", chatOptions)) { Console.WriteLine(JsonSerializer.Serialize(message)); } diff --git a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj index 35ea530..791029d 100644 --- a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj +++ b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj @@ -8,7 +8,7 @@ - +