Skip to content

Commit b55ba02

Browse files
committed
deployment steps added
1 parent f97e9e6 commit b55ba02

File tree

6 files changed

+702
-0
lines changed

6 files changed

+702
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "xDtrRfNmaIzV"
7+
},
8+
"source": [
9+
"# Creating a deployment\n",
10+
"\n",
11+
"Let's create a deployment of the `task_maistro` app that we created in module 5.\n",
12+
"\n",
13+
"## Code structure\n",
14+
"\n",
15+
"[The following information should be provided](https://langchain-ai.github.io/langgraph/concepts/application_structure/) to create a LangGraph Platform deployment:\n",
16+
"\n",
17+
"* A [LangGraph API Configuration file](https://langchain-ai.github.io/langgraph/concepts/application_structure/#configuration-file) - `langgraph.json`\n",
18+
"* The graphs that implement the logic of the application - e.g., `task_maistro.py`\n",
19+
"* A file that specifies dependencies required to run the application - `requirements.txt`\n",
20+
"* Supply environment variables needed for the application to run - `.env` or `docker-compose.yml`\n",
21+
"\n",
22+
"We have this already in the `module-6/deployment` directory!\n",
23+
"\n",
24+
"## CLI\n",
25+
"\n",
26+
"The [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli/) is a command-line interface for creating a LangGraph Platform deployment."
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"metadata": {
33+
"id": "dt8qCZr_aIzg"
34+
},
35+
"outputs": [],
36+
"source": [
37+
"%%capture --no-stderr\n",
38+
"%pip install -U langgraph-cli"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {
44+
"id": "nKLJCLY9aIzk"
45+
},
46+
"source": [
47+
"To create a [self-hosted deployment](https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/#how-to-do-a-self-hosted-deployment-of-langgraph), we'll follow a few steps.\n",
48+
"\n",
49+
"### Build Docker Image for LangGraph Server\n",
50+
"\n",
51+
"We first use the langgraph CLI to create a Docker image for the [LangGraph Server](https://docs.google.com/presentation/d/18MwIaNR2m4Oba6roK_2VQcBE_8Jq_SI7VHTXJdl7raU/edit#slide=id.g313fb160676_0_32).\n",
52+
"\n",
53+
"This will package our graph and dependencies into a Docker image.\n",
54+
"\n",
55+
"A Docker image is a template for a Docker container that contains the code and dependencies required to run the application.\n",
56+
"\n",
57+
"Ensure that [Docker](https://docs.docker.com/engine/install/) is installed and then run the following command to create the Docker image, `my-image`:\n",
58+
"\n",
59+
"```\n",
60+
"$ cd module-6/deployment\n",
61+
"$ langgraph build -t my-image\n",
62+
"```\n",
63+
"\n",
64+
"### Set Up Redis and PostgreSQL\n",
65+
"\n",
66+
"If you already have Redis and PostgreSQL running (e.g., locally or on other servers), then create and run the LangGraph Server container [by itself](https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/#running-the-application-locally) with the URIs for Redis and PostgreSQL:\n",
67+
"\n",
68+
"```\n",
69+
"docker run \\\n",
70+
" --env-file .env \\\n",
71+
" -p 8123:8000 \\\n",
72+
" -e REDIS_URI=\"foo\" \\\n",
73+
" -e DATABASE_URI=\"bar\" \\\n",
74+
" -e LANGSMITH_API_KEY=\"baz\" \\\n",
75+
" my-image\n",
76+
"```\n",
77+
"\n",
78+
"Alternatively, you can use the provided `docker-compose.yml` file to create three separate containers based on the services defined:\n",
79+
"\n",
80+
"* `langgraph-redis`: Creates a new container using the official Redis image.\n",
81+
"* `langgraph-postgres`: Creates a new container using the official Postgres image.\n",
82+
"* `langgraph-api`: Creates a new container using your pre-built image.\n",
83+
"\n",
84+
"Simply copy the `docker-compose-example.yml` and add the following environment variables to run the deployed `task_maistro` app:\n",
85+
"\n",
86+
"* `IMAGE_NAME` (e.g., `my-image`)\n",
87+
"* `LANGCHAIN_API_KEY`\n",
88+
"* `OPENAI_API_KEY`\n",
89+
"\n",
90+
"Then, [launch the deployment](https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/#using-docker-compose):\n",
91+
"\n",
92+
"```\n",
93+
"$ cd module-6/deployment\n",
94+
"$ docker compose up\n",
95+
"```"
96+
]
97+
},
98+
{
99+
"cell_type": "markdown",
100+
"metadata": {
101+
"id": "SsGtrOMVaIzn"
102+
},
103+
"source": []
104+
}
105+
],
106+
"metadata": {
107+
"kernelspec": {
108+
"display_name": "Python 3 (ipykernel)",
109+
"language": "python",
110+
"name": "python3"
111+
},
112+
"language_info": {
113+
"codemirror_mode": {
114+
"name": "ipython",
115+
"version": 3
116+
},
117+
"file_extension": ".py",
118+
"mimetype": "text/x-python",
119+
"name": "python",
120+
"nbconvert_exporter": "python",
121+
"pygments_lexer": "ipython3",
122+
"version": "3.11.8"
123+
},
124+
"colab": {
125+
"provenance": []
126+
}
127+
},
128+
"nbformat": 4,
129+
"nbformat_minor": 0
130+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
from dataclasses import dataclass, field, fields
3+
from typing import Any, Optional
4+
5+
from langchain_core.runnables import RunnableConfig
6+
from typing_extensions import Annotated
7+
from dataclasses import dataclass
8+
9+
10+
@dataclass(kw_only=True)
11+
class Configuration:
12+
"""The configurable fields for the chatbot."""
13+
14+
user_id: str = "default-user"
15+
todo_category: str = "general"
16+
task_maistro_role: str = (
17+
"You are a helpful task management assistant. You help you create, organize, and manage the user's ToDo list."
18+
)
19+
20+
@classmethod
21+
def from_runnable_config(
22+
cls, config: Optional[RunnableConfig] = None
23+
) -> "Configuration":
24+
"""Create a Configuration instance from a RunnableConfig."""
25+
configurable = (
26+
config["configurable"] if config and "configurable" in config else {}
27+
)
28+
values: dict[str, Any] = {
29+
f.name: os.environ.get(f.name.upper(), configurable.get(f.name))
30+
for f in fields(cls)
31+
if f.init
32+
}
33+
return cls(**{k: v for k, v in values.items() if v})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
volumes:
2+
langgraph-data:
3+
driver: local
4+
services:
5+
langgraph-redis:
6+
image: redis:6
7+
healthcheck:
8+
test: redis-cli ping
9+
interval: 5s
10+
timeout: 1s
11+
retries: 5
12+
langgraph-postgres:
13+
image: postgres:16
14+
ports:
15+
- "5433:5432"
16+
environment:
17+
POSTGRES_DB: postgres
18+
POSTGRES_USER: postgres
19+
POSTGRES_PASSWORD: postgres
20+
volumes:
21+
- langgraph-data:/var/lib/postgresql/data
22+
healthcheck:
23+
test: pg_isready -U postgres
24+
start_period: 10s
25+
timeout: 1s
26+
retries: 5
27+
interval: 5s
28+
langgraph-api:
29+
image: "my-image"
30+
ports:
31+
- "8123:8000"
32+
depends_on:
33+
langgraph-redis:
34+
condition: service_healthy
35+
langgraph-postgres:
36+
condition: service_healthy
37+
environment:
38+
REDIS_URI: redis://langgraph-redis:6379
39+
OPENAI_API_KEY: "xxx"
40+
LANGSMITH_API_KEY: "xxx"
41+
POSTGRES_URI: postgres://postgres:postgres@langgraph-postgres:5432/postgres?sslmode=disable
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"dockerfile_lines": [],
3+
"graphs": {
4+
"task_maistro": "./task_maistro.py:graph"
5+
},
6+
"python_version": "3.11",
7+
"dependencies": [
8+
"."
9+
]
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
langgraph
2+
langchain-core
3+
langchain-community
4+
langchain-openai
5+
trustcall

0 commit comments

Comments
 (0)