LangChain can flexibly integrate with the ChatGPT AI plugin ecosystem.
LangChain chains and agents can themselves be deployed as a plugin that can communicate with other agents or with ChatGPT itself.
For more information on AI Plugins, see OpenAI's example retrieval plugin repository.
Follow these steps to quickly set up and run a LangChain AI Plugin:
- Install Python 3.10, if not already installed.
- Clone the repository:
git clone git@github.com:langchain-ai/langchain-aiplugin.git
- Navigate to the example plugin directory:
cd langchain-aiplugin
- Install poetry:
pip install poetry
- Create a new virtual environment with Python 3.10:
poetry env use python3.10
- Activate the virtual environment:
poetry shell
- Install app dependencies:
poetry install
- Set up the chain you want to run (see detailed instructions below). For an example, run
export LANGCHAIN_DIRECTORY_PATH=retrieval_qa
andexport OPENAI_API_KEY=...
andexport BEARER_TOKEN=...
(the Bearer Token can be anything you want for local testing purposes). - Run the API locally:
poetry run app --port 8080
- Access the API documentation at
http://0.0.0.0:8080/docs
and test the API endpoints (make sure to add your bearer token).
For more detailed information on setting up, developing, and deploying the ChatGPT Retrieval Plugin, refer to the full Development section below.
This app uses Python 3.10, and poetry for dependency management.
Install Python 3.10 on your machine if it isn't already installed. It can be downloaded from the official Python website or with a package manager like brew
or apt
, depending on your system.
Note: If adding dependencies in the pyproject.toml
, make sure to run poetry lock
and poetry install
.
To setup a chain to be a plugin, you will need to do the following steps:
- Create a new folder
- Create a
chain.py
file in that folder, and fill it out appropriately (see instructions below) - Create a
constants.py
file in that folder, and fill it out appropriately (see instructions below) - Add an environment variable
export LANGCHAIN_DIRECTORY_PATH=$PATH_TO_FOLDER
In order to setup chain.py
all you need to do is expose a function with the following signature:
from langchain.chains.base import Chain
def load_chain() -> Chain:
"""Load your chain here."""
To get started, you can copy the file in template/chain.py
In order to setup constants.py
, you need to have a Python file with the following variables exposed:
# The description of the chain you are exposing. This will be used by ChatGPT to decide when to call it.
ENDPOINT_DESCRIPTION = ""
# The name of your endpoint that you are exposing.
ENDPOINT_NAME = ""
# The input key for the chain. The user input will get mapped to this key.
INPUT_NAME = ""
# The output key for the chain. The final response will take this key from the chain output.
OUTPUT_KEY = ""
# Name of the overall service to expose to the model.
NAME_FOR_MODEL = ""
# Name of the overall service to expose to humans.
NAME_FOR_HUMAN = ""
# Description of the overall service to expose to the model.
DESCRIPTION_FOR_MODEL = ""
# Description of the overall service to expose to humans.
DESCRIPTION_FOR_HUMAN = ""
To get started, you can copy the file in template/constants.py
To help get started we've set up two examples.
retrieval_qa
: Exposes a RetrievalQA Chain set up with LangChain Documentation. See the README in that folder for more information.agent
: Exposes a simple agent equipped with a calculator. See the README in that folder for more information.