Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add debugger host CLI flag to specify default base URL #900

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -448,13 +460,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 @@ -486,6 +500,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 @@ -509,6 +524,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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not very intuitive. could we do this check on host instead?

  • cli option for host: no default in click
  • cli option for port: default to DEFAULT_PORT in click

and below add environment only if host != localhost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really for changing the host of the debugger image, rather to change the default URL used by the debugger to access the LangGraph API.

Renamed the CLI flag to closely match the intent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that makes sense, thanks for clarifying!

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
Loading