Rename --python-tools to --tools, closes #1008

This commit is contained in:
Simon Willison 2025-05-12 21:09:35 -07:00
parent 336948f8fe
commit 7efe51fcb4
4 changed files with 10 additions and 11 deletions

View file

@ -127,7 +127,7 @@ Options:
Attachment with explicit mimetype,
--at image.jpg image/jpeg
-T, --tool TEXT Name of a tool to make available to the model
--python-tools TEXT Python code block defining functions to
--tools TEXT Python code block defining functions to
register as tools
--td, --tools-debug Show full details of tool executions
--ta, --tools-approve Manually approve every tool execution
@ -628,9 +628,9 @@ Usage: llm tools list [OPTIONS]
List available tools that have been provided by plugins
Options:
--json Output as JSON
--python-tools TEXT Python code block defining functions to register as tools
--help Show this message and exit.
--json Output as JSON
--tools TEXT Python code block defining functions to register as tools
--help Show this message and exit.
```
(help-aliases)=

View file

@ -20,4 +20,4 @@ In LLM every tool is a defined as a Python function. The function can take any n
Tool functions should include a docstring that describes what the function does. This docstring will become the description that is passed to the model.
The Python API can accept functions directly. The command-line interface has two ways for tools to be defined: via plugins that implement the {ref}`register_tools() plugin hook <plugin-hooks-register-tools>`, or directly on the commad-line using the `--python-tools` argument to specify a block of Python code defining one or more functions.
The Python API can accept functions directly. The command-line interface has two ways for tools to be defined: via plugins that implement the {ref}`register_tools() plugin hook <plugin-hooks-register-tools>`, or directly on the command-line using the `--tools` argument to specify a block of Python code defining one or more functions.

View file

@ -344,7 +344,7 @@ def cli():
)
@click.option(
"python_tools",
"--python-tools",
"--tools",
help="Python code block defining functions to register as tools",
)
@click.option(
@ -2180,7 +2180,7 @@ def tools():
@click.option("json_", "--json", is_flag=True, help="Output as JSON")
@click.option(
"python_tools",
"--python-tools",
"--tools",
help="Python code block defining functions to register as tools",
)
def tools_list(json_, python_tools):
@ -3468,7 +3468,7 @@ def _tools_from_code(code: str) -> List[Tool]:
try:
exec(code, globals)
except SyntaxError as ex:
raise click.ClickException("Error in --python-tools definition: {}".format(ex))
raise click.ClickException("Error in --tools definition: {}".format(ex))
# Register all callables in the locals dict:
for name, value in globals.items():
if callable(value) and not name.startswith("_"):

View file

@ -270,10 +270,9 @@ def test_register_tools():
},
},
}
# And test the --python-tools option
# llm tools --python-tools 'def reverse(s: str): return s[::-1]'
# And test the --tools option
result3 = runner.invoke(
cli.cli, ["tools", "--python-tools", "def reverse(s: str): return s[::-1]"]
cli.cli, ["tools", "--tools", "def reverse(s: str): return s[::-1]"]
)
assert result3.exit_code == 0
assert "reverse(s: str)" in result3.output