langchain/templates/README.md

75 lines
1.5 KiB
Markdown
Raw Normal View History

2023-10-26 15:28:01 +00:00
# LangServe Templates
2023-10-26 15:28:01 +00:00
Templates for a fully functioning app that can be hosted by LangServe.
2023-10-26 15:28:01 +00:00
## Usage
2023-10-26 15:28:01 +00:00
To use, first install the LangChain CLI.
2023-10-26 15:28:01 +00:00
```shell
pip install -U langchain-cli
```
2023-10-26 15:28:01 +00:00
Then, install `langserve`:
2023-10-26 15:28:01 +00:00
```shell
pip install "langserve[all]"
```
2023-10-26 15:28:01 +00:00
Next, create a new LangChain project:
2023-10-26 15:28:01 +00:00
```shell
langchain serve new my-app
```
2023-10-26 15:28:01 +00:00
This will create a new directory called `my-app` with two folders:
2023-10-26 15:28:01 +00:00
- `app`: This is where LangServe code will live
- `packages`: This is where your chains or agents will live
2023-10-26 15:28:01 +00:00
To pull in an existing template as a package, you first need to go into your new project:
2023-10-26 15:28:01 +00:00
```shell
cd my-app
```
2023-10-26 15:28:01 +00:00
And you can the add a template as a project
2023-10-26 15:28:01 +00:00
```shell
langchain serve add $PROJECT_NAME
```
2023-10-26 15:28:01 +00:00
This will pull in the specified template into `packages/$PROJECT_NAME`
2023-10-26 15:28:01 +00:00
You then need to install this package so you can use it in the langserve app:
2023-10-26 15:28:01 +00:00
```shell
pip install -e packages/$PROJECT_NAME
```
2023-10-26 15:28:01 +00:00
We install it with `-e` so that if we modify the template at all (which we likely will) the changes are updated.
2023-10-26 15:28:01 +00:00
In order to have LangServe use this project, you then need to modify `app/server.py`.
Specifically, you should add something like:
2023-10-26 15:28:01 +00:00
```python
from fastapi import FastAPI
from langserve import add_routes
# This depends on the structure of the package you install
from my_project import chain
2023-10-26 15:28:01 +00:00
app = FastAPI()
2023-10-26 15:28:01 +00:00
add_routes(app, chain)
```
2023-10-26 15:28:01 +00:00
You can then spin up production-ready endpoints, along with a playground, by running:
2023-10-26 15:28:01 +00:00
```shell
python app/server.py
```
2023-10-26 15:28:01 +00:00
## Adding a template
2023-10-26 15:28:01 +00:00
See [here](CONTRIBUTING.md)