2023-10-25 18:06:58 +00:00
|
|
|
from typing import Optional
|
2023-10-27 00:01:31 +00:00
|
|
|
|
|
|
|
import typer
|
2023-10-25 18:06:58 +00:00
|
|
|
from typing_extensions import Annotated
|
|
|
|
|
2023-10-27 00:01:31 +00:00
|
|
|
from langchain_cli.namespaces import hub, serve
|
2023-10-25 18:06:58 +00:00
|
|
|
|
|
|
|
app = typer.Typer(no_args_is_help=True, add_completion=False)
|
|
|
|
app.add_typer(hub.hub, name="hub", help=hub.__doc__)
|
|
|
|
app.add_typer(serve.serve, name="serve", help=serve.__doc__)
|
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def start(
|
|
|
|
*,
|
|
|
|
port: Annotated[
|
|
|
|
Optional[int], typer.Option(help="The port to run the server on")
|
|
|
|
] = None,
|
|
|
|
host: Annotated[
|
|
|
|
Optional[str], typer.Option(help="The host to run the server on")
|
|
|
|
] = None,
|
|
|
|
) -> None:
|
|
|
|
"""
|
|
|
|
Start the LangServe instance, whether it's a hub package or a serve project.
|
|
|
|
"""
|
2023-10-27 19:06:46 +00:00
|
|
|
|
|
|
|
# try starting hub package, if error, try langserve
|
|
|
|
try:
|
|
|
|
hub.start(port=port, host=host)
|
|
|
|
except KeyError:
|
|
|
|
serve.start(port=port, host=host)
|
2023-10-25 18:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app()
|