pip install -U langchain-cli
curl -sSL <https://install.python-poetry.org> | python3 -
: 'these instructions are for mac, but use an equivalent for linux/pc'
brew install gh
To create a new app called <app-name>, run:
: 'this will be interactive, do not add any packages when prompted'
langchain app new <app-name>
This will initialize a directory with roughly the following structure:
<my-app>/
|-- app/
| |-- server.py # code to run your langserve server
|-- packages/ # used for langchain templates (you can ignore)
|-- pyproject.toml # manage Python dependencies with poetry
|-- poetry.lock # gives exact versions of your dependencies
|-- Dockerfile # build application into a container which
| # will then be served by hosted langserve
A LangChain app has a few important components that developers should be aware of:
app/: The app/ directory contains a FastAPI app that we have bootstrapped for you as part of LangServe. It contains a single file, server.py, which when run creates a local server to serve the app via uvicorn. The langserve package is designed on top of FastAPI apps. We will see exactly how this works later in the tutorial.packages/: The packages/ directory contains different langchain templates that you’ve added to your application so that you can serve them. This can be ignored unless you are using templates in your app. Each template is its own poetry repo (see below) with its own managed dependencies. Note that the default Dockerfile created with the langchain cli (see below) assumes the packages directory exists.pyproject.toml and poetry.lock: These files manage your dependencies using Poetry. For those unfamiliar with poetry, it is like a requirements.txt file on steroids. It ensures that every user of your application uses the same set of dependencies, even when you don’t specify the exact version of your dependencies in your list of requirements. This is helpful for serving applications, since it lets Hosted LangServe be sure that we’re running the same exact code you are when we install your application using poetry.Dockerfile: Builds a container from your application using Docker. Docker containers are ways to run code on consistent, isolated environments even when deployed on different hardware. For example, running some software on Macs and PCs may be incompatible, but Docker abstracts away all the differences between your operating systems, and ensures the application runs smoothly.When Hosted LangServe eventually builds your application, we only have access to your repo and the instructions in your Dockerfile that tell us how to build it. For advanced use cases, this may require some customization. For example, if you want to package up pre-created embeddings into your application, you will need to modify your Dockerfile to download those embeddings from a known location.