hwchase17 / langchain
- понедельник, 12 декабря 2022 г. в 00:40:05
⚡ Building applications with LLMs through composability ⚡
pip install langchain
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.
Please see here for full documentation on:
There are four main areas that LangChain is designed to help with. These are, in increasing order of complexity:
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.
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
Problems Solved
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
Problems Solved
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
Problems Solved
By default, Chains and Agents are stateless, meaning that they treat each incoming query independently. In some applications (chatbots being a GREAT example) it is highly important to remember previous interactions, both at a short term but also at a long term level. The concept of "Memory" exists to do exactly that.
Key Concepts
Problems Solved
To begin developing on this project, first clone the repo locally.
This project uses Poetry as a dependency manager. Check out Poetry's own documentation on how to install it on your system before proceeding.
To install requirements:
poetry install -E all
This will install all requirements for running the package, examples, linting, formatting, and tests. Note the -E all
flag will install all optional dependencies necessary for integration testing.
Now, you should be able to run the common tasks in the following section.
Formatting for this project is a combination of Black and isort.
To run formatting for this project:
make format
Linting for this project is a combination of Black, isort, flake8, and mypy.
To run linting for this project:
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:
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:
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'll want to install the optional dev
dependencies.
To install dev dependencies:
poetry install --with dev
Launch a notebook:
poetry run jupyter notebook
When you run poetry install
, the langchain
package is installed as editable in the virtualenv, 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.