Repository: dbcli/litecli

Issue:
When running llm command, `Not Yet Implemented.`message is printed for every alternate invocation
Issue: `Not Yet Implemented` message is printed alternatively while using llm+ command.

### Setup
1) OS: `Mac OSX`
2) Python: `3.12.8`
3) Command: `uv run litecli test.db`
4) Terminal: Ghostty
5) Shell: `fish`

### Trimmed Output 

```fish
 uv run litecli /Users/kracekumar/code/mcp-chatbot/test.db
LiteCli: 0.1.dev429+g5be771e (SQLite: 3.47.1)
GitHub: https://github.com/dbcli/litecli
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Suggest 2 ways to find duplicate rows in the people table"
LLM took 43.58 seconds.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ models default codellama:latest
Not Yet Implemented.
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ models default codellama:latest
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Suggest 2 ways to find duplicate rows in the people table"
LLM took 23.71 seconds.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ models default codellama:qwen2.5:latest
Not Yet Implemented.
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ models default codellama:qwen2.5:latest
Error: Unknown model: codellama:qwen2.5:latest
Command llm failed with exit code 1.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ models default qwen2.5:latest
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Suggest 2 ways to find duplicate rows in the people table"
LLM took 25.18 seconds.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Suggest best way to find best record in the table"
Not Yet Implemented.
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Suggest best way to find best record in the table"
LLM took 24.91 seconds.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "select top 5 visited websites"
Not Yet Implemented.
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "select top 5 visited websites"
LLM took 12.11 seconds.
...
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Write a sql to implement foreign key in the people table"
Not Yet Implemented.
/Users/kracekumar/code/mcp-chatbot/test.db> \llm+ "Write a sql to implement foreign key in the people table"
LLM took 30.67 seconds.
```

- `LLM took 43.58 seconds.`is only extra statement added to the `handle_llm` function

Hints from issue comments:
@kracekumar: This PR https://github.com/dbcli/litecli/pull/213 fixes the issue, so closing the issue.

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be389b6..cf65367 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,9 +2,13 @@
 ## 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))
 
+### Bug Fixes
+
+* Fix a bug where the `\llm` command on alternate invocations weren't detected correctly. (#211)
+
 ### Internal
 
 * Fix typo `pormpt`to `prompt` in `special/llm.py`.
diff --git a/litecli/main.py b/litecli/main.py
index 8895980..263a434 100644
--- a/litecli/main.py
+++ b/litecli/main.py
@@ -444,7 +444,7 @@ def one_iteration(text=None):
                     self.echo(str(e), err=True, fg="red")
                     return
 
-                if special.is_llm_command(text):
+                while special.is_llm_command(text):
                     try:
                         start = time()
                         cur = self.sqlexecute.conn and self.sqlexecute.conn.cursor()
diff --git a/litecli/packages/special/llm.py b/litecli/packages/special/llm.py
index b7304a4..4473af3 100644
--- a/litecli/packages/special/llm.py
+++ b/litecli/packages/special/llm.py
@@ -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):


Test patch:
diff --git a/tests/test_llm_special.py b/tests/test_llm_special.py
index 2f3b010..25bcc9a 100644
--- a/tests/test_llm_special.py
+++ b/tests/test_llm_special.py
@@ -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")