mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 03:59:42 +00:00
cli updates oct27 (#12436)
This commit is contained in:
@@ -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)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user