{"id":13560684,"url":"https://github.com/tryAGI/LangChain","last_synced_at":"2025-04-03T16:30:59.850Z","repository":{"id":172773654,"uuid":"648854280","full_name":"tryAGI/LangChain","owner":"tryAGI","description":"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.","archived":false,"fork":false,"pushed_at":"2024-05-22T13:16:51.000Z","size":5117,"stargazers_count":397,"open_issues_count":52,"forks_count":62,"subscribers_count":22,"default_branch":"main","last_synced_at":"2024-05-22T14:35:17.130Z","etag":null,"topics":["abstractions","agents","ai","artificial-intelligence","chain","csharp","joi","langchain","langchain-csharp","llm","llms","openai","prompt","sdk","semantic","semantic-kernel","tryagi"],"latest_commit_sha":null,"homepage":"https://tryagi.gitbook.io/langchain/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tryAGI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"HavenDV","patreon":"havendv","ko_fi":"havendv","custom":["https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"]}},"created_at":"2023-06-03T02:14:25.000Z","updated_at":"2024-05-22T14:35:19.286Z","dependencies_parsed_at":"2023-11-06T23:30:50.724Z","dependency_job_id":"3bbc4b7e-9f68-400d-bd1a-ab9f9b8b0e01","html_url":"https://github.com/tryAGI/LangChain","commit_stats":null,"previous_names":["tryagi/langchain"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FLangChain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FLangChain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FLangChain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FLangChain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tryAGI","download_url":"https://codeload.github.com/tryAGI/LangChain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247036921,"owners_count":20873048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstractions","agents","ai","artificial-intelligence","chain","csharp","joi","langchain","langchain-csharp","llm","llms","openai","prompt","sdk","semantic","semantic-kernel","tryagi"],"created_at":"2024-08-01T13:00:48.656Z","updated_at":"2025-04-03T16:30:57.951Z","avatar_url":"https://github.com/tryAGI.png","language":"C#","readme":"# 🦜️🔗 LangChain .NET\n\n[![Nuget package](https://img.shields.io/nuget/vpre/LangChain)](https://www.nuget.org/packages/LangChain/)\n[![dotnet](https://github.com/tryAGI/LangChain/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/tryAGI/LangChain/actions/workflows/dotnet.yml)\n[![License: MIT](https://img.shields.io/github/license/tryAGI/LangChain)](https://github.com/tryAGI/LangChain/blob/main/LICENSE)\n[![Discord](https://img.shields.io/discord/1115206893015662663?label=Discord\u0026logo=discord\u0026logoColor=white\u0026color=d82679)](https://discord.gg/Ca2xhfBf3v)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\n⚡ Building applications with LLMs through composability ⚡  \nC# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.\n\nWhile the [SemanticKernel](https://github.com/microsoft/semantic-kernel/) is good and we will use it wherever possible, we believe that it has many limitations and based on Microsoft technologies.\nWe proceed from the position of the maximum choice of available options and are open to using third-party libraries within individual implementations.  \n\nI want to note:\n- 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\n- I try to accept any Pull Request within 24 hours (of course, it depends, but I will try)\n- I'm also looking for developers to join the core team. I will sponsor them whenever possible and also share any money received.\n- I also respond quite quickly on Discord for any questions related to the project\n\n## Usage\nYou can use our wiki to get started: https://tryagi.github.io/LangChain/  \nIf the wiki contains unupdated code, you can always take a look at [the tests for this](src/Meta/test/WikiTests.cs)  \nAlso see [examples](./examples) for example usage or [tests](./src/tests/LangChain.IntegrationTests/ReadmeTests.cs).\n```csharp\n// Price to run from zero(create embeddings and request to LLM): 0,015$\n// Price to re-run if database is exists: 0,0004$\n// Dependencies: LangChain, LangChain.Databases.Sqlite, LangChain.DocumentLoaders.Pdf\n\n// Initialize models\nvar provider = new OpenAiProvider(\n    Environment.GetEnvironmentVariable(\"OPENAI_API_KEY\") ??\n    throw new InconclusiveException(\"OPENAI_API_KEY is not set\"));\nvar llm = new OpenAiLatestFastChatModel(provider);\nvar embeddingModel = new TextEmbeddingV3SmallModel(provider);\n\n// Create vector database from Harry Potter book pdf\nusing var vectorDatabase = new SqLiteVectorDatabase(dataSource: \"vectors.db\");\nvar vectorCollection = await vectorDatabase.AddDocumentsFromAsync\u003cPdfPigPdfLoader\u003e(\n    embeddingModel, // Used to convert text to embeddings\n    dimensions: 1536, // Should be 1536 for TextEmbeddingV3SmallModel\n    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\"),\n    collectionName: \"harrypotter\", // Can be omitted, use if you want to have multiple collections\n    textSplitter: null); // Default is CharacterTextSplitter(ChunkSize = 4000, ChunkOverlap = 200)\n\n// Now we have two ways: use the async methods or use the chains\n// 1. Async methods\n\n// Find similar documents for the question\nconst string question = \"Who was drinking a unicorn blood?\";\nvar similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5);\n\n// Use similar documents and LLM to answer the question\nvar answer = await llm.GenerateAsync(\n    $\"\"\"\n     Use the following pieces of context to answer the question at the end.\n     If the answer is not in context then just say that you don't know, don't try to make up an answer.\n     Keep the answer as short as possible.\n\n     {similarDocuments.AsString()}\n\n     Question: {question}\n     Helpful Answer:\n     \"\"\");\n\nConsole.WriteLine($\"LLM answer: {answer}\"); // The cloaked figure.\n\n// 2. Chains\nvar promptTemplate =\n    @\"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.\n{context}\nQuestion: {text}\nHelpful Answer:\";\n\nvar chain =\n    Set(\"Who was drinking a unicorn blood?\")     // set the question (default key is \"text\")\n    | RetrieveSimilarDocuments(vectorCollection, embeddingModel, amount: 5) // take 5 most similar documents\n    | CombineDocuments(outputKey: \"context\")     // combine documents together and put them into context\n    | Template(promptTemplate)                   // replace context and question in the prompt with their values\n    | LLM(llm.UseConsoleForDebug());             // send the result to the language model\nvar chainAnswer = await chain.RunAsync(\"text\");  // get chain result\n\nConsole.WriteLine(\"Chain Answer:\"+ chainAnswer);       // print the result\n        \nConsole.WriteLine($\"LLM usage: {llm.Usage}\");    // Print usage and price\nConsole.WriteLine($\"Embedding model usage: {embeddingModel.Usage}\");   // Print usage and price\n```\n\n## Featured projects\n- [LangChainChat](https://github.com/TesAnti/LangChainChat) - Allows you to run a chat based on a Blazor project using LangChain.Serve and any of the supported local or paid models\n\n## 🌟 Contributors\n\n[![langchain.net contributors](https://contrib.rocks/image?repo=tryagi/langchain\u0026max=2000)](https://github.com/tryagi/langchain/graphs/contributors)\n\n## Support\n\nPriority place for bugs: https://github.com/tryAGI/LangChain/issues  \nPriority place for ideas and general questions: https://github.com/tryAGI/LangChain/discussions  \nDiscord: https://discord.gg/Ca2xhfBf3v  \n\n## Legal information and credits\nIt's licensed under [the MIT license](LICENSE). We do not plan to change the license in any foreseeable future for this project, \nbut projects based on this within the organization may have different licenses.  \nSome documentation is based on documentation from [dotnet/docs](https://github.com/dotnet/docs/) repository \nunder [CC BY 4.0 license](https://github.com/dotnet/docs/blob/main/LICENSE), \nwhere code examples are changed to code examples for using this project.  \n\n## Acknowledgments\n\n![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png)\n\nThis project is supported by JetBrains through the [Open Source Support Program](https://jb.gg/OpenSourceSupport).\n\n![CodeRabbit logo](https://opengraph.githubassets.com/1c51002d7d0bbe0c4fd72ff8f2e58192702f73a7037102f77e4dbb98ac00ea8f/marketplace/coderabbitai)\n\nThis project is supported by CodeRabbit through the [Open Source Support Program](https://github.com/marketplace/coderabbitai).","funding_links":["https://github.com/sponsors/HavenDV","https://patreon.com/havendv","https://ko-fi.com/havendv","https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"],"categories":["Open Source Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtryAGI%2FLangChain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FtryAGI%2FLangChain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtryAGI%2FLangChain/lists"}