LangChain.Serve 0.15.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package LangChain.Serve --version 0.15.2                
NuGet\Install-Package LangChain.Serve -Version 0.15.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LangChain.Serve" Version="0.15.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LangChain.Serve --version 0.15.2                
#r "nuget: LangChain.Serve, 0.15.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LangChain.Serve as a Cake Addin
#addin nuget:?package=LangChain.Serve&version=0.15.2

// Install LangChain.Serve as a Cake Tool
#tool nuget:?package=LangChain.Serve&version=0.15.2                

šŸ¦œļøšŸ”— LangChain .NET

Nuget package dotnet License: MIT Discord

All Contributors

āš” Building applications with LLMs through composability āš”
C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.

While the SemanticKernel is good and we will use it wherever possible, we believe that it has many limitations and based on Microsoft technologies. We proceed from the position of the maximum choice of available options and are open to using third-party libraries within individual implementations.

I want to note:

  • Iā€™m unlikely to be able to make serious progress alone, so my goal is to unite the efforts of C# developers to create a C# version of LangChain and control the quality of the final project
  • I try to accept any Pull Request within 24 hours (of course, it depends, but I will try)
  • I'm also looking for developers to join the core team. I will sponsor them whenever possible and also share any money received.
  • I also respond quite quickly on Discord for any questions related to the project

Usage

You can use our wiki to get started: https://tryagi.github.io/LangChain/
If the wiki contains unupdated code, you can always take a look at the tests for this
Also see examples for example usage or tests.

// Price to run from zero(create embeddings and request to LLM): 0,015$
// Price to re-run if database is exists: 0,0004$
// Dependencies: LangChain, LangChain.Databases.Sqlite, LangChain.DocumentLoaders.Pdf

// Initialize models
var provider = new OpenAiProvider(
    Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??
    throw new InconclusiveException("OPENAI_API_KEY is not set"));
var llm = new OpenAiLatestFastChatModel(provider);
var embeddingModel = new TextEmbeddingV3SmallModel(provider);

// Create vector database from Harry Potter book pdf
using var vectorDatabase = new SqLiteVectorDatabase(dataSource: "vectors.db");
var vectorCollection = await vectorDatabase.AddDocumentsFromAsync<PdfPigPdfLoader>(
    embeddingModel, // Used to convert text to embeddings
    dimensions: 1536, // Should be 1536 for TextEmbeddingV3SmallModel
    dataSource: DataSource.FromUrl("https://canonburyprimaryschool.co.uk/wp-content/uploads/2016/01/Joanne-K.-Rowling-Harry-Potter-Book-1-Harry-Potter-and-the-Philosophers-Stone-EnglishOnlineClub.com_.pdf"),
    collectionName: "harrypotter", // Can be omitted, use if you want to have multiple collections
    textSplitter: null); // Default is CharacterTextSplitter(ChunkSize = 4000, ChunkOverlap = 200)

// Now we have two ways: use the async methods or use the chains
// 1. Async methods

// Find similar documents for the question
const string question = "Who was drinking a unicorn blood?";
var similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5);

// Use similar documents and LLM to answer the question
var answer = await llm.GenerateAsync(
    $"""
     Use the following pieces of context to answer the question at the end.
     If the answer is not in context then just say that you don't know, don't try to make up an answer.
     Keep the answer as short as possible.

     {similarDocuments.AsString()}

     Question: {question}
     Helpful Answer:
     """);

Console.WriteLine($"LLM answer: {answer}"); // The cloaked figure.

// 2. Chains
var promptTemplate =
    @"Use the following pieces of context to answer the question at the end. If the answer is not in context then just say that you don't know, don't try to make up an answer. Keep the answer as short as possible. Always quote the context in your answer.
{context}
Question: {text}
Helpful Answer:";

var chain =
    Set("Who was drinking a unicorn blood?")     // set the question (default key is "text")
    | RetrieveSimilarDocuments(vectorCollection, embeddingModel, amount: 5) // take 5 most similar documents
    | CombineDocuments(outputKey: "context")     // combine documents together and put them into context
    | Template(promptTemplate)                   // replace context and question in the prompt with their values
    | LLM(llm.UseConsoleForDebug());             // send the result to the language model
