langgraph-cli 0.1.4__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langgraph-cli
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary:
5
5
  Author: Nuno Campos
6
6
  Author-email: nuno@langchain.dev
@@ -179,6 +179,70 @@ def up(
179
179
  runner.run(exec("docker", "compose", *args, input=stdin))
180
180
 
181
181
 
182
+ @OPT_C
183
+ @click.option("--tag", "-t", help="Tag for the image", required=True)
184
+ @cli.command(help="Build langgraph API server image")
185
+ def build(
186
+ config: pathlib.Path,
187
+ tag: str,
188
+ ):
189
+ with asyncio.Runner() as runner:
190
+ # check docker available
191
+ try:
192
+ runner.run(exec("docker", "--version"))
193
+ runner.run(exec("docker", "compose", "version"))
194
+ except click.exceptions.Exit:
195
+ click.echo("Docker not installed or not running")
196
+ return
197
+ # apply options
198
+ args = [
199
+ "-f",
200
+ "-", # stdin
201
+ "-t",
202
+ tag,
203
+ ]
204
+ with open(config) as f:
205
+ stdin = langgraph_cli.config.config_to_docker(config, json.load(f))
206
+ # run docker build
207
+ runner.run(exec("docker", "build", *args, config.parent, input=stdin))
208
+
209
+
210
+ @OPT_DEBUGGER_PORT
211
+ @OPT_PORT
212
+ @OPT_O
213
+ @OPT_C
214
+ @cli.command(help="Write k8s files", hidden=True)
215
+ def k8s(
216
+ config: pathlib.Path,
217
+ docker_compose: Optional[pathlib.Path],
218
+ port: int,
219
+ debugger_port: Optional[int],
220
+ ):
221
+ with asyncio.Runner() as runner:
222
+ # check docker available
223
+ try:
224
+ runner.run(exec("docker", "--version"))
225
+ runner.run(exec("docker", "compose", "version"))
226
+ except click.exceptions.Exit:
227
+ click.echo("Docker not installed or not running")
228
+ return
229
+ # prepare args
230
+ stdin = langgraph_cli.docker.compose(port=port, debugger_port=debugger_port)
231
+ args = [
232
+ "-f",
233
+ "-", # stdin
234
+ ]
235
+ # apply options
236
+ if docker_compose:
237
+ args.extend(["-f", str(docker_compose)])
238
+ args.append("convert")
239
+ if config:
240
+ with open(config) as f:
241
+ stdin += langgraph_cli.config.config_to_compose(config, json.load(f))
242
+ # run kompose convert
243
+ runner.run(exec("kompose", *args, input=stdin))
244
+
245
+
182
246
  @OPT_O
183
247
  @OPT_PORT
184
248
  @cli.command()
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import os
3
3
  import pathlib
4
+ import textwrap
4
5
  from typing import TypedDict, Union
5
6
 
6
7
 
@@ -10,7 +11,7 @@ class Config(TypedDict):
10
11
  env: Union[dict[str, str], str]
11
12
 
12
13
 
13
- def config_to_compose(config_path: pathlib.Path, config: Config):
14
+ def config_to_docker(config_path: pathlib.Path, config: Config):
14
15
  pypi_deps = [dep for dep in config["dependencies"] if not dep.startswith(".")]
15
16
  local_pkgs: dict[pathlib.Path, str] = {}
16
17
  faux_pkgs: dict[pathlib.Path, str] = {}
@@ -83,7 +84,23 @@ def config_to_compose(config_path: pathlib.Path, config: Config):
83
84
  f"ADD {relpath} /tmp/{fullpath.name}/{fullpath.name}\n RUN touch /tmp/{fullpath.name}/pyproject.toml"
84
85
  for fullpath, relpath in faux_pkgs.items()
85
86
  )
