Deploy: LangServer
This commit is contained in:
parent
4b58bdae37
commit
a5e9f2db81
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
RUN pip install poetry==1.6.1
|
||||||
|
|
||||||
|
RUN poetry config virtualenvs.create false
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY ./pyproject.toml ./README.md ./poetry.lock* ./
|
||||||
|
|
||||||
|
COPY ./package[s] ./packages
|
||||||
|
|
||||||
|
RUN poetry install --no-interaction --no-ansi --no-root
|
||||||
|
|
||||||
|
COPY ./app ./app
|
||||||
|
|
||||||
|
RUN poetry install --no-interaction --no-ansi
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD exec uvicorn app.server:app --host 0.0.0.0 --port 8080
|
79
README.md
79
README.md
@ -1,2 +1,79 @@
|
|||||||
# oc-assistant
|
# assistant
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Install the LangChain CLI if you haven't yet
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -U langchain-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding packages
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# adding packages from
|
||||||
|
# https://github.com/langchain-ai/langchain/tree/master/templates
|
||||||
|
langchain app add $PROJECT_NAME
|
||||||
|
|
||||||
|
# adding custom GitHub repo packages
|
||||||
|
langchain app add --repo $OWNER/$REPO
|
||||||
|
# or with whole git string (supports other git providers):
|
||||||
|
# langchain app add git+https://github.com/hwchase17/chain-of-verification
|
||||||
|
|
||||||
|
# with a custom api mount point (defaults to `/{package_name}`)
|
||||||
|
langchain app add $PROJECT_NAME --api_path=/my/custom/path/rag
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: you remove packages by their api path
|
||||||
|
|
||||||
|
```bash
|
||||||
|
langchain app remove my/custom/path/rag
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setup LangSmith (Optional)
|
||||||
|
LangSmith will help us trace, monitor and debug LangChain applications.
|
||||||
|
You can sign up for LangSmith [here](https://smith.langchain.com/).
|
||||||
|
If you don't have access, you can skip this section
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export LANGCHAIN_TRACING_V2=true
|
||||||
|
export LANGCHAIN_API_KEY=<your-api-key>
|
||||||
|
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Launch LangServe
|
||||||
|
|
||||||
|
```bash
|
||||||
|
langchain serve
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running in Docker
|
||||||
|
|
||||||
|
This project folder includes a Dockerfile that allows you to easily build and host your LangServe app.
|
||||||
|
|
||||||
|
### Building the Image
|
||||||
|
|
||||||
|
To build the image, you simply:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker build . -t my-langserve-app
|
||||||
|
```
|
||||||
|
|
||||||
|
If you tag your image with something other than `my-langserve-app`,
|
||||||
|
note it for use in the next step.
|
||||||
|
|
||||||
|
### Running the Image Locally
|
||||||
|
|
||||||
|
To run the image, you'll need to include any environment variables
|
||||||
|
necessary for your application.
|
||||||
|
|
||||||
|
In the below example, we inject the `OPENAI_API_KEY` environment
|
||||||
|
variable with the value set in my local environment
|
||||||
|
(`$OPENAI_API_KEY`)
|
||||||
|
|
||||||
|
We also expose port 8080 with the `-p 8080:8080` option.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -p 8080:8080 my-langserve-app
|
||||||
|
```
|
||||||
|
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
19
app/server.py
Normal file
19
app/server.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
from langserve import add_routes
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def redirect_root_to_docs():
|
||||||
|
return RedirectResponse("/docs")
|
||||||
|
|
||||||
|
|
||||||
|
# Edit this to add the chain you want to add
|
||||||
|
add_routes(app, NotImplemented)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
19
docker-compose.yml
Normal file
19
docker-compose.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
OPENAI_API_KEY: ${OPENAI_API_KEY}
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
- .:/code
|
||||||
|
environment:
|
||||||
|
- PYTHONUNBUFFERED=1
|
||||||
|
command: >
|
||||||
|
uvicorn app.server:app --host 0.0.0.0 --port 8080
|
||||||
|
env_file:
|
||||||
|
- .env
|
0
packages/README.md
Normal file
0
packages/README.md
Normal file
23
pyproject.toml
Normal file
23
pyproject.toml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "assistant"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = ["Your Name <you@example.com>"]
|
||||||
|
readme = "README.md"
|
||||||
|
packages = [
|
||||||
|
{ include = "app" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.11"
|
||||||
|
uvicorn = "^0.23.2"
|
||||||
|
langserve = {extras = ["server"], version = ">=0.0.30"}
|
||||||
|
pydantic = "<2"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
langchain-cli = ">=0.0.15"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
@ -1 +1 @@
|
|||||||
{"token": "ya29.a0AeDClZBjncDp4ZwNKNtQ5ghKHPr1IT4XkgDc9QtvhPLrFGAR84f5r5iZPCd91VB7_WoJCG3iGQS0MU1n01xdRlEjDl7wVlKjKF0H680Bdim_bzykCXn3Jj0nVVkkHDOZP7RWeP1oAfY7Vjd4qbw_VxOdOzVzG_Bc6Auy4EJINAaCgYKAcYSARASFQHGX2MipaJllxIRMLCcZb2csCZECA0177", "refresh_token": "1//05nbircha66xlCgYIARAAGAUSNwF-L9IrxbE2v7kfLwXb4u0pD6Rin7xEBOTT83DeH7t2ttfD5CDmUCyhDsOaVRMRK_r8UtdoMq8", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "19011937557-bi5nh4afvg4tuqr87v6dp55qj9a9o1h2.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://mail.google.com/"], "universe_domain": "googleapis.com", "account": "", "expiry": "2024-10-30T01:16:56.882894Z"}
|
{"token": "ya29.a0AeDClZABfltq9OLAHLaKOn2vHXVhOJSMTTe9HijkoZTexSswOMjnIlJj4-NV4TOwCq-wRKJadY7wppE2hAodyY3P0mHCzfpxbNZo0PGWMf2t6gmEDup4quGcIMHup1xjKETg0JkftCDepAh7UTi2tEg_YMeReI3TaZTvaMlScwaCgYKAewSARASFQHGX2MijepHh68yMlxXo_TGuquUPw0177", "refresh_token": "1//05nbircha66xlCgYIARAAGAUSNwF-L9IrxbE2v7kfLwXb4u0pD6Rin7xEBOTT83DeH7t2ttfD5CDmUCyhDsOaVRMRK_r8UtdoMq8", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "19011937557-bi5nh4afvg4tuqr87v6dp55qj9a9o1h2.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://mail.google.com/"], "universe_domain": "googleapis.com", "account": "", "expiry": "2024-10-30T20:18:03.194400Z"}
|
Loading…
Reference in New Issue
Block a user