var chainAnswer = await chain.RunAsync("text");  // get chain result

Console.WriteLine("Chain Answer:"+ chainAnswer);       // print the result
        
Console.WriteLine($"LLM usage: {llm.Usage}");    // Print usage and price
Console.WriteLine($"Embedding model usage: {embeddingModel.Usage}");   // Print usage and price
  • LangChainChat - Allows you to run a chat based on a Blazor project using LangChain.Serve and any of the supported local or paid models

šŸŒŸ Contributors

langchain.net contributors

Support

Priority place for bugs: https://github.com/tryAGI/LangChain/issues
Priority place for ideas and general questions: https://github.com/tryAGI/LangChain/discussions
Discord: https://discord.gg/Ca2xhfBf3v

It's licensed under the MIT license. We do not plan to change the license in any foreseeable future for this project, but projects based on this within the organization may have different licenses.
Some documentation is based on documentation from dotnet/docs repository under CC BY 4.0 license, where code examples are changed to code examples for using this project.

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.

CodeRabbit logo

This project is supported by CodeRabbit through the Open Source Support Program.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.15.3-dev.14 33 11/13/2024
0.15.3-dev.12 35 11/2/2024
0.15.3-dev.8 47 10/11/2024
0.15.2 100 9/19/2024
0.15.1-dev.130 47 9/18/2024
0.15.1-dev.129 50 9/17/2024
0.15.1-dev.126 58 9/14/2024
0.15.1-dev.125 47 9/12/2024
0.15.1-dev.124 46 9/12/2024
0.15.1-dev.123 47 9/12/2024
0.15.1-dev.122 41 9/12/2024
0.15.1-dev.120 46 9/11/2024
0.15.1-dev.118 40 9/10/2024
0.15.1-dev.116 48 9/5/2024
0.15.1-dev.115 44 9/3/2024
0.15.1-dev.112 39 9/1/2024
0.15.1-dev.111 46 9/1/2024
0.15.1-dev.104 70 8/22/2024
0.15.1-dev.100 63 8/21/2024
0.15.1-dev.98 66 8/20/2024
0.15.1-dev.96 66 8/20/2024
0.15.1-dev.95 66 8/20/2024
0.15.1-dev.94 73 8/20/2024
0.15.1-dev.90 71 8/18/2024
0.15.1-dev.89 65 8/16/2024
0.15.1-dev.86 61 8/14/2024
0.15.1-dev.79 30 8/6/2024
0.15.1-dev.78 32 8/6/2024
0.15.1-dev.77 36 8/6/2024
0.15.1-dev.76 47 8/6/2024
0.15.1-dev.69 33 8/4/2024
0.15.1-dev.68 33 8/3/2024
0.15.1-dev.67 30 8/3/2024
0.15.1-dev.65 29 8/3/2024
0.15.1-dev.63 47 8/1/2024
0.15.1-dev.51 46 7/30/2024
0.15.1-dev.46 50 7/27/2024
0.15.1-dev.43 50 7/25/2024
0.15.1-dev.42 49 7/24/2024
0.15.1-dev.41 48 7/24/2024
0.15.1-dev.39 46 7/24/2024
0.15.1-dev.37 49 7/24/2024
0.15.1-dev.35 52 7/22/2024
0.15.1-dev.34 48 7/22/2024
0.15.1-dev.31 51 7/21/2024
0.15.1-dev.12 36 7/11/2024
0.15.1-dev.11 31 7/11/2024
0.15.1-dev.1 71 6/27/2024
0.15.0 127 6/27/2024
0.14.1-dev.79 47 6/26/2024
0.14.1-dev.73 56 6/19/2024
0.14.1-dev.69 51 6/14/2024
0.14.1-dev.66 44 6/11/2024
0.14.1-dev.65 41 6/11/2024
0.14.1-dev.60 49 6/8/2024
0.14.1-dev.57 59 6/6/2024
0.14.1-dev.52 47 6/3/2024
0.14.1-dev.51 51 6/3/2024
0.14.1-dev.49 51 6/1/2024
0.14.1-dev.48 47 6/1/2024
0.14.1-dev.47 53 5/31/2024
0.14.1-dev.43 59 5/23/2024
0.14.1-dev.42 55 5/23/2024
0.14.1-dev.39 56 5/21/2024
0.14.1-dev.35 60 5/19/2024
0.14.1-dev.34 55 5/18/2024
0.14.1-dev.33 52 5/18/2024
0.14.1-dev.31 52 5/17/2024
0.14.1-dev.30 56 5/17/2024
0.14.1-dev.25 48 5/15/2024
0.14.1-dev.24 54 5/15/2024
0.14.1-dev.21 58 5/13/2024
0.14.1-dev.17 50 5/13/2024
0.14.1-dev.14 48 5/12/2024
0.14.1-dev.11 61 5/8/2024
0.14.1-dev.10 59 5/8/2024
0.14.1-dev.8 60 5/5/2024
0.14.1-dev.7 68 5/5/2024
0.14.1-dev.6 67 5/5/2024
0.14.1-dev.5 61 5/5/2024
0.14.1-dev.2 52 5/3/2024
0.14.1-dev.1 42 5/3/2024
0.14.0 126 5/3/2024
0.13.1-dev.184 47 5/3/2024
0.13.1-dev.183 44 5/3/2024
0.13.1-dev.179 18 5/2/2024
0.13.1-dev.178 22 5/2/2024
0.13.1-dev.177 18 5/2/2024
0.13.1-dev.175 16 5/2/2024
0.13.1-dev.171 16 5/2/2024
0.13.1-dev.169 38 5/1/2024
0.13.1-dev.161 57 4/30/2024
0.13.1-dev.157 54 4/29/2024
0.13.1-dev.154 56 4/29/2024
0.13.1-dev.150 53 4/29/2024
0.13.1-dev.145 48 4/29/2024
0.13.1-dev.144 53 4/29/2024
0.13.1-dev.142 49 4/29/2024
0.13.1-dev.141 53 4/29/2024
0.13.1-dev.138 50 4/29/2024
0.13.1-dev.137 45 4/29/2024
0.13.1-dev.136 46 4/29/2024
0.13.1-dev.131 59 4/28/2024
0.13.1-dev.121 53 4/27/2024
0.13.1-dev.119 58 4/27/2024
0.13.1-dev.116 59 4/26/2024
0.13.1-dev.112 70 4/25/2024
0.13.1-dev.110 62 4/25/2024
0.13.1-dev.107 58 4/24/2024
0.13.1-dev.106 58 4/24/2024
0.13.1-dev.103 53 4/23/2024
0.13.1-dev.102 56 4/23/2024
0.13.1-dev.101 56 4/23/2024
0.13.1-dev.99 53 4/22/2024
0.13.1-dev.97 53 4/22/2024
0.13.1-dev.96 61 4/22/2024
0.13.1-dev.95 50 4/21/2024
0.13.1-dev.94 51 4/21/2024
0.13.1-dev.93 64 4/21/2024
0.13.1-dev.92 58 4/20/2024
0.13.1-dev.91 54 4/20/2024
0.13.1-dev.90 55 4/20/2024
0.13.1-dev.89 50 4/20/2024
0.13.1-dev.88 52 4/20/2024
0.13.1-dev.87 51 4/20/2024
0.13.1-dev.86 60 4/20/2024
0.13.1-dev.85 57 4/20/2024
0.13.1-dev.84 54 4/20/2024
0.13.1-dev.83 55 4/20/2024
0.13.1-dev.82 52 4/20/2024
0.13.1-dev.81 61 4/20/2024
0.13.1-dev.80 51 4/20/2024
0.13.1-dev.79 57 4/20/2024
0.13.1-dev.78 51 4/20/2024
0.13.1-dev.77 48 4/20/2024
0.13.1-dev.76 53 4/20/2024
0.13.1-dev.75 49 4/20/2024
0.13.1-dev.74 56 4/20/2024
0.13.1-dev.73 54 4/20/2024
0.13.1-dev.72 50 4/20/2024
0.13.1-dev.71 55 4/20/2024
0.13.1-dev.70 59 4/20/2024
0.13.1-dev.69 58 4/20/2024
0.13.1-dev.68 52 4/20/2024
0.13.1-dev.67 47 4/20/2024
0.13.1-dev.66 46 4/20/2024
0.13.1-dev.65 60 4/20/2024
0.13.1-dev.64 52 4/20/2024
0.13.1-dev.63 56 4/20/2024
0.13.1-dev.62 60 4/20/2024
0.13.1-dev.61 60 4/20/2024
0.13.1-dev.60 53 4/20/2024
0.13.1-dev.59 47 4/20/2024
0.13.1-dev.57 64 4/20/2024
0.13.1-dev.56 58 4/20/2024
0.13.1-dev.55 62 4/20/2024
0.13.1-dev.54 64 4/20/2024
0.13.1-dev.53 63 4/20/2024
0.13.1-dev.52 51 4/19/2024
0.13.1-dev.51 48 4/19/2024
0.13.1-dev.50 49 4/18/2024
0.13.1-dev.49 64 4/15/2024
0.13.1-dev.48 58 4/15/2024
0.13.1-dev.47 59 4/14/2024
0.13.1-dev.45 67 4/13/2024
0.13.1-dev.44 56 4/13/2024
0.13.1-dev.43 65 4/13/2024
0.13.1-dev.41 57 4/13/2024
0.13.1-dev.40 53 4/12/2024
0.13.1-dev.39 55 4/11/2024
0.13.1-dev.38 48 4/10/2024
0.13.1-dev.37 55 4/9/2024
0.13.1-dev.36 58 4/8/2024
0.13.1-dev.35 61 4/7/2024
0.13.1-dev.34 60 4/7/2024
0.13.1-dev.33 60 4/7/2024
0.13.1-dev.32 64 4/6/2024
0.13.1-dev.31 63 4/5/2024
0.13.1-dev.29 55 4/5/2024
0.13.1-dev.28 51 4/5/2024
0.13.1-dev.27 54 4/4/2024
0.13.1-dev.26 62 4/3/2024
0.13.1-dev.25 54 4/3/2024
0.13.1-dev.24 56 4/3/2024
0.13.1-dev.22 55 4/3/2024
0.13.1-dev.21 52 4/3/2024
0.13.1-dev.20 56 4/3/2024
0.13.1-dev.19 65 4/3/2024
0.13.1-dev.18 55 4/3/2024
0.13.1-dev.17 57 4/2/2024
0.13.1-dev.16 60 4/1/2024
0.13.1-dev.15 58 4/1/2024
0.13.1-dev.13 65 3/30/2024
0.13.1-dev.12 62 3/27/2024
0.13.1-dev.11 62 3/24/2024
0.13.1-dev.10 62 3/23/2024
0.13.1-dev.9 63 3/22/2024
0.13.1-dev.7 79 3/18/2024
0.13.1-dev.5 55 3/9/2024
0.13.1-dev.3 65 3/7/2024
0.13.1-dev.2 60 3/7/2024
0.13.1-dev.1 57 3/6/2024
0.13.0 341 3/6/2024
0.12.3-dev.157 61 3/6/2024
0.12.3-dev.156 68 3/6/2024
0.12.3-dev.155 54 3/6/2024
0.12.3-dev.151 43 3/5/2024
0.12.3-dev.150 54 3/4/2024
0.12.3-dev.149 58 3/4/2024
0.12.3-dev.148 53 3/4/2024
0.12.3-dev.147 63 3/3/2024
0.12.3-dev.145 62 3/3/2024
0.12.3-dev.144 59 3/3/2024
0.12.3-dev.143 70 3/3/2024
0.12.3-dev.142 63 3/2/2024
0.12.3-dev.141 54 3/2/2024
0.12.3-dev.140 57 2/29/2024
0.12.3-dev.139 54 2/29/2024
0.12.3-dev.137 52 2/28/2024
0.12.3-dev.134 47 2/28/2024
0.12.3-dev.133 50 2/28/2024
0.12.3-dev.132 54 2/27/2024
0.12.3-dev.131 55 2/26/2024
0.12.3-dev.130 56 2/26/2024
0.12.3-dev.128 65 2/25/2024
0.12.3-dev.127 52 2/25/2024
0.12.3-dev.120 69 2/24/2024
0.12.3-dev.119 59 2/24/2024
0.12.3-dev.118 52 2/23/2024
0.12.3-dev.116 64 2/23/2024
0.12.3-dev.115 80 2/23/2024