Skip to main content

Ask your llm from the command line

Project description

lask

Ask LLMs right from the terminal.

Features

  • CLI for multiple LLM providers (OpenAI, Anthropic, AWS Bedrock, Azure)
  • Customizable models and parameters
  • Minimal dependencies (requests, boto3 for AWS)
  • Streaming responses
  • Repl mode for interactive use, with temporary chat history
  • Pipe input support
  • Smart command mode: describe what you want in plain English and lask translates it into a shell command, with confirmation before execution

Installation

pip install lask

Usage

With OPENAI_API_KEY in your environment or in ~/.lask-config:

lask What movie is this quote from\? \"that still only counts as one\"

Or as a repl:

lask

==== Lask REPL Mode ====
Using provider: openai
Smart command: auto

> What movie is this quote from? "that still only counts as one"
LLM response here...
> When was that movie released?

Smart command mode also works in the REPL. When smart_command is auto or true, the REPL automatically detects command requests and handles them the same way — propose, confirm, execute:

> show disk usage for the current directory

  du -sh .

Press Enter to run, or any other key to abort.

> explain what du does
The `du` command estimates file space usage...

REPL commands:

Command Description
!help Show available REPL commands
!clear Clear the screen
!history Show prompt history
!vi Switch to Vi editing mode
!emacs Switch to Emacs editing mode
exit / quit Exit the REPL
Ctrl+C Interrupt a running command or response
Ctrl+D Exit the REPL

Or via pipe:

echo "What movie is this quote from? \"that still only counts as one\"" | lask

Smart Command Mode

By default, lask automatically detects if your prompt is asking for a shell command. When it is, it translates your natural language into a command, shows it to you, and waits for confirmation:

$ lask show diff between current branch and main

  git diff HEAD..main

Press Enter to run, or any other key to abort.

Press Enter to execute, or any other key to abort. The executed command is added to your shell history, so you can press to recall and re-run or edit it.

The behaviour is controlled by the smart_command setting (default: auto):

Value Behaviour
auto LLM decides if the prompt is a command request or a general question
true Always treat the prompt as a command request
false Never use smart command mode, always answer normally

In REPL mode, smart command keeps a rolling history of your interactions so you can reference them naturally ("do the same but with -v", "now compress that", etc.). Two settings control what is included:

Setting Default Description
smart_context_commands true Include previous prompts and commands in context
smart_context_output false Also capture and include command output

Setup

  1. Get API keys from your provider:

  2. Create ~/.lask-config:

    [default]
    provider = openai  # openai, anthropic, aws, azure
    system_prompt = Always answer questions concisely.
    
    [openai]
    api_key = your-api-key-here
    model = gpt-4.1
    
    [anthropic]
    api_key = your-api-key-here
    model = claude-3-opus-20240229
    
    [aws]
    model_id = anthropic.claude-3-sonnet-20240229-v1:0
    region = us-east-1
    
    [azure]
    api_key = your-azure-api-key
    resource_name = your-resource-name
    deployment_id = your-deployment-id
    

    See examples/example.lask-config for a full example.

  3. Or use environment variables:

    export OPENAI_API_KEY='your-api-key-here'
    export ANTHROPIC_API_KEY='your-api-key-here'
    # AWS uses standard AWS credentials
    export AZURE_OPENAI_API_KEY='your-api-key-here'
    

Configuration Options

Provider Selection

[default]
provider = openai  # openai, anthropic, aws, azure

Streaming

[openai]
streaming = false  # Disable streaming (true by default)

System Prompts

[default]
system_prompt = Always answer questions concisely.

[openai]
system_prompt = You are a helpful AI assistant.  # Provider-specific

Smart Command

[default]
smart_command = auto              # auto, true, or false
smart_context_commands = true      # include command history in context
smart_context_output = false       # include command output in context

Provider-Specific Settings

Each provider supports model, temperature, max_tokens, and other parameters.

See examples/example.lask-config for all options.

Development

This repo uses uv:

# Install dependencies
uv sync

# Build
uv build

# Install for development
pip install -e .

# For AWS Bedrock
pip install boto3

License

GNU General Public License v3.0 (GPL-3.0)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lask-0.3.0.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lask-0.3.0-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

Details for the file lask-0.3.0.tar.gz.

File metadata

  • Download URL: lask-0.3.0.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lask-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ef7f80a5af0e16bbedf089f7e8a1e7d3a51746c808e45193e338b76111fbeb51
MD5 95af9bd73fdd7112dfee8754e3f0c9fe
BLAKE2b-256 28d622c40705c11f88499543643f70618664e12b2841ee146870c4a14c357465

See more details on using hashes here.

Provenance

The following attestation bundles were made for lask-0.3.0.tar.gz:

Publisher: pypipublish.yml on Open-Source-Lodge/lask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lask-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lask-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 37.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lask-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4afe968a9681702255434eb1fb19431dc9c0e553eb4a3ec74489aab8b8057805
MD5 7003fc6a94b342ae644166a5c518b000
BLAKE2b-256 836a8dd467b2ab448b800114a4027e1008e63a798548d7618f3029533fe1174e

See more details on using hashes here.

Provenance

The following attestation bundles were made for lask-0.3.0-py3-none-any.whl:

Publisher: pypipublish.yml on Open-Source-Lodge/lask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page