mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
cli updates oct27 (#12436)
This commit is contained in:
parent
3fd9f2752f
commit
6908634428
@ -1,4 +1,3 @@
|
|||||||
import subprocess
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
@ -24,12 +23,12 @@ def start(
|
|||||||
"""
|
"""
|
||||||
Start the LangServe instance, whether it's a hub package or a serve project.
|
Start the LangServe instance, whether it's a hub package or a serve project.
|
||||||
"""
|
"""
|
||||||
cmd = ["poetry", "run", "poe", "start"]
|
|
||||||
if port is not None:
|
# try starting hub package, if error, try langserve
|
||||||
cmd += ["--port", str(port)]
|
try:
|
||||||
if host is not None:
|
hub.start(port=port, host=host)
|
||||||
cmd += ["--host", host]
|
except KeyError:
|
||||||
subprocess.run(cmd)
|
serve.start(port=port, host=host)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -9,8 +9,11 @@ from pathlib import Path
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
from langserve.packages import get_langserve_export
|
||||||
from typing_extensions import Annotated
|
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)
|
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")],
|
name: Annotated[str, typer.Argument(help="The name of the folder to create")],
|
||||||
with_poetry: Annotated[
|
with_poetry: Annotated[
|
||||||
bool,
|
bool,
|
||||||
typer.Option(
|
typer.Option("--with-poetry/--no-poetry", help="Don't run poetry install"),
|
||||||
"--with-poetry/--no-poetry", help="Don't run poetry install"
|
|
||||||
),
|
|
||||||
] = False,
|
] = False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -82,9 +83,23 @@ def start(
|
|||||||
"""
|
"""
|
||||||
Starts a demo LangServe instance for this hub package.
|
Starts a demo LangServe instance for this hub package.
|
||||||
"""
|
"""
|
||||||
cmd = ["poetry", "run", "poe", "start"]
|
# load pyproject.toml
|
||||||
if port is not None:
|
project_dir = get_package_root()
|
||||||
cmd += ["--port", str(port)]
|
pyproject = project_dir / "pyproject.toml"
|
||||||
if host is not None:
|
|
||||||
cmd += ["--host", host]
|
# get langserve export - throws KeyError if invalid
|
||||||
subprocess.run(cmd)
|
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[
|
host: Annotated[
|
||||||
Optional[str], typer.Option(help="The host to run the server on")
|
Optional[str], typer.Option(help="The host to run the server on")
|
||||||
] = None,
|
] = None,
|
||||||
|
app: Annotated[Optional[str], typer.Option(help="The app to run")] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Starts the LangServe instance.
|
Starts the LangServe instance.
|
||||||
"""
|
"""
|
||||||
cmd = ["poetry", "run", "poe", "start"]
|
|
||||||
if port is not None:
|
app_str = app if app is not None else "app.server:app"
|
||||||
cmd += ["--port", str(port)]
|
port_str = str(port) if port is not None else "8000"
|
||||||
if host is not None:
|
host_str = host if host is not None else "127.0.0.1"
|
||||||
cmd += ["--host", host]
|
|
||||||
|
cmd = ["uvicorn", app_str, "--reload", "--port", port_str, "--host", host_str]
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
|
@ -11,7 +11,6 @@ langchain = ">=0.0.313, <0.1"
|
|||||||
openai = "^0.28.1"
|
openai = "^0.28.1"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
poethepoet = "^0.24.1"
|
|
||||||
langchain-cli = ">=0.0.4"
|
langchain-cli = ">=0.0.4"
|
||||||
fastapi = "^0.104.0"
|
fastapi = "^0.104.0"
|
||||||
sse-starlette = "^1.6.5"
|
sse-starlette = "^1.6.5"
|
||||||
@ -20,13 +19,6 @@ sse-starlette = "^1.6.5"
|
|||||||
export_module = "__package_name__.chain"
|
export_module = "__package_name__.chain"
|
||||||
export_attr = "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]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
@ -9,4 +9,4 @@ add_routes(app, NotImplemented)
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8001)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
|
@ -14,17 +14,9 @@ fastapi = "^0.103.2"
|
|||||||
langserve = ">=0.0.16"
|
langserve = ">=0.0.16"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
poethepoet = "^0.24.1"
|
|
||||||
uvicorn = "^0.23.2"
|
uvicorn = "^0.23.2"
|
||||||
pygithub = "^2.1.1"
|
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]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "langchain-cli"
|
name = "langchain-cli"
|
||||||
version = "0.0.5"
|
version = "0.0.6"
|
||||||
description = "CLI for interacting with LangChain"
|
description = "CLI for interacting with LangChain"
|
||||||
authors = ["Erick Friis <erick@langchain.dev>"]
|
authors = ["Erick Friis <erick@langchain.dev>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
Templates for a fully functioning app that can be hosted by LangServe.
|
Templates for a fully functioning app that can be hosted by LangServe.
|
||||||
|
|
||||||
|
Some other helpful docs:
|
||||||
|
|
||||||
|
- [Templates]
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To use, first install the LangChain CLI.
|
To use, first install the LangChain CLI.
|
||||||
@ -13,7 +17,7 @@ pip install -U langchain-cli
|
|||||||
Then, install `langserve`:
|
Then, install `langserve`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
pip install "langserve[all]"
|
pip install -U "langserve[all]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, create a new LangChain project:
|
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
|
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`.
|
In order to have LangServe use this project, you then need to modify `app/server.py`.
|
||||||
Specifically, you should add something like:
|
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:
|
You can then spin up production-ready endpoints, along with a playground, by running:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
python app/server.py
|
langchain start
|
||||||
```
|
```
|
||||||
|
|
||||||
## Adding a template
|
## Adding a template
|
||||||
|
Loading…
Reference in New Issue
Block a user