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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 42 deletions

View File

@ -1,4 +1,3 @@
import subprocess
from typing import Optional
import typer
@ -24,12 +23,12 @@ def start(
"""
Start the LangServe instance, whether it's a hub package or a serve project.
"""
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)
# try starting hub package, if error, try langserve
try:
hub.start(port=port, host=host)
except KeyError:
serve.start(port=port, host=host)
if __name__ == "__main__":

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)

View File

@ -11,7 +11,6 @@ langchain = ">=0.0.313, <0.1"
openai = "^0.28.1"
[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.1"
langchain-cli = ">=0.0.4"
fastapi = "^0.104.0"
sse-starlette = "^1.6.5"
@ -20,13 +19,6 @@ sse-starlette = "^1.6.5"
export_module = "__package_name__.chain"
export_attr = "chain"
[tool.poe.tasks.start]
cmd="uvicorn langchain_cli.dev_scripts:create_demo_server --reload --port $port --host $host"
args = [
{name = "port", help = "port to run on", default = "8000"},
{name = "host", help = "host to run on", default = "127.0.0.1"}
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@ -9,4 +9,4 @@ add_routes(app, NotImplemented)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)
uvicorn.run(app, host="0.0.0.0", port=8000)

View File

@ -14,17 +14,9 @@ fastapi = "^0.103.2"
langserve = ">=0.0.16"
[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.1"
uvicorn = "^0.23.2"
pygithub = "^2.1.1"
[tool.poe.tasks.start]
cmd="uvicorn app.server:app --reload --port $port --host $host"
args = [
{name = "port", help = "port to run on", default = "8000"},
{name = "host", help = "host to run on", default = "127.0.0.1"}
]
[build-system]
requires = ["poetry-core"]

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain-cli"
version = "0.0.5"
version = "0.0.6"
description = "CLI for interacting with LangChain"
authors = ["Erick Friis <erick@langchain.dev>"]
readme = "README.md"

View File

@ -2,6 +2,10 @@
Templates for a fully functioning app that can be hosted by LangServe.
Some other helpful docs:
- [Templates]
## Usage
To use, first install the LangChain CLI.
@ -13,7 +17,7 @@ pip install -U langchain-cli
Then, install `langserve`:
```shell
pip install "langserve[all]"
pip install -U "langserve[all]"
```
Next, create a new LangChain project:
@ -47,7 +51,7 @@ You then need to install this package so you can use it in the langserve app:
pip install -e packages/$PROJECT_NAME
```
We install it with `-e` so that if we modify the template at all (which we likely will) the changes are updated.
We install it with `-e` so that if you modify the template at all (which you likely will) the changes are updated.
In order to have LangServe use this project, you then need to modify `app/server.py`.
Specifically, you should add something like:
@ -66,7 +70,7 @@ add_routes(app, chain)
You can then spin up production-ready endpoints, along with a playground, by running:
```shell
python app/server.py
langchain start
```
## Adding a template