mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 19:47:13 +00:00
add a template for the package readme (#12499)
Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
207
libs/cli/DOCS.md
207
libs/cli/DOCS.md
@@ -12,18 +12,18 @@ $ langchain [OPTIONS] COMMAND [ARGS]...
|
|||||||
|
|
||||||
**Commands**:
|
**Commands**:
|
||||||
|
|
||||||
* `hub`: Manage installable hub packages.
|
* `app`: Manage LangChain apps
|
||||||
* `serve`: Manage LangServe application projects.
|
* `serve`: Start the LangServe app, whether it's a...
|
||||||
* `start`: Start the LangServe instance, whether it's...
|
* `template`: Develop installable templates.
|
||||||
|
|
||||||
## `langchain hub`
|
## `langchain app`
|
||||||
|
|
||||||
Manage installable hub packages.
|
Manage LangChain apps
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain hub [OPTIONS] COMMAND [ARGS]...
|
$ langchain app [OPTIONS] COMMAND [ARGS]...
|
||||||
```
|
```
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
@@ -32,182 +32,157 @@ $ langchain hub [OPTIONS] COMMAND [ARGS]...
|
|||||||
|
|
||||||
**Commands**:
|
**Commands**:
|
||||||
|
|
||||||
* `new`: Creates a new hub package.
|
* `add`: Adds the specified template to the current...
|
||||||
* `start`: Starts a demo LangServe instance for this...
|
|
||||||
|
|
||||||
### `langchain hub new`
|
|
||||||
|
|
||||||
Creates a new hub package.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ langchain hub new [OPTIONS] NAME
|
|
||||||
```
|
|
||||||
|
|
||||||
**Arguments**:
|
|
||||||
|
|
||||||
* `NAME`: [required]
|
|
||||||
|
|
||||||
**Options**:
|
|
||||||
|
|
||||||
* `--help`: Show this message and exit.
|
|
||||||
|
|
||||||
### `langchain hub start`
|
|
||||||
|
|
||||||
Starts a demo LangServe instance for this hub package.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ langchain hub start [OPTIONS]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Options**:
|
|
||||||
|
|
||||||
* `--port INTEGER`
|
|
||||||
* `--host TEXT`
|
|
||||||
* `--help`: Show this message and exit.
|
|
||||||
|
|
||||||
## `langchain serve`
|
|
||||||
|
|
||||||
Manage LangServe application projects.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ langchain serve [OPTIONS] COMMAND [ARGS]...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Options**:
|
|
||||||
|
|
||||||
* `--help`: Show this message and exit.
|
|
||||||
|
|
||||||
**Commands**:
|
|
||||||
|
|
||||||
* `add`: Adds the specified package to the current...
|
|
||||||
* `install`
|
|
||||||
* `list`: Lists all packages in the current...
|
|
||||||
* `new`: Create a new LangServe application.
|
* `new`: Create a new LangServe application.
|
||||||
* `remove`: Removes the specified package from the...
|
* `remove`: Removes the specified package from the...
|
||||||
* `start`: Starts the LangServe instance.
|
* `serve`: Starts the LangServe app.
|
||||||
|
|
||||||
### `langchain serve add`
|
### `langchain app add`
|
||||||
|
|
||||||
Adds the specified package to the current LangServe instance.
|
Adds the specified template to the current LangServe app.
|
||||||
|
|
||||||
e.g.:
|
e.g.:
|
||||||
langchain serve add extraction-openai-functions
|
langchain app add extraction-openai-functions
|
||||||
langchain serve add git+ssh://git@github.com/efriis/simple-pirate.git
|
langchain app add git+ssh://git@github.com/efriis/simple-pirate.git
|
||||||
langchain serve add git+https://github.com/efriis/hub.git#devbranch#subdirectory=mypackage
|
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain serve add [OPTIONS] DEPENDENCIES...
|
$ langchain app add [OPTIONS] [DEPENDENCIES]...
|
||||||
```
|
```
|
||||||
|
|
||||||
**Arguments**:
|
**Arguments**:
|
||||||
|
|
||||||
* `DEPENDENCIES...`: [required]
|
* `[DEPENDENCIES]...`: The dependency to add
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
|
|
||||||
* `--api-path TEXT`
|
* `--api-path TEXT`: API paths to add
|
||||||
* `--project-dir PATH`
|
* `--project-dir PATH`: The project directory
|
||||||
|
* `--repo TEXT`: Install templates from a specific github repo instead
|
||||||
|
* `--branch TEXT`: Install templates from a specific branch
|
||||||
* `--help`: Show this message and exit.
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
### `langchain serve install`
|
### `langchain app new`
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ langchain serve install [OPTIONS]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Options**:
|
|
||||||
|
|
||||||
* `--help`: Show this message and exit.
|
|
||||||
|
|
||||||
### `langchain serve list`
|
|
||||||
|
|
||||||
Lists all packages in the current LangServe instance.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ langchain serve list [OPTIONS]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Options**:
|
|
||||||
|
|
||||||
* `--help`: Show this message and exit.
|
|
||||||
|
|
||||||
### `langchain serve new`
|
|
||||||
|
|
||||||
Create a new LangServe application.
|
Create a new LangServe application.
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain serve new [OPTIONS] NAME
|
$ langchain app new [OPTIONS] NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
**Arguments**:
|
**Arguments**:
|
||||||
|
|
||||||
* `NAME`: [required]
|
* `NAME`: The name of the folder to create [required]
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
|
|
||||||
* `--package TEXT`
|
* `--package TEXT`: Packages to seed the project with
|
||||||
* `--help`: Show this message and exit.
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
### `langchain serve remove`
|
### `langchain app remove`
|
||||||
|
|
||||||
Removes the specified package from the current LangServe instance.
|
Removes the specified package from the current LangServe app.
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain serve remove [OPTIONS] API_PATHS...
|
$ langchain app remove [OPTIONS] API_PATHS...
|
||||||
```
|
```
|
||||||
|
|
||||||
**Arguments**:
|
**Arguments**:
|
||||||
|
|
||||||
* `API_PATHS...`: [required]
|
* `API_PATHS...`: The API paths to remove [required]
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
|
|
||||||
* `--help`: Show this message and exit.
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
### `langchain serve start`
|
### `langchain app serve`
|
||||||
|
|
||||||
Starts the LangServe instance.
|
Starts the LangServe app.
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain serve start [OPTIONS]
|
$ langchain app serve [OPTIONS]
|
||||||
```
|
```
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
|
|
||||||
* `--port INTEGER`
|
* `--port INTEGER`: The port to run the server on
|
||||||
* `--host TEXT`
|
* `--host TEXT`: The host to run the server on
|
||||||
|
* `--app TEXT`: The app to run, e.g. `app.server:app`
|
||||||
* `--help`: Show this message and exit.
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
## `langchain start`
|
## `langchain serve`
|
||||||
|
|
||||||
Start the LangServe instance, whether it's a hub package or a serve project.
|
Start the LangServe app, whether it's a template or an app.
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ langchain start [OPTIONS]
|
$ langchain serve [OPTIONS]
|
||||||
```
|
```
|
||||||
|
|
||||||
**Options**:
|
**Options**:
|
||||||
|
|
||||||
* `--port INTEGER`
|
* `--port INTEGER`: The port to run the server on
|
||||||
* `--host TEXT`
|
* `--host TEXT`: The host to run the server on
|
||||||
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
|
## `langchain template`
|
||||||
|
|
||||||
|
Develop installable templates.
|
||||||
|
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ langchain template [OPTIONS] COMMAND [ARGS]...
|
||||||
|
```
|
||||||
|
|
||||||
|
**Options**:
|
||||||
|
|
||||||
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
|
**Commands**:
|
||||||
|
|
||||||
|
* `new`: Creates a new template package.
|
||||||
|
* `serve`: Starts a demo app for this template.
|
||||||
|
|
||||||
|
### `langchain template new`
|
||||||
|
|
||||||
|
Creates a new template package.
|
||||||
|
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ langchain template new [OPTIONS] NAME
|
||||||
|
```
|
||||||
|
|
||||||
|
**Arguments**:
|
||||||
|
|
||||||
|
* `NAME`: The name of the folder to create [required]
|
||||||
|
|
||||||
|
**Options**:
|
||||||
|
|
||||||
|
* `--with-poetry / --no-poetry`: Don't run poetry install [default: no-poetry]
|
||||||
|
* `--help`: Show this message and exit.
|
||||||
|
|
||||||
|
### `langchain template serve`
|
||||||
|
|
||||||
|
Starts a demo app for this template.
|
||||||
|
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ langchain template serve [OPTIONS]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Options**:
|
||||||
|
|
||||||
|
* `--port INTEGER`: The port to run the server on
|
||||||
|
* `--host TEXT`: The host to run the server on
|
||||||
* `--help`: Show this message and exit.
|
* `--help`: Show this message and exit.
|
||||||
|
@@ -3,15 +3,18 @@ from typing import Optional
|
|||||||
import typer
|
import typer
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
from langchain_cli.namespaces import hub, serve
|
from langchain_cli.namespaces import app as app_namespace
|
||||||
|
from langchain_cli.namespaces import template as template_namespace
|
||||||
|
|
||||||
app = typer.Typer(no_args_is_help=True, add_completion=False)
|
app = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||||
app.add_typer(hub.hub, name="hub", help=hub.__doc__)
|
app.add_typer(
|
||||||
app.add_typer(serve.serve, name="serve", help=serve.__doc__)
|
template_namespace.package_cli, name="template", help=template_namespace.__doc__
|
||||||
|
)
|
||||||
|
app.add_typer(app_namespace.app_cli, name="app", help=app_namespace.__doc__)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def start(
|
def serve(
|
||||||
*,
|
*,
|
||||||
port: Annotated[
|
port: Annotated[
|
||||||
Optional[int], typer.Option(help="The port to run the server on")
|
Optional[int], typer.Option(help="The port to run the server on")
|
||||||
@@ -21,14 +24,14 @@ def start(
|
|||||||
] = None,
|
] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Start the LangServe instance, whether it's a hub package or a serve project.
|
Start the LangServe app, whether it's a template or an app.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# try starting hub package, if error, try langserve
|
# try starting template package, if error, try langserve
|
||||||
try:
|
try:
|
||||||
hub.start(port=port, host=host)
|
template_namespace.serve(port=port, host=host)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
serve.start(port=port, host=host)
|
app_namespace.serve(port=port, host=host)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Development Scripts for Hub Packages
|
Development Scripts for template packages
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
@@ -10,7 +10,7 @@ from langchain_cli.utils.packages import get_package_root
|
|||||||
|
|
||||||
def create_demo_server():
|
def create_demo_server():
|
||||||
"""
|
"""
|
||||||
Creates a demo server for the current hub package.
|
Creates a demo server for the current template.
|
||||||
"""
|
"""
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
package_root = get_package_root()
|
package_root = get_package_root()
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Manage LangServe application projects.
|
Manage LangChain apps
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
@@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
from typing import Dict, List, Optional, Tuple
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from langserve.packages import get_langserve_export, list_packages
|
from langserve.packages import get_langserve_export
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
from langchain_cli.utils.events import create_events
|
from langchain_cli.utils.events import create_events
|
||||||
@@ -22,10 +22,10 @@ from langchain_cli.utils.packages import get_package_root
|
|||||||
|
|
||||||
REPO_DIR = Path(typer.get_app_dir("langchain")) / "git_repos"
|
REPO_DIR = Path(typer.get_app_dir("langchain")) / "git_repos"
|
||||||
|
|
||||||
serve = typer.Typer(no_args_is_help=True, add_completion=False)
|
app_cli = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
@app_cli.command()
|
||||||
def new(
|
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")],
|
||||||
*,
|
*,
|
||||||
@@ -33,10 +33,6 @@ def new(
|
|||||||
Optional[List[str]],
|
Optional[List[str]],
|
||||||
typer.Option(help="Packages to seed the project with"),
|
typer.Option(help="Packages to seed the project with"),
|
||||||
] = None,
|
] = None,
|
||||||
with_poetry: Annotated[
|
|
||||||
bool,
|
|
||||||
typer.Option("--with-poetry/--no-poetry", help="Run poetry install"),
|
|
||||||
] = False,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Create a new LangServe application.
|
Create a new LangServe application.
|
||||||
@@ -44,31 +40,19 @@ def new(
|
|||||||
# copy over template from ../project_template
|
# copy over template from ../project_template
|
||||||
project_template_dir = Path(__file__).parents[1] / "project_template"
|
project_template_dir = Path(__file__).parents[1] / "project_template"
|
||||||
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
|
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
|
||||||
|
app_name = name if name != "." else Path.cwd().name
|
||||||
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")
|
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")
|
||||||
|
|
||||||
# poetry install
|
readme = destination_dir / "README.md"
|
||||||
if with_poetry:
|
readme_contents = readme.read_text()
|
||||||
subprocess.run(["poetry", "install"], cwd=destination_dir)
|
readme.write_text(readme_contents.replace("__app_name__", app_name))
|
||||||
|
|
||||||
# add packages if specified
|
# add packages if specified
|
||||||
if package is not None and len(package) > 0:
|
if package is not None and len(package) > 0:
|
||||||
add(package, project_dir=destination_dir, with_poetry=with_poetry)
|
add(package, project_dir=destination_dir)
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
@app_cli.command()
|
||||||
def install():
|
|
||||||
package_root = get_package_root() / "packages"
|
|
||||||
for package_path in list_packages(package_root):
|
|
||||||
try:
|
|
||||||
pyproject_path = package_path / "pyproject.toml"
|
|
||||||
langserve_export = get_langserve_export(pyproject_path)
|
|
||||||
typer.echo(f"Installing {langserve_export['package_name']}...")
|
|
||||||
subprocess.run(["poetry", "add", "--editable", package_path])
|
|
||||||
except Exception as e:
|
|
||||||
typer.echo(f"Skipping installing {package_path} due to error: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
|
||||||
def add(
|
def add(
|
||||||
dependencies: Annotated[
|
dependencies: Annotated[
|
||||||
Optional[List[str]], typer.Argument(help="The dependency to add")
|
Optional[List[str]], typer.Argument(help="The dependency to add")
|
||||||
@@ -79,22 +63,19 @@ def add(
|
|||||||
Optional[Path], typer.Option(help="The project directory")
|
Optional[Path], typer.Option(help="The project directory")
|
||||||
] = None,
|
] = None,
|
||||||
repo: Annotated[
|
repo: Annotated[
|
||||||
List[str], typer.Option(help="Install deps from a specific github repo instead")
|
List[str],
|
||||||
|
typer.Option(help="Install templates from a specific github repo instead"),
|
||||||
] = [],
|
] = [],
|
||||||
branch: Annotated[
|
branch: Annotated[
|
||||||
List[str], typer.Option(help="Install deps from a specific branch")
|
List[str], typer.Option(help="Install templates from a specific branch")
|
||||||
] = [],
|
] = [],
|
||||||
with_poetry: Annotated[
|
|
||||||
bool,
|
|
||||||
typer.Option("--with-poetry/--no-poetry", help="Run poetry install"),
|
|
||||||
] = False,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Adds the specified package to the current LangServe instance.
|
Adds the specified template to the current LangServe app.
|
||||||
|
|
||||||
e.g.:
|
e.g.:
|
||||||
langchain serve add extraction-openai-functions
|
langchain app add extraction-openai-functions
|
||||||
langchain serve add git+ssh://git@github.com/efriis/simple-pirate.git
|
langchain app add git+ssh://git@github.com/efriis/simple-pirate.git
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parsed_deps = parse_dependencies(dependencies, repo, branch, api_path)
|
parsed_deps = parse_dependencies(dependencies, repo, branch, api_path)
|
||||||
@@ -122,7 +103,7 @@ def add(
|
|||||||
if len(group_deps) == 1:
|
if len(group_deps) == 1:
|
||||||
typer.echo(f"Adding {git}@{ref}...")
|
typer.echo(f"Adding {git}@{ref}...")
|
||||||
else:
|
else:
|
||||||
typer.echo(f"Adding {len(group_deps)} dependencies from {git}@{ref}")
|
typer.echo(f"Adding {len(group_deps)} templates from {git}@{ref}")
|
||||||
source_repo_path = update_repo(git, ref, REPO_DIR)
|
source_repo_path = update_repo(git, ref, REPO_DIR)
|
||||||
|
|
||||||
for dep in group_deps:
|
for dep in group_deps:
|
||||||
@@ -159,13 +140,6 @@ def add(
|
|||||||
installed_desination_strs = [
|
installed_desination_strs = [
|
||||||
str(p.relative_to(cwd)) for p in installed_destination_paths
|
str(p.relative_to(cwd)) for p in installed_destination_paths
|
||||||
]
|
]
|
||||||
|
|
||||||
if with_poetry:
|
|
||||||
subprocess.run(
|
|
||||||
["poetry", "add", "--editable"] + installed_desination_strs,
|
|
||||||
cwd=cwd,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
cmd = ["pip", "install", "-e"] + installed_desination_strs
|
cmd = ["pip", "install", "-e"] + installed_desination_strs
|
||||||
cmd_str = " \\\n ".join(installed_desination_strs)
|
cmd_str = " \\\n ".join(installed_desination_strs)
|
||||||
install_str = f"To install:\n\npip install -e \\\n {cmd_str}"
|
install_str = f"To install:\n\npip install -e \\\n {cmd_str}"
|
||||||
@@ -173,6 +147,7 @@ def add(
|
|||||||
|
|
||||||
if typer.confirm("Run it?"):
|
if typer.confirm("Run it?"):
|
||||||
subprocess.run(cmd, cwd=cwd)
|
subprocess.run(cmd, cwd=cwd)
|
||||||
|
|
||||||
if typer.confirm("\nGenerate route code for these packages?", default=True):
|
if typer.confirm("\nGenerate route code for these packages?", default=True):
|
||||||
chain_names = []
|
chain_names = []
|
||||||
for e in installed_exports:
|
for e in installed_exports:
|
||||||
@@ -200,21 +175,20 @@ def add(
|
|||||||
|
|
||||||
lines = (
|
lines = (
|
||||||
["", "Great! Add the following to your app:\n\n```", ""]
|
["", "Great! Add the following to your app:\n\n```", ""]
|
||||||
+ imports + [""] + routes + ["```"]
|
+ imports
|
||||||
|
+ [""]
|
||||||
|
+ routes
|
||||||
|
+ ["```"]
|
||||||
)
|
)
|
||||||
typer.echo("\n".join(lines))
|
typer.echo("\n".join(lines))
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
@app_cli.command()
|
||||||
def remove(
|
def remove(
|
||||||
api_paths: Annotated[List[str], typer.Argument(help="The API paths to remove")],
|
api_paths: Annotated[List[str], typer.Argument(help="The API paths to remove")],
|
||||||
with_poetry: Annotated[
|
|
||||||
bool,
|
|
||||||
typer.Option("--with_poetry/--no-poetry", help="Don't run poetry remove"),
|
|
||||||
] = False,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Removes the specified package from the current LangServe instance.
|
Removes the specified package from the current LangServe app.
|
||||||
"""
|
"""
|
||||||
for api_path in api_paths:
|
for api_path in api_paths:
|
||||||
package_dir = Path.cwd() / "packages" / api_path
|
package_dir = Path.cwd() / "packages" / api_path
|
||||||
@@ -224,28 +198,12 @@ def remove(
|
|||||||
pyproject = package_dir / "pyproject.toml"
|
pyproject = package_dir / "pyproject.toml"
|
||||||
langserve_export = get_langserve_export(pyproject)
|
langserve_export = get_langserve_export(pyproject)
|
||||||
typer.echo(f"Removing {langserve_export['package_name']}...")
|
typer.echo(f"Removing {langserve_export['package_name']}...")
|
||||||
if with_poetry:
|
|
||||||
subprocess.run(["poetry", "remove", langserve_export["package_name"]])
|
|
||||||
shutil.rmtree(package_dir)
|
shutil.rmtree(package_dir)
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
@app_cli.command()
|
||||||
def list():
|
def serve(
|
||||||
"""
|
|
||||||
Lists all packages in the current LangServe instance.
|
|
||||||
"""
|
|
||||||
package_root = get_package_root() / "packages"
|
|
||||||
for package_path in list_packages(package_root):
|
|
||||||
relative = package_path.relative_to(package_root)
|
|
||||||
pyproject_path = package_path / "pyproject.toml"
|
|
||||||
langserve_export = get_langserve_export(pyproject_path)
|
|
||||||
typer.echo(
|
|
||||||
f"{relative}: ({langserve_export['module']}.{langserve_export['attr']})"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@serve.command()
|
|
||||||
def start(
|
|
||||||
*,
|
*,
|
||||||
port: Annotated[
|
port: Annotated[
|
||||||
Optional[int], typer.Option(help="The port to run the server on")
|
Optional[int], typer.Option(help="The port to run the server on")
|
||||||
@@ -253,10 +211,12 @@ 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,
|
app: Annotated[
|
||||||
|
Optional[str], typer.Option(help="The app to run, e.g. `app.server:app`")
|
||||||
|
] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Starts the LangServe instance.
|
Starts the LangServe app.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
app_str = app if app is not None else "app.server:app"
|
app_str = app if app is not None else "app.server:app"
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Manage installable hub packages.
|
Develop installable templates.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
@@ -14,10 +14,10 @@ from typing_extensions import Annotated
|
|||||||
|
|
||||||
from langchain_cli.utils.packages import get_package_root
|
from langchain_cli.utils.packages import get_package_root
|
||||||
|
|
||||||
hub = typer.Typer(no_args_is_help=True, add_completion=False)
|
package_cli = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||||
|
|
||||||
|
|
||||||
@hub.command()
|
@package_cli.command()
|
||||||
def new(
|
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[
|
||||||
@@ -26,7 +26,7 @@ def new(
|
|||||||
] = False,
|
] = False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Creates a new hub package.
|
Creates a new template package.
|
||||||
"""
|
"""
|
||||||
computed_name = name if name != "." else Path.cwd().name
|
computed_name = name if name != "." else Path.cwd().name
|
||||||
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
|
destination_dir = Path.cwd() / name if name != "." else Path.cwd()
|
||||||
@@ -36,33 +36,44 @@ def new(
|
|||||||
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")
|
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=name == ".")
|
||||||
|
|
||||||
package_name_split = computed_name.split("/")
|
package_name_split = computed_name.split("/")
|
||||||
package_name_last = (
|
package_name = (
|
||||||
package_name_split[-2]
|
package_name_split[-2]
|
||||||
if len(package_name_split) > 1 and package_name_split[-1] == ""
|
if len(package_name_split) > 1 and package_name_split[-1] == ""
|
||||||
else package_name_split[-1]
|
else package_name_split[-1]
|
||||||
)
|
)
|
||||||
default_package_name = re.sub(
|
module_name = re.sub(
|
||||||
r"[^a-zA-Z0-9_]",
|
r"[^a-zA-Z0-9_]",
|
||||||
"_",
|
"_",
|
||||||
package_name_last,
|
package_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
# generate app route code
|
||||||
|
chain_name = f"{module_name}_chain"
|
||||||
|
app_route_code = (
|
||||||
|
f"from {module_name} import chain as {chain_name}\n\n"
|
||||||
|
f'add_routes(app, {chain_name}, path="/{package_name}")'
|
||||||
)
|
)
|
||||||
|
|
||||||
# replace template strings
|
# replace template strings
|
||||||
pyproject = destination_dir / "pyproject.toml"
|
pyproject = destination_dir / "pyproject.toml"
|
||||||
pyproject_contents = pyproject.read_text()
|
pyproject_contents = pyproject.read_text()
|
||||||
pyproject.write_text(
|
pyproject.write_text(
|
||||||
pyproject_contents.replace("__package_name__", default_package_name)
|
pyproject_contents.replace("__package_name__", module_name).replace(
|
||||||
|
"__module_name__", module_name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# move module folder
|
# move module folder
|
||||||
package_dir = destination_dir / default_package_name
|
package_dir = destination_dir / module_name
|
||||||
shutil.move(destination_dir / "package_template", package_dir)
|
shutil.move(destination_dir / "package_template", package_dir)
|
||||||
|
|
||||||
# replace readme
|
# replace readme
|
||||||
readme = destination_dir / "README.md"
|
readme = destination_dir / "README.md"
|
||||||
readme_contents = readme.read_text()
|
readme_contents = readme.read_text()
|
||||||
readme.write_text(
|
readme.write_text(
|
||||||
readme_contents.replace("__package_name_last__", package_name_last)
|
readme_contents.replace("__package_name_last__", package_name).replace(
|
||||||
|
"__app_route_code__", app_route_code
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# poetry install
|
# poetry install
|
||||||
@@ -70,8 +81,8 @@ def new(
|
|||||||
subprocess.run(["poetry", "install"], cwd=destination_dir)
|
subprocess.run(["poetry", "install"], cwd=destination_dir)
|
||||||
|
|
||||||
|
|
||||||
@hub.command()
|
@package_cli.command()
|
||||||
def start(
|
def serve(
|
||||||
*,
|
*,
|
||||||
port: Annotated[
|
port: Annotated[
|
||||||
Optional[int], typer.Option(help="The port to run the server on")
|
Optional[int], typer.Option(help="The port to run the server on")
|
||||||
@@ -81,7 +92,7 @@ def start(
|
|||||||
] = None,
|
] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Starts a demo LangServe instance for this hub package.
|
Starts a demo app for this template.
|
||||||
"""
|
"""
|
||||||
# load pyproject.toml
|
# load pyproject.toml
|
||||||
project_dir = get_package_root()
|
project_dir = get_package_root()
|
@@ -1 +1,64 @@
|
|||||||
# __package_name_last__
|
# __package_name_last__
|
||||||
|
|
||||||
|
TODO: What does this package do
|
||||||
|
|
||||||
|
## Environment Setup
|
||||||
|
|
||||||
|
TODO: What environment variables need to be set (if any)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
To use this package, you should first have the LangChain CLI installed:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pip install -U "langchain-cli[serve]"
|
||||||
|
```
|
||||||
|
|
||||||
|
To create a new LangChain project and install this as the only package, you can do:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
langchain app new my-app --package __package_name__
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to add this to an existing project, you can just run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
langchain app add __package_name__
|
||||||
|
```
|
||||||
|
|
||||||
|
And add the following code to your `server.py` file:
|
||||||
|
```python
|
||||||
|
__app_route_code__
|
||||||
|
```
|
||||||
|
|
||||||
|
(Optional) Let's now configure LangSmith.
|
||||||
|
LangSmith will help us trace, monitor and debug LangChain applications.
|
||||||
|
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
|
||||||
|
If you don't have access, you can skip this section
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export LANGCHAIN_TRACING_V2=true
|
||||||
|
export LANGCHAIN_API_KEY=<your-api-key>
|
||||||
|
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are inside this directory, then you can spin up a LangServe instance directly by:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
langchain serve
|
||||||
|
```
|
||||||
|
|
||||||
|
This will start the FastAPI app with a server is running locally at
|
||||||
|
[http://localhost:8000](http://localhost:8000)
|
||||||
|
|
||||||
|
We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
||||||
|
We can access the playground at [http://127.0.0.1:8000/__package_name__/playground](http://127.0.0.1:8000/__package_name__/playground)
|
||||||
|
|
||||||
|
We can access the template from code with:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from langserve.client import RemoteRunnable
|
||||||
|
|
||||||
|
runnable = RemoteRunnable("http://localhost:8000/__package_name__")
|
||||||
|
```
|
@@ -0,0 +1,3 @@
|
|||||||
|
from chain import chain
|
||||||
|
|
||||||
|
__all__ = ["chain"]
|
||||||
|
@@ -16,7 +16,7 @@ fastapi = "^0.104.0"
|
|||||||
sse-starlette = "^1.6.5"
|
sse-starlette = "^1.6.5"
|
||||||
|
|
||||||
[tool.langserve]
|
[tool.langserve]
|
||||||
export_module = "__package_name__.chain"
|
export_module = "__module_name__"
|
||||||
export_attr = "chain"
|
export_attr = "chain"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# LangServeHub Project Template
|
# __app_name__
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -11,11 +11,39 @@ pip install -U "langchain-cli[serve]"
|
|||||||
## Adding packages
|
## Adding packages
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
langchain serve add $PROJECT_NAME
|
# adding packages from
|
||||||
|
# https://github.com/langchain-ai/langchain/tree/master/templates
|
||||||
|
langchain app add $PROJECT_NAME
|
||||||
|
|
||||||
|
# adding custom GitHub repo packages
|
||||||
|
langchain app add --repo $OWNER/$REPO
|
||||||
|
# or with whole git string (supports other git providers):
|
||||||
|
# langchain app add git+https://github.com/hwchase17/chain-of-verification
|
||||||
|
|
||||||
|
# with a custom api mount point (defaults to `/{package_name}`)
|
||||||
|
langchain app add $PROJECT_NAME --api_path=/my/custom/path/rag
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: you remove packages by their api path
|
||||||
|
|
||||||
|
```bash
|
||||||
|
langchain app remove my/custom/path/rag
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setup LangSmith (Optional)
|
||||||
|
LangSmith will help us trace, monitor and debug LangChain applications.
|
||||||
|
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
|
||||||
|
If you don't have access, you can skip this section
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export LANGCHAIN_TRACING_V2=true
|
||||||
|
export LANGCHAIN_API_KEY=<your-api-key>
|
||||||
|
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Launch LangServe
|
## Launch LangServe
|
||||||
|
|
||||||
```shell
|
```bash
|
||||||
python app/server.py
|
langchain serve
|
||||||
```
|
```
|
||||||
|
@@ -132,7 +132,7 @@ def parse_dependencies(
|
|||||||
):
|
):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Number of defined repos/branches/api_paths did not match the "
|
"Number of defined repos/branches/api_paths did not match the "
|
||||||
"number of dependencies."
|
"number of templates."
|
||||||
)
|
)
|
||||||
inner_deps = _list_arg_to_length(dependencies, num_deps)
|
inner_deps = _list_arg_to_length(dependencies, num_deps)
|
||||||
inner_api_paths = _list_arg_to_length(api_path, num_deps)
|
inner_api_paths = _list_arg_to_length(api_path, num_deps)
|
||||||
|
@@ -17,7 +17,7 @@ pip install -U "langchain-cli[serve]"
|
|||||||
Next, create a new LangChain project:
|
Next, create a new LangChain project:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
langchain serve new my-app
|
langchain app new my-app
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a new directory called `my-app` with two folders:
|
This will create a new directory called `my-app` with two folders:
|
||||||
@@ -36,7 +36,7 @@ In this getting started guide, we will add a simple `pirate-speak` project.
|
|||||||
All this project does is convert user input into pirate speak.
|
All this project does is convert user input into pirate speak.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
langchain serve add pirate-speak
|
langchain app add pirate-speak
|
||||||
```
|
```
|
||||||
|
|
||||||
This will pull in the specified template into `packages/pirate-speak`
|
This will pull in the specified template into `packages/pirate-speak`
|
||||||
@@ -53,7 +53,7 @@ If we accept, we will see the following code generated:
|
|||||||
```shell
|
```shell
|
||||||
from pirate_speak.chain import chain as pirate_speak_chain
|
from pirate_speak.chain import chain as pirate_speak_chain
|
||||||
|
|
||||||
add_routes(app, pirate_speak_chain, path="/pirate_speak")
|
add_routes(app, pirate_speak_chain, path="/pirate-speak")
|
||||||
```
|
```
|
||||||
|
|
||||||
You can now edit the template you pulled down.
|
You can now edit the template you pulled down.
|
||||||
@@ -72,7 +72,7 @@ from pirate_speak.chain import chain as pirate_speak_chain
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
add_routes(app, pirate_speak_chain, path="/pirate_speak")
|
add_routes(app, pirate_speak_chain, path="/pirate-speak")
|
||||||
```
|
```
|
||||||
|
|
||||||
(Optional) Let's now configure LangSmith.
|
(Optional) Let's now configure LangSmith.
|
||||||
@@ -96,11 +96,11 @@ export OPENAI_API_KEY=sk-...
|
|||||||
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
|
||||||
langchain start
|
langchain serve
|
||||||
```
|
```
|
||||||
|
|
||||||
This now gives a fully deployed LangServe application.
|
This now gives a fully deployed LangServe application.
|
||||||
For example, you get a playground out-of-the-box at [http://127.0.0.1:8000/pirate_speak/playground/](http://127.0.0.1:8000/pirate_speak/playground/):
|
For example, you get a playground out-of-the-box at [http://127.0.0.1:8000/pirate-speak/playground/](http://127.0.0.1:8000/pirate-speak/playground/):
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ Use the LangServe python or js SDK to interact with the API as if it were a regu
|
|||||||
```python
|
```python
|
||||||
from langserve import RemoteRunnable
|
from langserve import RemoteRunnable
|
||||||
|
|
||||||
api = RemoteRunnable("http://127.0.0.1:8000/pirate_speak")
|
api = RemoteRunnable("http://127.0.0.1:8000/pirate-speak")
|
||||||
api.invoke({"text": "hi"})
|
api.invoke({"text": "hi"})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ You can then run the following command to create a new skeleton of a package.
|
|||||||
By convention, package names should use `-` delimeters (not `_`).
|
By convention, package names should use `-` delimeters (not `_`).
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
langchain hub new $PROJECT_NAME
|
langchain template new $PROJECT_NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then edit the contents of the package as you desire.
|
You can then edit the contents of the package as you desire.
|
||||||
|
@@ -32,7 +32,7 @@ pip install -U "langchain-cli[serve]"
|
|||||||
You can then run:
|
You can then run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
langchain hub start
|
langchain template serve
|
||||||
```
|
```
|
||||||
|
|
||||||
This will spin up endpoints, documentation, and playground for this chain.
|
This will spin up endpoints, documentation, and playground for this chain.
|
||||||
|
@@ -32,8 +32,8 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"As shown in the README, add template and start server:\n",
|
"As shown in the README, add template and start server:\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"langchain serve add extraction-anthropic-functions\n",
|
"langchain app add extraction-anthropic-functions\n",
|
||||||
"langchain start\n",
|
"langchain serve\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We can now look at the endpoints:\n",
|
"We can now look at the endpoints:\n",
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"As shown in the README, add template and start server:\n",
|
"As shown in the README, add template and start server:\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"langchain serve add rag-chroma\n",
|
"langchain app add rag-chroma\n",
|
||||||
"langchain start\n",
|
"langchain serve\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We can now look at the endpoints:\n",
|
"We can now look at the endpoints:\n",
|
||||||
|
@@ -62,16 +62,16 @@ We use a variety of environment variables to configure this application
|
|||||||
## Installation
|
## Installation
|
||||||
To create a langserve application using this template, run the following:
|
To create a langserve application using this template, run the following:
|
||||||
```bash
|
```bash
|
||||||
langchain serve new my-langserve-app
|
langchain app new my-langserve-app
|
||||||
cd my-langserve-app
|
cd my-langserve-app
|
||||||
```
|
```
|
||||||
|
|
||||||
Add this template:
|
Add this template:
|
||||||
```bash
|
```bash
|
||||||
langchain serve add rag-redis
|
langchain app add rag-redis
|
||||||
```
|
```
|
||||||
|
|
||||||
Start the server:
|
Start the server:
|
||||||
```bash
|
```bash
|
||||||
langchain start
|
langchain serve
|
||||||
```
|
```
|
@@ -30,18 +30,18 @@ Be sure that `OPENAI_API_KEY` is set in order to the OpenAI models.
|
|||||||
|
|
||||||
Create your LangServe app:
|
Create your LangServe app:
|
||||||
```
|
```
|
||||||
langchain serve new my-app
|
langchain app new my-app
|
||||||
cd my-app
|
cd my-app
|
||||||
```
|
```
|
||||||
|
|
||||||
Add template:
|
Add template:
|
||||||
```
|
```
|
||||||
langchain serve add rag-semi-structured
|
langchain app add rag-semi-structured
|
||||||
```
|
```
|
||||||
|
|
||||||
Start server:
|
Start server:
|
||||||
```
|
```
|
||||||
langchain start
|
langchain serve
|
||||||
```
|
```
|
||||||
|
|
||||||
See Jupyter notebook `rag_semi_structured` for various way to connect to the template.
|
See Jupyter notebook `rag_semi_structured` for various way to connect to the template.
|
@@ -9,8 +9,8 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"As shown in the README, add template and start server:\n",
|
"As shown in the README, add template and start server:\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"langchain serve add rag-semi-structured\n",
|
"langchain app add rag-semi-structured\n",
|
||||||
"langchain start\n",
|
"langchain serve\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We can now look at the endpoints:\n",
|
"We can now look at the endpoints:\n",
|
||||||
|
@@ -101,7 +101,7 @@
|
|||||||
"* This will create a new Poetry environment /\n",
|
"* This will create a new Poetry environment /\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"pip install < to add > \n",
|
"pip install < to add > \n",
|
||||||
"langchain serve new my-app\n",
|
"langchain app new my-app\n",
|
||||||
"cd my-app\n",
|
"cd my-app\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -110,13 +110,13 @@
|
|||||||
"* When we add a template, we update the Poetry config file with the necessary dependencies.\n",
|
"* When we add a template, we update the Poetry config file with the necessary dependencies.\n",
|
||||||
"* It also automatically installed these template dependencies in your Poetry environment\n",
|
"* It also automatically installed these template dependencies in your Poetry environment\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"langchain serve add summarize-anthropic\n",
|
"langchain app add summarize-anthropic\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
"`Start FastAPI server`\n",
|
"`Start FastAPI server`\n",
|
||||||
"\n",
|
"\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"langchain start\n",
|
"langchain serve\n",
|
||||||
"```\n",
|
"```\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Note, we can now look at the endpoints:\n",
|
"Note, we can now look at the endpoints:\n",
|
||||||
|
Reference in New Issue
Block a user