diff --git a/docs/help.md b/docs/help.md index b77cc9f..c110eee 100644 --- a/docs/help.md +++ b/docs/help.md @@ -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. +``` \ No newline at end of file diff --git a/docs/plugins.md b/docs/plugins.md index e9dfebb..e8f25b5 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -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 diff --git a/llm/cli.py b/llm/cli.py index cde5a4d..ea4195b 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -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: