pip install <your-package>
,
which contain classes that are compatible with LangChain’s core interfaces.
This guide covers:
- (Optional) How to bootstrap a new integration package
- How to implement components, such as chat models and vector stores, that adhere to the LangChain interface
(Optional) bootstrapping a new integration package
In this section, there are two options for bootstrapping a new integration package, but you can use other tools if you prefer.- langchain-cli: This is a command-line tool that can be used to bootstrap a new integration package with a template for LangChain components and Poetry for dependency management.
- Poetry: This is a Python dependency management tool that can be used to bootstrap a new Python package with dependencies. You can then add LangChain components to this package.
Option 1: langchain-cli (recommended)
Option 1: langchain-cli (recommended)
In this guide, we will be using the Next, come up with a name for your package. For this guide, we’ll use Next, add any dependencies:We can also add some And finally, have Poetry set up a virtual environment with your dependencies, as well as your integration package:You now have a new Python package with a template for LangChain components. This template comes with files for each integration type, but you can duplicate or delete any of these files as needed (including the associated test files). You can create individual files with commands like this:
langchain-cli
to create a new integration package
from a template, which can be edited to implement your LangChain components.Prerequisites
Bootstrapping a new Python package with langchain-cli
First, installlangchain-cli
and poetry
:langchain-parrot-link
.
You can confirm that the name is available on PyPi by searching for it on the PyPi website.Next, create your new Python package with langchain-cli
, and navigate into the new directory with cd
:typing
or test
dependencies in a separate Poetry dependency group.Option 2: Poetry (manual)
Option 2: Poetry (manual)
In this guide, we will be using Poetry for dependency management and packaging, but you can use other tools you prefer.Next, come up with a name for your package. For this guide, we’ll use Add main dependencies using Poetry, which will add them to your We will also add some
And finally, have Poetry set up a virtual environment with your dependencies, as well
as your integration package:All of these files should already exist from step 1, except for
Prerequisites
Bootstrapping a new Python package with Poetry
First, install Poetry:langchain-parrot-link
.
You can confirm that the name is available on PyPi by searching for it on the PyPi website.Next, create your new Python package with Poetry, and navigate into the new directory with cd
:pyproject.toml
file:test
dependencies in a separate Poetry dependency group. If
you are not using Poetry, we recommend adding these in a way that won’t package them
with your published package, or just installing them separately when you run tests.langchain-tests
will provide the standard tests we will use later.
We recommended pinning these to the latest version: Replace
<latest_version>
with the latest version of langchain-tests
below.Writing your integration
Let’s say you’re building an integration package that provides aChatParrotLink
chat model integration for LangChain. Here’s an example of what your project structure might look like:chat_models.py
and test_chat_models.py
. We will implement test_chat_models.py
later, following the standard tests guide.For chat_models.py
, paste the contents of the chat model implementation
above.Push your package to a public Github repository
This is only required if you want to publish your integration in the LangChain documentation.- Create a new repository on GitHub.
- Push your code to the repository.
- Confirm that your repository is viewable by the public (e.g., in a private browsing window, where you’re not logged into GitHub).
Implementing LangChain components
LangChain components are subclasses of base classes inlangchain-core
.
Examples include chat models, vector stores, tools, embedding models, and retrievers.
Your integration package will typically implement a subclass of at least one of these
components. Expand the tabs below to see details on each.
You can start from the following template or You can find example starter chat model code here.
langchain-cli
command: