Skip to content

Commit 3674a3b

Browse files
authored
chore: remove json ref on net8.0 (#158)
* feat: add net8.0 into target frameworks * fix: run full tests on net8.0 * fix: update test command * fix: remove net6 framework settings
1 parent 50e0dc3 commit 3674a3b

File tree

9 files changed

+32
-27
lines changed

9 files changed

+32
-27
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ jobs:
1414
- name: Checkout
1515
uses: actions/checkout@v4
1616
- name: Build
17-
run: dotnet build src/Cnblogs.DashScope.AspNetCore -c Release
17+
run: dotnet build src/Cnblogs.DashScope.AspNetCore -c Release -p:TargetFrameworks=net6.0
1818
- name: Test
19-
run: dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release
19+
run: dotnet test test/Cnblogs.DashScope.Sdk.UnitTests -c Release -p:TargetFrameworks=net6.0
2020
test-net8:
2121
runs-on: ubuntu-latest
2222
container: mcr.microsoft.com/dotnet/sdk:8.0
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v4
2626
- name: Build
27-
run: dotnet build src/Cnblogs.DashScope.AI -c Release
27+
run: dotnet build src/Cnblogs.DashScope.AI -c Release -p:TargetFrameworks=net8.0
2828
- name: Test
29-
run: dotnet test test/Cnblogs.DashScope.AI.UnitTests -c Release
29+
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
3030

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Authors>Cnblogs</Authors>

sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFrameworks>net8.0</TargetFrameworks>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>false</IsPackable>

src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<TargetFrameworks>net8.0</TargetFrameworks>
34
<Product>Cnblogs.DashScope.AI</Product>
45
<GenerateDocumentationFile>true</GenerateDocumentationFile>
56
<PackageTags>Cnblogs;Dashscope;Microsoft.Extensions.AI;Sdk;Embedding;</PackageTags>

src/Cnblogs.DashScope.Core/Cnblogs.DashScope.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
16+
</ItemGroup>
17+
18+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
1619
<PackageReference Include="System.Text.Json" Version="8.0.6" />
1720
</ItemGroup>
1821

src/Cnblogs.DashScope.Core/DashScopeClientCore.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -552,28 +552,31 @@ private async IAsyncEnumerable<TResponse> StreamAsync<TResponse>(
552552
HttpCompletionOption.ResponseHeadersRead,
553553
cancellationToken);
554554
using StreamReader reader = new(await response.Content.ReadAsStreamAsync(cancellationToken), Encoding.UTF8);
555-
while (!reader.EndOfStream)
555+
while (await reader.ReadLineAsync() is { } line)
556556
{
557557
if (cancellationToken.IsCancellationRequested)
558+
{
558559
throw new TaskCanceledException();
560+
}
561+
562+
if (line.StartsWith("data:") == false)
563+
{
564+
continue;
565+
}
559566

560-
var line = await reader.ReadLineAsync();
561-
if (line != null && line.StartsWith("data:"))
567+
var data = line["data:".Length..];
568+
if (data.StartsWith("{\"code\":"))
562569
{
563-
var data = line["data:".Length..];
564-
if (data.StartsWith("{\"code\":"))
565-
{
566-
var error =
567-
JsonSerializer.Deserialize<DashScopeError>(data, DashScopeDefaults.SerializationOptions)!;
568-
throw new DashScopeException(
569-
message.RequestUri?.ToString(),
570-
(int)response.StatusCode,
571-
error,
572-
error.Message);
573-
}
574-
575-
yield return JsonSerializer.Deserialize<TResponse>(data, DashScopeDefaults.SerializationOptions)!;
570+
var error =
571+
JsonSerializer.Deserialize<DashScopeError>(data, DashScopeDefaults.SerializationOptions)!;
572+
throw new DashScopeException(
573+
message.RequestUri?.ToString(),
574+
(int)response.StatusCode,
575+
error,
576+
error.Message);
576577
}
578+
579+
yield return JsonSerializer.Deserialize<TResponse>(data, DashScopeDefaults.SerializationOptions)!;
577580
}
578581
}
579582

test/Cnblogs.DashScope.AI.UnitTests/Cnblogs.DashScope.AI.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>false</IsPackable>

test/Cnblogs.DashScope.Sdk.UnitTests/Cnblogs.DashScope.Sdk.UnitTests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<IsPackable>false</IsPackable>
65
<IsTestProject>true</IsTestProject>
76
</PropertyGroup>
@@ -13,7 +12,7 @@
1312
</PackageReference>
1413
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
1514
<PackageReference Include="NSubstitute" Version="5.3.0"/>
16-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
1716
<PrivateAssets>all</PrivateAssets>
1817
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1918
</PackageReference>

test/Cnblogs.DashScope.Tests.Shared/Cnblogs.DashScope.Tests.Shared.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
76
<IsPackable>false</IsPackable>
87
</PropertyGroup>
98

109
<ItemGroup>
1110
<PackageReference Include="NSubstitute" Version="5.3.0"/>
12-
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
11+
<PackageReference Include="System.Linq.Async" Version="7.0.0" />
1312
<PackageReference Include="JsonSchema.Net.Generation" Version="4.6.0" />
1413
<PackageReference Include="xunit" Version="2.9.3" />
1514
</ItemGroup>

0 commit comments

Comments
 (0)