diff --git a/llm/cli.py b/llm/cli.py index 41ebe84..8b6d56c 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -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_: diff --git a/tests/conftest.py b/tests/conftest.py index f64dce5..8b9a7f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( diff --git a/tests/test_tools.py b/tests/test_tools.py index a07081a..c61154f 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -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()