Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## TBD

### Features

* Support `--help` in the `\llm`and `\llm+` command. ([#214](https://github.com/dbcli/litecli/pull/214))
* Make the history file location configurable. ([#206](https://github.com/dbcli/litecli/issues/206))

### Internal
Expand Down
4 changes: 4 additions & 0 deletions litecli/packages/special/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ def handle_llm(text, cur) -> Tuple[str, Optional[str]]:
elif parts[0] in LLM_CLI_COMMANDS:
capture_output = False
use_context = False
# If the user wants to use --help option to see each command and it's description
elif "--help" == parts[0]:
capture_output = False
use_context = False
# If the parts doesn't have any known LLM_CLI_COMMANDS then the user is
# invoking a question. eg: \llm -m ollama "Most visited urls?"
elif not set(parts).intersection(LLM_CLI_COMMANDS):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_llm_special.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ def test_llm_command_known_subcommand(mock_run_cmd, mock_llm, executor):
# And the function should raise FinishIteration(None)
assert exc_info.value.args[0] is None

@patch("litecli.packages.special.llm.llm")
@patch("litecli.packages.special.llm.run_external_cmd")
def test_llm_command_with_help_flag(mock_run_cmd, mock_llm, executor):
"""
If the parts[0] is --help, we do NOT capture output, we just call run_external_cmd
and then raise FinishIteration.
"""
# Let's assume 'models' is in LLM_CLI_COMMANDS
test_text = r"\llm --help"

with pytest.raises(FinishIteration) as exc_info:
handle_llm(test_text, executor)

# We check that run_external_cmd was called with these arguments:
mock_run_cmd.assert_called_once_with("llm", "--help", restart_cli=False)
# And the function should raise FinishIteration(None)
assert exc_info.value.args[0] is None

@patch("litecli.packages.special.llm.llm")
@patch("litecli.packages.special.llm.run_external_cmd")
Expand Down
Loading