Skip to content

Commit

Permalink
feat: Added initial trimming support.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Feb 26, 2024
1 parent 6750a77 commit 4000a0e
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 6 deletions.
9 changes: 9 additions & 0 deletions LangChain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebBase", "WebBase", "{ED26
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangChain.Splitters.Abstractions.Tests", "src\Splitters\Abstractions\test\LangChain.Splitters.Abstractions.Tests.csproj", "{1F76A632-BC80-4225-ABA3-2D87BBA064E9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Helpers", "Helpers", "{1325D29E-D42F-423F-A6AC-5E880BE2AB68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrimmingHelper", "src\Helpers\TrimmingHelper\TrimmingHelper.csproj", "{BEE04F82-38FB-4BB2-AB48-A73AD0104142}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -496,6 +500,10 @@ Global
{1F76A632-BC80-4225-ABA3-2D87BBA064E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F76A632-BC80-4225-ABA3-2D87BBA064E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F76A632-BC80-4225-ABA3-2D87BBA064E9}.Release|Any CPU.Build.0 = Release|Any CPU
{BEE04F82-38FB-4BB2-AB48-A73AD0104142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEE04F82-38FB-4BB2-AB48-A73AD0104142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEE04F82-38FB-4BB2-AB48-A73AD0104142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEE04F82-38FB-4BB2-AB48-A73AD0104142}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -594,6 +602,7 @@ Global
{7D97D652-AFF5-465C-8688-FC3066423707} = {ED2684D8-5229-4397-A2FB-06AF1E5A6CBC}
{16D0189E-2B4A-4B7C-B60C-CD74EF83D119} = {ED2684D8-5229-4397-A2FB-06AF1E5A6CBC}
{1F76A632-BC80-4225-ABA3-2D87BBA064E9} = {FBF5D827-0D5B-4A71-BBBF-3EAA5A5AA1C2}
{BEE04F82-38FB-4BB2-AB48-A73AD0104142} = {1325D29E-D42F-423F-A6AC-5E880BE2AB68}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C00D0F1-6138-4ED9-846B-97E43D6DFF1C}
Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/LangChain.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<NoWarn>$(NoWarn);CA1031;CA1822;CA1307;CA1002;CA1303;CA1003;CA1724;CA1034;CA1849</NoWarn>
<NoWarn>$(NoWarn);CA2227;CA2214;CA1040;CA1812;CA1720;CS9107</NoWarn>
<NoWarn>$(NoWarn);CA1308;CA1862;CA1510;CA1850;CA1305;CA1725</NoWarn>
<IsAotCompatible>false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<PropertyGroup Label="NuGet">
Expand Down
3 changes: 3 additions & 0 deletions src/Databases/Chroma/src/ChromaVectorStore.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using LangChain.Common.Converters;
using LangChain.Docstore;
Expand All @@ -14,6 +15,8 @@ namespace LangChain.Databases;
/// ChromaDB vector store.
/// According: https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
/// </summary>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public class ChromaVectorStore : VectorStore
{
private const string LangchainDefaultCollectionName = "langchain";
Expand Down
3 changes: 3 additions & 0 deletions src/Databases/Postgres/src/PostgresDbClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.Json;
using LangChain.Common.Converters;
Expand All @@ -10,6 +11,8 @@ namespace LangChain.Databases.Postgres;
/// <summary>
///
/// </summary>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public class PostgresDbClient
{
private readonly NpgsqlDataSource _dataSource;
Expand Down
3 changes: 3 additions & 0 deletions src/Databases/Postgres/src/PostgresVectorStore.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using LangChain.Databases.Postgres;
using LangChain.Docstore;
using LangChain.Providers;
Expand All @@ -12,6 +13,8 @@ namespace LangChain.Databases;
/// required: CREATE EXTENSION IF NOT EXISTS vector
/// </remarks>
/// </summary>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public class PostgresVectorStore : VectorStore
{
private readonly DistanceStrategy _distanceStrategy;
Expand Down
3 changes: 3 additions & 0 deletions src/Databases/Redis/src/RedisChatMessageHistory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using LangChain.Memory;
using LangChain.Providers;
Expand All @@ -8,6 +9,8 @@ namespace LangChain.Databases;
/// <summary>
/// Chat message history stored in a Redis database.
/// </summary>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public class RedisChatMessageHistory : BaseChatMessageHistory
{
private readonly string _sessionId;
Expand Down
5 changes: 4 additions & 1 deletion src/Databases/Sqlite/src/SQLiteVectorStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using LangChain.Base;
using LangChain.Docstore;
using LangChain.Indexes;
Expand All @@ -12,6 +13,8 @@ namespace LangChain.Databases;
/// <summary>
///
/// </summary>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public sealed class SQLiteVectorStore : VectorStore, IDisposable
{
private readonly string _tableName;
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<PropertyGroup>
<IsTestProject Condition="$(MSBuildProjectFile.Contains('Tests'))">true</IsTestProject>
<IsLibraryProject Condition="'$(IsTestProject)' != 'true'">true</IsLibraryProject>
<IsLibraryProject Condition="$(MSBuildProjectFile.Contains('LangChain')) AND !$(MSBuildProjectFile.Contains('Tests')) AND !$(MSBuildProjectFile.Contains('Samples'))">true</IsLibraryProject>
</PropertyGroup>

<Import Project="Packaging.props" Condition="'$(IsLibraryProject)' == 'true'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LangChain.Providers.Anthropic;
using System.Diagnostics.CodeAnalysis;
using LangChain.Providers.Anthropic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -15,6 +16,8 @@ public static partial class ServiceCollectionExtensions
/// <param name="services"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public static IServiceCollection AddAnthropic(
this IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LangChain.Providers.Anyscale;
using System.Diagnostics.CodeAnalysis;
using LangChain.Providers.Anyscale;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -15,6 +16,8 @@ public static partial class ServiceCollectionExtensions
/// <param name="services"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public static IServiceCollection AddAnyscale(
this IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LangChain.Providers.HuggingFace;
using System.Diagnostics.CodeAnalysis;
using LangChain.Providers.HuggingFace;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -15,6 +16,8 @@ public static partial class ServiceCollectionExtensions
/// <param name="services"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public static IServiceCollection AddHuggingFace(
this IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LangChain.Providers.OpenAI;
using System.Diagnostics.CodeAnalysis;
using LangChain.Providers.OpenAI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -15,6 +16,8 @@ public static partial class ServiceCollectionExtensions
/// <param name="services"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[RequiresDynamicCode("Requires dynamic code.")]
[RequiresUnreferencedCode("Requires unreferenced code.")]
public static IServiceCollection AddOpenAi(
this IServiceCollection services)
{
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.");
34 changes: 34 additions & 0 deletions src/Helpers/TrimmingHelper/TrimmingHelper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<ProjectReference Include="..\..\Providers\Abstractions\src\LangChain.Providers.Abstractions.csproj" />
<ProjectReference Include="..\..\Sources\Abstractions\src\LangChain.Sources.Abstractions.csproj" />
<ProjectReference Include="..\..\Splitters\Abstractions\src\LangChain.Splitters.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<TrimmerRootAssembly Include="LangChain.Providers.Abstractions" />
<TrimmerRootAssembly Include="LangChain.Sources.Abstractions" />
<TrimmerRootAssembly Include="LangChain.Splitters.Abstractions" />
</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>
12 changes: 12 additions & 0 deletions src/Packaging.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup Label="Trimmable" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsAotCompatible>true</IsAotCompatible>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>

<PropertyGroup Label="Polyfills">
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>

<ItemGroup Label="Polyfills">
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFrameworks>net4.6.2;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1003;CA1307;CA1054;CA1711;CA1819;CA2234</NoWarn>
<RootNamespace>LangChain.Providers.Amazon.Bedrock</RootNamespace>
<IsAotCompatible>false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFrameworks>net4.6.2;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA2016</NoWarn>
<RootNamespace>LangChain.Providers.Amazon.SageMaker</RootNamespace>
<IsAotCompatible>false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net4.6.2'">
Expand Down
3 changes: 3 additions & 0 deletions src/Providers/Ollama/src/LangChain.Providers.Ollama.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFrameworks>net4.6.2;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<NoWarn>$(NoWarn);CA1003;CA1307;CA1054;CA1711;CA1819;CA2234</NoWarn>
<IsAotCompatible>false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
</PropertyGroup>

<ItemGroup Label="Usings">
Expand Down

0 comments on commit 4000a0e

Please sign in to comment.