From d5765c50fc080d349e7540af1100ba69d7e69db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 4 Dec 2025 14:22:18 +0800 Subject: [PATCH 1/4] feat: add net8.0 into target frameworks --- .github/workflows/ci.yml | 8 ++++---- Directory.Build.props | 2 +- .../Cnblogs.DashScope.Sample.csproj | 2 +- src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj | 1 + src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj | 3 +++ .../Cnblogs.DashScope.AI.UnitTests.csproj | 2 +- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 2 +- .../Cnblogs.DashScope.Tests.Shared.csproj | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 681349e..095f3af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,9 +14,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Build - run: dotnet build src/Cnblogs.DashScope.AspNetCore -c Release + run: dotnet build src/Cnblogs.DashScope.AspNetCore -c Release -p:TargetFrameworks=net6.0 - name: Test - run: dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release + run: dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release -p:TargetFrameworks=net6.0 test-net8: runs-on: ubuntu-latest container: mcr.microsoft.com/dotnet/sdk:8.0 @@ -24,7 +24,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Build - run: dotnet build src/Cnblogs.DashScope.AI -c Release + run: dotnet build src/Cnblogs.DashScope.AI -c Release -p:TargetFrameworks=net8.0 - name: Test - run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release + run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release -p:TargetFrameworks=net8.0 diff --git a/Directory.Build.props b/Directory.Build.props index 3eaabd9..c98ba0c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net6.0 + net6.0;net8.0 enable enable Cnblogs diff --git a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj index 00a1318..1929eb1 100644 --- a/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj +++ b/sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net8.0 enable enable false diff --git a/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj b/src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj index d75ae37..039cbfe 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; diff --git a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj index 7dd23dd..c5fab03 100644 --- a/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj +++ b/src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj @@ -13,6 +13,9 @@ + + + diff --git a/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj b/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj index 82cd87a..063acd8 100644 --- a/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj +++ b/test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj @@ -1,7 +1,7 @@  - net8.0 + net8.0 enable enable false 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 11240e0..2fd5793 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj index f4a861c..95b270f 100644 --- a/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj +++ b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj @@ -9,7 +9,7 @@ - + From 0d4037201b490125833225e74ee6d2f5b81df1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 4 Dec 2025 14:26:43 +0800 Subject: [PATCH 2/4] fix: run full tests on net8.0 --- .github/workflows/ci.yml | 2 +- .../Cnblogs.DashScope.Tests.Shared.csproj | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 095f3af..710cf4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,5 +26,5 @@ jobs: - name: Build run: dotnet build src/Cnblogs.DashScope.AI -c Release -p:TargetFrameworks=net8.0 - name: Test - run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release -p:TargetFrameworks=net8.0 + run: dotnet test -p:TargetFrameworks=net8.0 diff --git a/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj index 95b270f..62e5330 100644 --- a/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj +++ b/test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj @@ -1,7 +1,6 @@ - net6.0 enable enable false From 9977a2854f427ae8e5fbe6f571575549a2b6c6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 4 Dec 2025 14:40:09 +0800 Subject: [PATCH 3/4] fix: update test command --- .github/workflows/ci.yml | 2 +- .../DashScopeClientCore.cs | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 710cf4f..6ec5b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,5 +26,5 @@ jobs: - name: Build run: dotnet build src/Cnblogs.DashScope.AI -c Release -p:TargetFrameworks=net8.0 - name: Test - run: dotnet test -p:TargetFrameworks=net8.0 + run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release -p:TargetFrameworks=net8.0 && dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release -p:TargetFrameworks=net8.0 diff --git a/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs b/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs index 72c8c69..5041955 100644 --- a/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs +++ b/src/Cnblogs.DashScope.Core/DashScopeClientCore.cs @@ -552,28 +552,31 @@ private async IAsyncEnumerable StreamAsync( HttpCompletionOption.ResponseHeadersRead, cancellationToken); using StreamReader reader = new(await response.Content.ReadAsStreamAsync(cancellationToken), Encoding.UTF8); - while (!reader.EndOfStream) + while (await reader.ReadLineAsync() is { } line) { if (cancellationToken.IsCancellationRequested) + { throw new TaskCanceledException(); + } + + if (line.StartsWith("data:") == false) + { + continue; + } - var line = await reader.ReadLineAsync(); - if (line != null && line.StartsWith("data:")) + var data = line["data:".Length..]; + if (data.StartsWith("{\"code\":")) { - var data = line["data:".Length..]; - if (data.StartsWith("{\"code\":")) - { - var error = - JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; - throw new DashScopeException( - message.RequestUri?.ToString(), - (int)response.StatusCode, - error, - error.Message); - } - - yield return JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; + var error = + JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; + throw new DashScopeException( + message.RequestUri?.ToString(), + (int)response.StatusCode, + error, + error.Message); } + + yield return JsonSerializer.Deserialize(data, DashScopeDefaults.SerializationOptions)!; } } From de8022749cd42b5e37220fd7940c34694d8deebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=98=9F=E7=B9=81?= Date: Thu, 4 Dec 2025 15:31:43 +0800 Subject: [PATCH 4/4] fix: remove net6 framework settings --- .../Cnblogs.DashScope.Sdk.UnitTests.csproj | 1 - 1 file changed, 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 2fd5793..cd35c5f 100644 --- a/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj +++ b/test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj @@ -1,7 +1,6 @@ - net6.0 false true