Git Product home page Git Product logo

langchain's Introduction

๐Ÿฆœ๏ธ๐Ÿ”— LangChain

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://github.com/tryAGI/LangChain/wiki
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.Sources.Pdf

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

// Create vector database from Harry Potter book pdf
var source = await PdfPigPdfSource.CreateFromUriAsync(new Uri("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"));
var index = await SQLiteVectorStore.GetOrCreateIndexAsync(embeddings, source);

// 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 index.Store.GetSimilarDocuments(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:
     """, cancellationToken: CancellationToken.None).ConfigureAwait(false);

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(index, 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.Run("text");  // get chain result

Console.WriteLine("Chain Answer:"+ chainAnswer);       // print the result
        
Console.WriteLine($"LLM usage: {llm.Usage}");    // Print usage and price
Console.WriteLine($"Embeddings usage: {embeddings.Usage}");   // Print usage and price

Contributors

Konstantin S.
Konstantin S.

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
TesAnti
TesAnti

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Khoroshev Evgeniy
Khoroshev Evgeniy

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
SiegDuch
SiegDuch

๐Ÿš‡
gunpal5
gunpal5

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Ketan Khare
Ketan Khare

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Roderic Bos
Roderic Bos

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Peter James
Peter James

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Ty Augustine
Ty Augustine

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Eric Green
Eric Green

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Lyx52
Lyx52

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
Lorenzo Fiore
Lorenzo Fiore

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป
matt-regier
matt-regier

๐Ÿš‡ โš ๏ธ ๐Ÿ’ป

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

langchain's People

Contributors

havendv avatar tesanti avatar dependabot[bot] avatar allcontributors[bot] avatar curlyfro avatar khoroshevj avatar gunpal5 avatar hiptopjones avatar irooc avatar ericgreenmix avatar kharedev247 avatar fiorelorenzo avatar lyx52 avatar siegduch avatar matt-regier avatar sweep-ai[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.