Allow -o option when calling tools, closes #1233

This commit is contained in:
Simon Willison 2025-08-11 13:41:24 -07:00
parent cbd3aab511
commit 5204a11f33
3 changed files with 27 additions and 1 deletions

View file

@ -777,7 +777,7 @@ def prompt(
if key_ not in validated_options:
validated_options[key_] = value
kwargs = {**validated_options}
kwargs = {}
resolved_attachments = [*attachments, *attachment_types]
@ -817,12 +817,16 @@ def prompt(
if tool_implementations:
prompt_method = conversation.chain
kwargs["options"] = validated_options
kwargs["chain_limit"] = chain_limit
if tools_debug:
kwargs["after_call"] = _debug_tool_call
if tools_approve:
kwargs["before_call"] = _approve_tool_call
kwargs["tools"] = tool_implementations
else:
# Merge in options for the .prompt() methods
kwargs.update(validated_options)
try:
if async_:

View file

@ -52,6 +52,7 @@ class MockModel(llm.Model):
model_id = "mock"
attachment_types = {"image/png", "audio/wav"}
supports_schema = True
supports_tools = True
class Options(llm.Options):
max_tokens: Optional[int] = Field(

View file

@ -304,6 +304,27 @@ def test_default_tool_llm_version():
assert '"output": "{}"'.format(version("llm")) in result.output
def test_cli_tools_with_options():
runner = CliRunner()
result = runner.invoke(
cli.cli,
[
"-m",
"mock",
"-o",
"max_tokens",
"10",
"-T",
"llm_version",
json.dumps({"tool_calls": [{"name": "llm_version"}]}),
],
catch_exceptions=False,
)
assert result.exit_code == 0
# It just needs not to crash
# https://github.com/simonw/llm/issues/1233
def test_functions_tool_locals():
# https://github.com/simonw/llm/issues/1107
runner = CliRunner()