llm install and llm uninstall, closes #51, refs #49

This commit is contained in:
Simon Willison 2023-06-17 17:55:53 +01:00
parent 441311a7a2
commit 1be6230f1f
3 changed files with 56 additions and 3 deletions

View file

@ -57,10 +57,12 @@ Options:
Commands:
prompt* Execute a prompt
init-db Ensure the logs.db SQLite database exists
install Install packages from PyPI into the same environment as LLM
keys Manage stored API keys for different models
logs Tools for exploring logged prompts and responses
plugins List installed plugins
templates Manage stored prompt templates
uninstall Uninstall Python packages from the LLM environment
```
### llm prompt --help
```
@ -224,4 +226,24 @@ Usage: llm plugins [OPTIONS]
Options:
--help Show this message and exit.
```
### llm install --help
```
Usage: llm install [OPTIONS] PACKAGES...
Install packages from PyPI into the same environment as LLM
Options:
-U, --upgrade Upgrade packages to latest version
--help Show this message and exit.
```
### llm uninstall --help
```
Usage: llm uninstall [OPTIONS] PACKAGES...
Uninstall Python packages from the LLM environment
Options:
-y, --yes Don't ask for confirmation
--help Show this message and exit.
```
<!-- [[[end]]] -->

View file

@ -2,13 +2,19 @@
LLM plugins can provide extra features to the tool.
The [llm-hello-world](https://github.com/simonw/llm-hello-world) plugin is the current best example of how to build and package a plugin.
## Installing plugins
Plugins can be installed by running `pip install` in the same virtual environment as `llm` itself:
Plugins must be installed in the same virtual environment as LLM itself. You can use the `llm install` command (a thin wrapper around `pip install`) for this:
```bash
pip install llm-hello-world
llm install llm-hello-world
```
The [llm-hello-world](https://github.com/simonw/llm-hello-world) plugin is the current best example of how to build and package a plugin.
Plugins can be uninstalled with `llm uninstall`:
```bash
llm uninstall llm-hello-world -y
```
The `-y` flag skips asking for confirmation.
## Listing installed plugins

View file

@ -9,6 +9,7 @@ import openai
import os
import pathlib
import pydantic
from runpy import run_module
import shutil
import sqlite_utils
from string import Template as StringTemplate
@ -355,6 +356,30 @@ def templates_path():
click.echo(template_dir())
@cli.command()
@click.argument("packages", nargs=-1, required=True)
@click.option(
"-U", "--upgrade", is_flag=True, help="Upgrade packages to latest version"
)
def install(packages, upgrade):
"""Install packages from PyPI into the same environment as LLM"""
args = ["pip", "install"]
if upgrade:
args += ["--upgrade"]
args += list(packages)
sys.argv = args
run_module("pip", run_name="__main__")
@cli.command()
@click.argument("packages", nargs=-1, required=True)
@click.option("-y", "--yes", is_flag=True, help="Don't ask for confirmation")
def uninstall(packages, yes):
"""Uninstall Python packages from the LLM environment"""
sys.argv = ["pip", "uninstall"] + list(packages) + (["-y"] if yes else [])
run_module("pip", run_name="__main__")
def template_dir():
llm_templates_path = os.environ.get("LLM_TEMPLATES_PATH")
if llm_templates_path: