Building applications with LLMs through composability
Project description
🦜️🔗 LangChain
⚡ Building applications with LLMs through composability ⚡
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:
- LLM and Prompts
- Chains
- Agents
- (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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain-0.0.19.tar.gz
.
File metadata
- Download URL: langchain-0.0.19.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c8aebd7895e86401139213037d8f3866d61ab047873bacc0018e50b8f48ca3b |
|
MD5 | 4853b2cdb745d9922fcf1902658c024d |
|
BLAKE2b-256 | fc428309b2b55bcb504713ca1350ffeccc8731e06f4b201038927c12bf62273a |
File details
Details for the file langchain-0.0.19-py3-none-any.whl
.
File metadata
- Download URL: langchain-0.0.19-py3-none-any.whl
- Upload date:
- Size: 101.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 580d4fe20bfb4c4cb93c3d88df0db5cefefc415265d632ea218f854e66947ee5 |
|
MD5 | 0e5099b51b30412d76eeaf58ca0d54ff |
|
BLAKE2b-256 | 7d40e8228dc4b154d73e4b02536749f788c56644108f9cc89b75f4816137ce12 |