cli updates oct27 (#12436)

This commit is contained in:
Erick Friis
2023-10-27 12:06:46 -07:00
committed by GitHub
parent 3fd9f2752f
commit 6908634428
8 changed files with 46 additions and 42 deletions

View File

@@ -9,8 +9,11 @@ from pathlib import Path
from typing import Optional
import typer
from langserve.packages import get_langserve_export
from typing_extensions import Annotated
from langchain_cli.utils.packages import get_package_root
hub = typer.Typer(no_args_is_help=True, add_completion=False)
@@ -19,9 +22,7 @@ def new(
name: Annotated[str, typer.Argument(help="The name of the folder to create")],
with_poetry: Annotated[
bool,
typer.Option(
"--with-poetry/--no-poetry", help="Don't run poetry install"
),
typer.Option("--with-poetry/--no-poetry", help="Don't run poetry install"),
] = False,
):
"""
@@ -82,9 +83,23 @@ def start(
"""
Starts a demo LangServe instance for this hub package.
"""
cmd = ["poetry", "run", "poe", "start"]
if port is not None:
cmd += ["--port", str(port)]
if host is not None:
cmd += ["--host", host]
subprocess.run(cmd)
# load pyproject.toml
project_dir = get_package_root()
pyproject = project_dir / "pyproject.toml"
# get langserve export - throws KeyError if invalid
get_langserve_export(pyproject)
port_str = str(port) if port is not None else "8000"
host_str = host if host is not None else "127.0.0.1"
command = [
"uvicorn",
"langchain_cli.dev_scripts:create_demo_server",
"--reload",
"--port",
port_str,
"--host",
host_str,
]
subprocess.run(command)

View File

@@ -218,13 +218,15 @@ def start(
host: Annotated[
Optional[str], typer.Option(help="The host to run the server on")
] = None,
app: Annotated[Optional[str], typer.Option(help="The app to run")] = None,
) -> None:
"""
Starts the LangServe instance.
"""
cmd = ["poetry", "run", "poe", "start"]
if port is not None:
cmd += ["--port", str(port)]
if host is not None:
cmd += ["--host", host]
app_str = app if app is not None else "app.server:app"
port_str = str(port) if port is not None else "8000"
host_str = host if host is not None else "127.0.0.1"
cmd = ["uvicorn", app_str, "--reload", "--port", port_str, "--host", host_str]
subprocess.run(cmd)