File tree 2 files changed +19
-5
lines changed
2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,11 @@ def prompt(
143
143
144
144
Documentation: https://llm.datasette.io/en/stable/usage.html
145
145
"""
146
+ # If no prompt is provided, and we are in a TTY, show the help
147
+ if sys .stdin .isatty () and not prompt :
148
+ click .echo (click .Context (cli ).get_help ())
149
+ return
150
+
146
151
if log and no_log :
147
152
raise click .ClickException ("--log and --no-log are mutually exclusive" )
148
153
@@ -153,18 +158,14 @@ def read_prompt():
153
158
154
159
# Is there extra prompt available on stdin?
155
160
stdin_prompt = None
156
- if not sys .stdin .isatty ():
157
- stdin_prompt = sys .stdin .read ()
161
+ stdin_prompt = sys .stdin .read ()
158
162
159
163
if stdin_prompt :
160
164
bits = [stdin_prompt ]
161
165
if prompt :
162
166
bits .append (prompt )
163
167
prompt = " " .join (bits )
164
168
165
- if prompt is None and not save and sys .stdin .isatty ():
166
- # Hang waiting for input to stdin (unless --save)
167
- prompt = sys .stdin .read ()
168
169
return prompt
169
170
170
171
if save :
Original file line number Diff line number Diff line change @@ -570,3 +570,16 @@ def test_model_defaults(tmpdir, monkeypatch):
570
570
assert config_path .exists ()
571
571
assert llm .get_default_model () == "gpt-4o"
572
572
assert llm .get_model ().model_id == "gpt-4o"
573
+
574
+
575
+ def test_interactive_llm_empty_prompt ():
576
+ runner = CliRunner ()
577
+ # use a pty for stdin
578
+ master , _ = os .openpty ()
579
+ input = os .fdopen (master , "r" )
580
+ args = ["--no-stream" ]
581
+ result = runner .invoke (cli , args , input = input , catch_exceptions = False )
582
+ assert result .exit_code == 0
583
+ # ensure the result is the help message
584
+ assert result .output .startswith ("Usage:" )
585
+ input .close ()
You can’t perform that action at this time.
0 commit comments