Skip to content

Commit

Permalink
feat(cli): add debugger host CLI flag to specify default base URL (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd authored Jul 9, 2024
1 parent bb6785b commit 293bc2c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
18 changes: 17 additions & 1 deletion libs/cli/langgraph_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
type=int,
help="Pull the debugger image locally and serve the UI on specified port",
)
OPT_DEBUGGER_BASE_URL = click.option(
"--debugger-base-url",
type=str,
help="URL used by the debugger to access LangGraph API. Defaults to http://127.0.0.1:[PORT]",
)

OPT_POSTGRES_URI = click.option(
"--postgres-uri",
help="Postgres URI to use for the database. Defaults to launching a local database",
Expand All @@ -152,6 +158,7 @@ def cli():
@OPT_CONFIG
@OPT_VERBOSE
@OPT_DEBUGGER_PORT
@OPT_DEBUGGER_BASE_URL
@OPT_WATCH
@OPT_POSTGRES_URI
@click.option(
Expand All @@ -173,6 +180,7 @@ def up(
wait: bool,
verbose: bool,
debugger_port: Optional[int],
debugger_base_url: Optional[str],
postgres_uri: Optional[str],
):
click.secho("Starting LangGraph API server...", fg="green")
Expand All @@ -193,6 +201,7 @@ def up(
watch=watch,
verbose=verbose,
debugger_port=debugger_port,
debugger_base_url=debugger_base_url,
postgres_uri=postgres_uri,
)
# add up + options
Expand Down Expand Up @@ -221,12 +230,15 @@ def on_stdout(line: str):
if debugger_port
else "https://smith.langchain.com"
)
debugger_base_url_query = (
debugger_base_url or f"http://127.0.0.1:{port}"
)
set("")
sys.stdout.write(
f"""Ready!
- API: http://localhost:{port}
- Docs: http://localhost:{port}/docs
- Debugger: {debugger_origin}/studio/?baseUrl=http://127.0.0.1:{port}
- Debugger: {debugger_origin}/studio/?baseUrl={debugger_base_url_query}
"""
)
sys.stdout.flush()
Expand Down Expand Up @@ -449,13 +461,15 @@ def prepare_args_and_stdin(
port: int,
watch: bool,
debugger_port: Optional[int] = None,
debugger_base_url: Optional[str] = None,
postgres_uri: Optional[str] = None,
):
# prepare args
stdin = langgraph_cli.docker.compose(
capabilities,
port=port,
debugger_port=debugger_port,
debugger_base_url=debugger_base_url,
postgres_uri=postgres_uri,
)
args = [
Expand Down Expand Up @@ -487,6 +501,7 @@ def prepare(
watch: bool,
verbose: bool,
debugger_port: Optional[int] = None,
debugger_base_url: Optional[str] = None,
postgres_uri: Optional[str] = None,
):
with open(config_path) as f:
Expand All @@ -510,6 +525,7 @@ def prepare(
port=port,
watch=watch,
debugger_port=debugger_port,
debugger_base_url=debugger_base_url or f"http://127.0.0.1:{port}",
postgres_uri=postgres_uri,
)
return args, stdin
41 changes: 28 additions & 13 deletions libs/cli/langgraph_cli/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@
"""


DEBUGGER = """
langgraph-debugger:
image: langchain/langgraph-debugger
restart: on-failure
ports:
- "{debugger_port}:3968"
depends_on:
langgraph-postgres:
condition: service_healthy
"""


class Version(NamedTuple):
major: int
minor: int
Expand Down Expand Up @@ -117,11 +105,38 @@ def check_capabilities(runner) -> DockerCapabilities:
)


def debugger_compose(
*, port: Optional[int] = None, base_url: Optional[str] = None
) -> str:
if port is None:
return ""

compose_str = """
langgraph-debugger:
image: langchain/langgraph-debugger
restart: on-failure
depends_on:
langgraph-postgres:
condition: service_healthy
ports:
- "{port}:3968"
"""

if base_url:
compose_str += """
environment:
VITE_STUDIO_LOCAL_GRAPH_URL: {base_url}
"""

return compose_str.format(port=port, base_url=base_url)


def compose(
capabilities: DockerCapabilities,
*,
port: int,
debugger_port: Optional[int] = None,
debugger_base_url: Optional[str] = None,
# postgres://user:password@host:port/database?option=value
postgres_uri: Optional[str] = None,
) -> str:
Expand Down Expand Up @@ -151,7 +166,7 @@ def compose(

compose_str = f"""{volumes}services:
{db}
{DEBUGGER.format(debugger_port=debugger_port) if debugger_port else ""}
{debugger_compose(port=debugger_port, base_url=debugger_base_url)}
langgraph-api:
ports:
- "{port}:8000\""""
Expand Down
8 changes: 6 additions & 2 deletions libs/cli/tests/unit_tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_prepare_args_and_stdin():
)
port = 8000
debugger_port = 8001
debugger_graph_url = f"http://127.0.0.1:{port}"

actual_args, actual_stdin = prepare_args_and_stdin(
capabilities=DEFAULT_DOCKER_CAPABILITIES,
Expand All @@ -28,6 +29,7 @@ def test_prepare_args_and_stdin():
docker_compose="custom-docker-compose.yml",
port=port,
debugger_port=debugger_port,
debugger_base_url=debugger_graph_url,
watch=True,
)

Expand Down Expand Up @@ -63,11 +65,13 @@ def test_prepare_args_and_stdin():
langgraph-debugger:
image: langchain/langgraph-debugger
restart: on-failure
ports:
- "{debugger_port}:3968"
depends_on:
langgraph-postgres:
condition: service_healthy
ports:
- "{debugger_port}:3968"
environment:
VITE_STUDIO_LOCAL_GRAPH_URL: {debugger_graph_url}
langgraph-api:
ports:
- "8000:8000"
Expand Down

0 comments on commit 293bc2c

Please sign in to comment.