Skip to content

Commit

Permalink
feat: Added TrimmingHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jul 13, 2024
1 parent c6afc0c commit c00d110
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
7 changes: 7 additions & 0 deletions OpenAI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{1A00
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.Core", "src\libs\OpenAI.Generators.Core\OpenAI.Generators.Core.csproj", "{FCBE699C-CCD3-4809-8128-78956BC3F2C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrimmingHelper", "src\helpers\TrimmingHelper\TrimmingHelper.csproj", "{9F7DC3A1-B113-4577-875D-73B2DDD6647A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -73,6 +75,10 @@ Global
{FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Release|Any CPU.Build.0 = Release|Any CPU
{9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F7DC3A1-B113-4577-875D-73B2DDD6647A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -85,6 +91,7 @@ Global
{4F534836-40A3-4E75-8B71-C46CD4FBE137} = {AAA11B78-2764-4520-A97E-46AA7089A588}
{594DCFD8-E707-4232-B878-90FA3D880474} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54}
{FCBE699C-CCD3-4809-8128-78956BC3F2C3} = {61E7E11E-4558-434C-ACE8-06316A3097B3}
{9F7DC3A1-B113-4577-875D-73B2DDD6647A} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CED9A020-DBA5-4BE6-8096-75E528648EC1}
Expand Down
1 change: 1 addition & 0 deletions src/helpers/TrimmingHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Console.WriteLine("Build, rebuild or publish this app to see trimming warnings.");
30 changes: 30 additions & 0 deletions src/helpers/TrimmingHelper/TrimmingHelper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\OpenAI\OpenAI.csproj" />
</ItemGroup>

<ItemGroup>
<TrimmerRootAssembly Include="OpenAI" />
</ItemGroup>

<PropertyGroup Label="Publish">
<RuntimeIdentifier Condition="$([MSBuild]::IsOSPlatform('windows'))">win-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="!$([MSBuild]::IsOSPlatform('windows'))">osx-arm64</RuntimeIdentifier>

<SelfContained>true</SelfContained>
</PropertyGroup>

<Target Name="ProduceTrimmingWarnings" AfterTargets="Build">
<CallTarget Targets="Publish"/>
</Target>

</Project>
6 changes: 5 additions & 1 deletion src/libs/OpenAI/ChatClient.AsStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public partial class ChatClient

using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
using var reader = new StreamReader(stream);


#if NET8_0_OR_GREATER
while (await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false) is { } streamData)
#else
while (await reader.ReadLineAsync().ConfigureAwait(false) is { } streamData)
#endif
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down
9 changes: 4 additions & 5 deletions src/libs/OpenAI/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Tiktoken" Version="2.0.2" />
<PackageReference Include="Tiktoken" Version="2.0.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net4.6.2'">
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OpenAI.Constants\OpenAI.Constants.csproj" />
<ProjectReference Include="..\OpenAI.Generators\OpenAI.Generators.csproj" ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
<None Include="..\OpenAI.Generators\bin\$(Configuration)\netstandard2.0\H.Generators.Extensions.dll" Pack="true" PackagePath="analyzers/dotnet" Visible="false" />
<None Include="..\OpenAI.Generators\bin\$(Configuration)\netstandard2.0\OpenAI.Generators.Core.dll" Pack="true" PackagePath="analyzers/dotnet" Visible="false" />
Expand Down

0 comments on commit c00d110

Please sign in to comment.