Skip to content

Commit

Permalink
CLI (#12284)
Browse files Browse the repository at this point in the history
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
  • Loading branch information
efriis and hwchase17 authored Oct 25, 2023
1 parent 07c2649 commit 47070b8
Show file tree
Hide file tree
Showing 31 changed files with 5,549 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libs/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
__pycache__
.venv
213 changes: 213 additions & 0 deletions libs/cli/DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# `langchain`

**Usage**:

```console
$ langchain [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--help`: Show this message and exit.

**Commands**:

* `hub`: Manage installable hub packages.
* `serve`: Manage LangServe application projects.
* `start`: Start the LangServe instance, whether it's...

## `langchain hub`

Manage installable hub packages.

**Usage**:

```console
$ langchain hub [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--help`: Show this message and exit.

**Commands**:

* `new`: Creates a new hub package.
* `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.
* `remove`: Removes the specified package from the...
* `start`: Starts the LangServe instance.

### `langchain serve add`

Adds the specified package to the current LangServe instance.

e.g.:
langchain serve add simple-pirate
langchain serve add git+ssh://git@github.com/efriis/simple-pirate.git
langchain serve add git+https://github.com/efriis/hub.git#devbranch#subdirectory=mypackage

**Usage**:

```console
$ langchain serve add [OPTIONS] DEPENDENCIES...
```

**Arguments**:

* `DEPENDENCIES...`: [required]

**Options**:

* `--api-path TEXT`
* `--project-dir PATH`
* `--help`: Show this message and exit.

### `langchain serve install`

**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.

**Usage**:

```console
$ langchain serve new [OPTIONS] NAME
```

**Arguments**:

* `NAME`: [required]

**Options**:

* `--package TEXT`
* `--help`: Show this message and exit.

### `langchain serve remove`

Removes the specified package from the current LangServe instance.

**Usage**:

```console
$ langchain serve remove [OPTIONS] API_PATHS...
```

**Arguments**:

* `API_PATHS...`: [required]

**Options**:

* `--help`: Show this message and exit.

### `langchain serve start`

Starts the LangServe instance.

**Usage**:

```console
$ langchain serve start [OPTIONS]
```

**Options**:

* `--port INTEGER`
* `--host TEXT`
* `--help`: Show this message and exit.

## `langchain start`

Start the LangServe instance, whether it's a hub package or a serve project.

**Usage**:

```console
$ langchain start [OPTIONS]
```

**Options**:

* `--port INTEGER`
* `--host TEXT`
* `--help`: Show this message and exit.
43 changes: 43 additions & 0 deletions libs/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# langchain-cli

Install CLI

`pip install -U --pre langchain-cli`

Create new langchain app

`langchain serve new my-app`

Go into app

`cd my-app`

Install a package

`langchain serve add extraction-summary`

(Activate virtualenv)

Install langserve

`pip install "langserve[all]"`

Install the langchain package

`pip install -e packages/extraction-summary`

Edit `app/server.py` to add that package to the routes

```markdown
from fastapi import FastAPI
from langserve import add_routes
from extraction_summary.chain import chain

app = FastAPI()

add_routes(app, chain)
```

Run the app

`python app/server.py`
Empty file.
36 changes: 36 additions & 0 deletions libs/cli/langchain_cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import typer
import subprocess
from typing import Optional
from typing_extensions import Annotated

from langchain_cli.namespaces import hub
from langchain_cli.namespaces import serve

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.
"""
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)


if __name__ == "__main__":
app()
2 changes: 2 additions & 0 deletions libs/cli/langchain_cli/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEFAULT_GIT_REPO = "https://github.com/langchain-ai/langchain.git"
DEFAULT_GIT_SUBDIRECTORY = "templates"
17 changes: 17 additions & 0 deletions libs/cli/langchain_cli/dev_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Development Scripts for Hub Packages
"""

from fastapi import FastAPI
from langserve.packages import add_package_route
from langchain_cli.utils.packages import get_package_root


def create_demo_server():
"""
Creates a demo server for the current hub package.
"""
app = FastAPI()
package_root = get_package_root()
add_package_route(app, package_root, "")
return app
Empty file.
Loading

0 comments on commit 47070b8

Please sign in to comment.