86
- local_pkgs_str = f"ADD {' '.join(local_pkgs.values())} /tmp/" if local_pkgs else ""
87
+ local_pkgs_str = "\n".join(
88
+ f"ADD {relpath} /tmp/{fullpath.name}"
89
+ for fullpath, relpath in local_pkgs.items()
90
+ )
91
+
92
+ return f"""FROM langchain/langgraph-api
93
+
94
+ ENV LANGSERVE_GRAPHS='{json.dumps(config["graphs"])}'
95
+
96
+ {local_pkgs_str}
97
+
98
+ {faux_pkgs_str}
99
+
100
+ RUN pip install {' '.join(pypi_deps)} /tmp/*"""
101
+
102
+
103
+ def config_to_compose(config_path: pathlib.Path, config: Config):
87
104
  env_vars_str = (
88
105
  "\n".join(f" {k}: {v}" for k, v in config["env"].items())
89
106
  if isinstance(config["env"], dict)
@@ -94,17 +111,10 @@ def config_to_compose(config_path: pathlib.Path, config: Config):
94
111
  )
95
112
 
96
113
  return f"""
97
- LANGSERVE_GRAPHS: '{json.dumps(config["graphs"])}'
98
114
  {env_vars_str}
99
115
  {env_file_str}
100
116
  pull_policy: build
101
117
  build:
102
118
  dockerfile_inline: |
103
- FROM langchain/langserve
104
-
105
- {local_pkgs_str}
106
-
107
- {faux_pkgs_str}
108
-
109
- RUN pip install {' '.join(pypi_deps)} /tmp/*
119
+ {textwrap.indent(config_to_docker(config_path, config), " ")}
110
120
  """
@@ -6,7 +6,7 @@ ROOT = pathlib.Path(__file__).parent.resolve()
6
6
 
7
7
 
8
8
  DB = f"""
9
- postgres:
9
+ langgraph-postgres:
10
10
  image: postgres:16
11
11
  restart: on-failure
12
12
  healthcheck:
@@ -22,18 +22,18 @@ DB = f"""
22
22
  POSTGRES_USER: postgres
23
23
  POSTGRES_PASSWORD: postgres
24
24
  volumes:
25
- - ./.langserve-data:/var/lib/postgresql/data
25
+ - ./.langgraph-data:/var/lib/postgresql/data
26
26
  - {ROOT}/initdb:/docker-entrypoint-initdb.d
27
27
  """
28
28
 
29
29
  DEBUGGER = """
30
- debugger:
30
+ langgraph-debugger:
31
31
  image: langchain/langserve-debugger
32
- restart: on-failure:3
32
+ restart: on-failure
33
33
  ports:
34
34
  - "{debugger_port}:5173"
35
35
  depends_on:
36
- langserve:
36
+ langgraph-api:
37
37
  condition: service_healthy
38
38
  environment:
39
39
  VITE_API_BASE_URL: http://localhost:{port}
@@ -49,7 +49,7 @@ def compose(
49
49
  ) -> str:
50
50
  if postgres_uri is None:
51
51
  include_db = True
52
- postgres_uri = "postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable&search_path=langserve"
52
+ postgres_uri = "postgres://postgres:postgres@langgraph-postgres:5432/postgres?sslmode=disable&search_path=langgraph"
53
53
  else:
54
54
  include_db = False
55
55
 
@@ -57,22 +57,14 @@ def compose(
57
57
  services:
58
58
  {DB if include_db else ""}
59
59
  {DEBUGGER.format(port=port, debugger_port=debugger_port) if debugger_port else ""}
60
- migrate:
61
- image: langchain/langserve-migrate
62
- pull_policy: always
63
- {'''depends_on:
64
- postgres:
65
- condition: service_healthy''' if include_db else ""}
66
- environment:
67
- POSTGRES_URI: {postgres_uri}
68
- langserve:
69
- image: langchain/langserve
70
- restart: on-failure:3
60
+ langgraph-api:
61
+ image: langchain/langgraph-api
62
+ restart: on-failure
71
63
  ports:
72
64
  - "{port}:8000"
73
65
  depends_on:
74
- migrate:
75
- condition: service_completed_successfully
66
+ langgraph-postgres:
67
+ condition: service_healthy
76
68
  environment:
77
69
  POSTGRES_URI: {postgres_uri}
78
70
  """
@@ -0,0 +1 @@
1
+ create schema if not exists langgraph;
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langgraph-cli"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = ""
5
5
  authors = ["Nuno Campos <nuno@langchain.dev>"]
6
6
  readme = "README.md"
@@ -1 +0,0 @@
1
- create schema if not exists langserve;
File without changes