Skip to content
Closed
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
10 changes: 7 additions & 3 deletions llm_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def register_commands(cli):
@click.option("-m", "--model", default=None, help="Specify the model to use")
@click.option("-s", "--system", help="Custom system prompt")
@click.option("--key", help="API key to use")
def cmd(args, model, system, key):
@click.option("--print-only", is_flag=True, help="Print the command without executing it")
def cmd(args, model, system, key, print_only):
"""Generate and execute commands in your shell"""
from llm.cli import get_default_model
prompt = " ".join(args)
Expand All @@ -30,7 +31,10 @@ def cmd(args, model, system, key):
if model_obj.needs_key:
model_obj.key = llm.get_key(key, model_obj.needs_key, model_obj.key_env_var)
result = model_obj.prompt(prompt, system=system or SYSTEM_PROMPT)
interactive_exec(str(result))
if print_only:
print(str(result))
else:
interactive_exec(str(result))

def interactive_exec(command):
session = PromptSession(lexer=PygmentsLexer(BashLexer))
Expand All @@ -46,4 +50,4 @@ def interactive_exec(command):
)
print(output.decode())
except subprocess.CalledProcessError as e:
print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}")
print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}")