Skip to content

Commit 4c1056f

Browse files
authored
Merge pull request #214 from kracekumar/support-help-flag
[llm] Add support for --help flag
2 parents 4a7bd7d + 781f1bb commit 4c1056f

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## TBD
33

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

88
### Internal

litecli/packages/special/llm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ def handle_llm(text, cur) -> Tuple[str, Optional[str]]:
236236
elif parts[0] in LLM_CLI_COMMANDS:
237237
capture_output = False
238238
use_context = False
239+
# If the user wants to use --help option to see each command and it's description
240+
elif "--help" == parts[0]:
241+
capture_output = False
242+
use_context = False
239243
# If the parts doesn't have any known LLM_CLI_COMMANDS then the user is
240244
# invoking a question. eg: \llm -m ollama "Most visited urls?"
241245
elif not set(parts).intersection(LLM_CLI_COMMANDS):

tests/test_llm_special.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ def test_llm_command_known_subcommand(mock_run_cmd, mock_llm, executor):
8787
# And the function should raise FinishIteration(None)
8888
assert exc_info.value.args[0] is None
8989

90+
@patch("litecli.packages.special.llm.llm")
91+
@patch("litecli.packages.special.llm.run_external_cmd")
92+
def test_llm_command_with_help_flag(mock_run_cmd, mock_llm, executor):
93+
"""
94+
If the parts[0] is --help, we do NOT capture output, we just call run_external_cmd
95+
and then raise FinishIteration.
96+
"""
97+
# Let's assume 'models' is in LLM_CLI_COMMANDS
98+
test_text = r"\llm --help"
99+
100+
with pytest.raises(FinishIteration) as exc_info:
101+
handle_llm(test_text, executor)
102+
103+
# We check that run_external_cmd was called with these arguments:
104+
mock_run_cmd.assert_called_once_with("llm", "--help", restart_cli=False)
105+
# And the function should raise FinishIteration(None)
106+
assert exc_info.value.args[0] is None
90107

91108
@patch("litecli.packages.special.llm.llm")
92109
@patch("litecli.packages.special.llm.run_external_cmd")

0 commit comments

Comments
 (0)