Plugin hooks#

Plugins use plugin hooks to customize LLM’s behavior. These hooks are powered by the Pluggy plugin system.

Each plugin can implement one or more hooks using the @hookimpl decorator against one of the hook function names described on this page.

LLM imitates the Datasette plugin system. The Datasette plugin documentation describes how plugins work.


This hook adds new commands to the llm CLI tool - for example llm extra-command.

This example plugin adds a new hello-world command that prints “Hello world!”:

from llm import hookimpl
import click

def register_commands(cli):
    def hello_world():
        "Print hello world"
        click.echo("Hello world!")

This new command will be added to llm --help and can be run using llm hello-world.


This hook can be used to register one or more additional models.

import llm

def register_models(register):

class HelloWorld(llm.Model):
    model_id = "helloworld"

    def execute(self, prompt, stream, response):
        return ["hello world"]

Writing a plugin to support a new model describes how to use this hook in detail.