Skip to main content

🦜️🔗 LangChain

⚡ Building applications with LLMs through composability ⚡

lint test License: MIT Twitter

Quick Install

pip install langchain

🤔 What is this?

Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not. But using these LLMs in isolation is often not enough to create a truly powerful app - the real power comes when you are able to combine them with other sources of computation or knowledge.

This library is aimed at assisting in the development of those types of applications.

📖 Documentation

Please see here for full documentation on:

  • Getting started (installation, setting up environment, simple examples)
  • How-To examples (demos, integrations, helper functions)
  • Reference (full API docs)
  • Resources (high level explanation of core concepts)

🚀 What can this help with?

There are three main areas (with a forth coming soon) that LangChain is designed to help with. These are, in increasing order of complexity:

  1. LLM and Prompts
  2. Chains
  3. Agents
  4. (Coming Soon) Memory

Let's go through these categories and for each one identify key concepts (to clarify terminology) as well as the problems in this area LangChain helps solve.

LLMs and Prompts

Calling out to an LLM once is pretty easy, with most of them being behind well documented APIs. However, there are still some challenges going from that to an application running in production that LangChain attempts to address.

Key Concepts

  • LLM: A large language model, in particular a text-to-text model.
  • Prompt: The input to a language model. Typically this is not simply a hardcoded string but rather a combination of a template, some examples, and user input.
  • Prompt Template: An object responsible for constructing the final prompt to pass to a LLM.

Problems solved

  • Switching costs: by exposing a standard interface for all the top LLM providers, LangChain makes it easy to switch from one provider to another, whether it be for production use cases or just for testing stuff out.
  • Prompt management: managing your prompts is easy when you only have one simple one, but can get tricky when you have a bunch or when they start to get more complex. LangChain provides a standard way for storing, constructing, and referencing prompts.
  • Prompt optimization: despite the underlying models getting better and better, there is still currently a need for carefully constructing prompts.

Chains

Using an LLM in isolation is fine for some simple applications, but many more complex ones require chaining LLMs - either with eachother or with other experts. LangChain provides several parts to help with that.

Key Concepts

  • Tools: APIs designed for assisting with a particular use case (search, databases, Python REPL, etc). Prompt templates, LLMs, and chains can also be considered tools.
  • Chains: A combination of multiple tools in a deterministic manner.

Problems solved

  • Standard interface for working with Chains
  • Easy way to construct chains of LLMs
  • Lots of integrations with other tools that you may want to use in conjunction with LLMs
  • End-to-end chains for common workflows (database question/answer, recursive summarization, etc)

Agents

Some applications will require not just a predetermined chain of calls to LLMs/other tools, but potentially an unknown chain that depends on the user input. In these types of chains, there is a “agent” which has access to a suite of tools. Depending on the user input, the agent can then decide which, if any, of these tools to call.

Key Concepts

  • Tools: same as above.
  • Agent: An LLM-powered class responsible for determining which tools to use and in what order.

Problems solved

  • Standard agent interfaces
  • A selection of powerful agents to choose from
  • Common chains that can be used as tools

Memory

Coming soon.

🤖 Developer Guide

To begin developing on this project, first clone to the repo locally. To install requirements, run pip install -r requirements.txt. This will install all requirements for running the package, examples, linting, formatting, and tests.

Formatting for this project is a combination of Black and isort. To run formatting for this project, run make format.

Linting for this project is a combination of Black, isort, flake8, and mypy. To run linting for this project, run make lint. We recognize linting can be annoying - if you do not want to do it, please contact a project maintainer and they can help you with it. We do not want this to be a blocker for good code getting contributed.

Unit tests cover modular logic that does not require calls to outside apis. To run unit tests, run make tests. If you add new logic, please add a unit test.

Integration tests cover logic that requires making calls to outside APIs (often integration with other services). To run integration tests, run make integration_tests. If you add support for a new external API, please add a new integration test.

If you are adding a Jupyter notebook example, you can run pip install -e . to build the langchain package from your local changes, so your new logic can be imported into the notebook.

Docs are largely autogenerated by sphinx from the code. For that reason, we ask that you add good documentation to all classes and methods. Similar to linting, we recognize documentation can be annoying - if you do not want to do it, please contact a project maintainer and they can help you with it. We do not want this to be a blocker for good code getting contributed.

Metadata

Release files for langchain 0.0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain 0.0.21
File Size Uploaded
langchain-0.0.21.tar.gz 60.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain 0.0.21
File Interpreter ABI Platform
langchain-0.0.21-py3-none-any.whl Python 3 none any Details

Total release size: 167.7 kB

Release files / langchain-0.0.21.tar.gz

Download URL langchain-0.0.21.tar.gz
Size 60.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5de30d3a9c58d88423035803302f7ede36b78a99203e39f46dfbfd1e4cfa87dd
BLAKE2b-256 checksum
How to use checksums
91250ad00eba0f2a2e90b800bd734b2c7a4d0808f445f4eb15bc36e169cc17ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.6

Release files / langchain-0.0.21-py3-none-any.whl

Download URL langchain-0.0.21-py3-none-any.whl
Size 107.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a124db675f636a3e7ad612667a40691852d96032f5bb67eecb4276c5defbdab
BLAKE2b-256 checksum
How to use checksums
91d76848ee9cab9d1bcd2ae4b833483b0004187436b37300209787d1fef2b07e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.6

Release history Release notifications | RSS feed

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.18

2 release files

1.3.17

2 release files

1.3.16

2 release files

1.3.15

2 release files

1.3.14

2 release files

1.3.13

2 release files

1.3.11

2 release files

1.3.10

2 release files

1.3.9

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.17

2 release files

1.2.16

2 release files

1.2.14

2 release files

1.2.13

2 release files

1.2.12

2 release files

1.2.11

2 release files

1.2.10

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.27

2 release files

0.3.26

2 release files

0.3.24

2 release files

0.3.22

2 release files

0.3.21

2 release files

0.3.19

2 release files

0.3.17

2 release files

0.3.16

2 release files

0.3.15

2 release files

0.3.13

2 release files

0.3.12

2 release files

0.3.11

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.20

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.96

2 release files

0.0.95

2 release files

0.0.94

2 release files

0.0.93

2 release files

0.0.92

2 release files

0.0.91

2 release files

0.0.90

2 release files

0.0.89

2 release files

0.0.88

2 release files

0.0.87

2 release files

0.0.86

2 release files

0.0.85

2 release files

0.0.84

2 release files

0.0.83

2 release files

0.0.82

2 release files

0.0.75

2 release files

0.0.74

2 release files

0.0.73

2 release files

0.0.72

2 release files

0.0.71

2 release files

0.0.70

2 release files

0.0.69

2 release files

0.0.68

2 release files

0.0.67

2 release files

0.0.66

2 release files

0.0.65

2 release files

0.0.64

2 release files

0.0.63

2 release files

0.0.61

2 release files

0.0.60

2 release files

0.0.53

2 release files

0.0.52

2 release files

0.0.51

2 release files

0.0.50

2 release files

0.0.49

2 release files

0.0.48

2 release files

0.0.47

2 release files

0.0.46

2 release files

0.0.45

2 release files

0.0.44

2 release files

0.0.43

2 release files

0.0.42

2 release files

0.0.41

2 release files

0.0.40

2 release files

0.0.39

2 release files

0.0.38

2 release files

0.0.37

2 release files

0.0.36

2 release files

0.0.35

2 release files

0.0.34

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

This release

0.0.21 This release

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page