Skip to content

Commit

Permalink
CLI 0.0.14, Uvicorn update and no more [serve] (langchain-ai#12845)
Browse files Browse the repository at this point in the history
Calls uvicorn directly from cli:
Reload works if you define app by import string instead of object.
(was doing subprocess in order to get reloading)

Version bump to 0.0.14

Remove the need for [serve] for simplicity.

Readmes are updated in langchain-ai#12847 to avoid cluttering this PR
  • Loading branch information
efriis authored and xieqihui committed Nov 21, 2023
1 parent e4ed127 commit 1717498
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion libs/cli/langchain_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from langchain_cli.namespaces import app as app_namespace
from langchain_cli.namespaces import template as template_namespace

__version__ = "0.0.13"
__version__ = "0.0.14"

app = typer.Typer(no_args_is_help=True, add_completion=False)
app.add_typer(
Expand Down
8 changes: 5 additions & 3 deletions libs/cli/langchain_cli/namespaces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@ def serve(
"""

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)
import uvicorn

uvicorn.run(
app_str, host=host_str, port=port if port is not None else 8000, reload=True
)
19 changes: 8 additions & 11 deletions libs/cli/langchain_cli/namespaces/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def serve(
# 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"

script = (
Expand All @@ -122,14 +121,12 @@ def serve(
else "langchain_cli.dev_scripts:create_demo_server_configurable"
)

command = [
"uvicorn",
"--factory",
import uvicorn

uvicorn.run(
script,
"--reload",
"--port",
port_str,
"--host",
host_str,
]
subprocess.run(command)
factory=True,
reload=True,
port=port if port is not None else 8000,
host=host_str,
)
Loading

0 comments on commit 1717498

Please sign in to comment.