Skip to content

Commit

Permalink
add tui via trogon
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivancolin committed Jan 2, 2025
1 parent 000e984 commit cdf46f0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python-version: '3.11'

- name: Install dependencies
run: pip install -e '.[test]'
run: pip install -e '.[test,tui]'

- name: Run cog
run: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
run: |
pip install -e '.[test]'
pip install 'pydantic${{ matrix.pydantic }}'
- name: Optionally install tui dependencies
run: |
pip install -e '.[tui]'
- name: Run tests
run: |
pytest
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Install dependencies and test dependencies
@init:
pipenv run pip install -e '.[test]'
pipenv run pip install -e '.[test, tui]'

# Run pytest with supplied options
@test *options:
Expand Down
12 changes: 12 additions & 0 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,21 @@ Commands:
plugins List installed plugins
similar Return top N similar IDs from a collection
templates Manage stored prompt templates
tui Open Textual TUI.
uninstall Uninstall Python packages from the LLM environment
```

(help-tui)=
### llm tui --help
```
Usage: llm tui [OPTIONS]
Open Textual TUI.
Options:
--help Show this message and exit.
```

(help-prompt)=
### llm prompt --help
```
Expand Down
20 changes: 20 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,23 @@ When running a prompt you can pass the full model name or any of the aliases to
llm -m 4o \
'As many names for cheesecakes as you can think of, with detailed descriptions'
```

## Experimental TUI

A TUI is a "text user interface" (or "terminal user interface") - a keyboard and mouse driven graphical interface running in your terminal.

``llm`` has experimental support for a TUI for building command-line invocations, built on top of the [Trogon](https://github.com/Textualize/trogon) TUI library.

To enable this feature you will need to install the ``trogon`` dependency. You can do that like so:

```bash
llm install trogon
```

Once installed, running the ``llm tui`` command will launch the TUI interface:

```bash
llm tui
```

You can then construct a command by selecting options from the menus, and execute it using ``Ctrl+R``.
9 changes: 9 additions & 0 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
import warnings
import yaml

try:
import trogon # type: ignore
except ImportError:
trogon = None

warnings.simplefilter("ignore", ResourceWarning)

DEFAULT_TEMPLATE = "prompt: "
Expand Down Expand Up @@ -151,6 +156,10 @@ def cli():
"""


if trogon is not None:
cli = trogon.tui()(cli)


@cli.command(name="prompt")
@click.argument("prompt", required=False)
@click.option("-s", "--system", help="System prompt to use")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def get_long_description():
"types-click",
"types-PyYAML",
"types-setuptools",
]
],
"tui": ["trogon"],
},
python_requires=">=3.9",
)

0 comments on commit cdf46f0

Please sign in to comment.