mirror of
https://github.com/Hopiu/llm.git
synced 2026-03-16 20:50:25 +00:00
llm plugins --hook X option, closes #1047
This commit is contained in:
parent
f320de1b0c
commit
f879b816e4
3 changed files with 34 additions and 4 deletions
|
|
@ -811,8 +811,9 @@ Usage: llm plugins [OPTIONS]
|
|||
List installed plugins
|
||||
|
||||
Options:
|
||||
--all Include built-in default plugins
|
||||
--help Show this message and exit.
|
||||
--all Include built-in default plugins
|
||||
--hook TEXT Filter for plugins that implement this hook
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
(help-install)=
|
||||
|
|
|
|||
11
llm/cli.py
11
llm/cli.py
|
|
@ -2617,9 +2617,16 @@ def fragments_loaders():
|
|||
|
||||
@cli.command(name="plugins")
|
||||
@click.option("--all", help="Include built-in default plugins", is_flag=True)
|
||||
def plugins_list(all):
|
||||
@click.option(
|
||||
"hooks", "--hook", help="Filter for plugins that implement this hook", multiple=True
|
||||
)
|
||||
def plugins_list(all, hooks):
|
||||
"List installed plugins"
|
||||
click.echo(json.dumps(get_plugins(all), indent=2))
|
||||
plugins = get_plugins(all)
|
||||
hooks = set(hooks)
|
||||
if hooks:
|
||||
plugins = [plugin for plugin in plugins if hooks.intersection(plugin["hooks"])]
|
||||
click.echo(json.dumps(plugins, indent=2))
|
||||
|
||||
|
||||
def display_truncated(text):
|
||||
|
|
|
|||
|
|
@ -290,3 +290,25 @@ def test_register_tools(tmpdir):
|
|||
finally:
|
||||
plugins.pm.unregister(name="ToolsPlugin")
|
||||
assert llm.get_tools() == {}
|
||||
|
||||
|
||||
def test_plugins_command():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli.cli, ["plugins"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output) == [
|
||||
{"name": "EchoModelPlugin", "hooks": ["register_models"]},
|
||||
{
|
||||
"name": "MockModelsPlugin",
|
||||
"hooks": ["register_embedding_models", "register_models"],
|
||||
},
|
||||
]
|
||||
# Test the --hook option
|
||||
result2 = runner.invoke(cli.cli, ["plugins", "--hook", "register_embedding_models"])
|
||||
assert result2.exit_code == 0
|
||||
assert json.loads(result2.output) == [
|
||||
{
|
||||
"name": "MockModelsPlugin",
|
||||
"hooks": ["register_embedding_models", "register_models"],
|
||||
},
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue