Skip to main content

Ask your llm from the command line

Project description

(Still under development)

lask

Ask LLMs right from the terminal.

Supports multiple providers like OpenAI, Anthropic, AWS Bedrock, and Azure OpenAI

Usage

Ensure you have OPENAI_API_KEY in your environment variables or configure it in ~/.lask-config, then you can use lask to send prompts to the LLM.

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

Features

  • Simple command-line interface to send prompts to multiple LLM providers
  • Support for OpenAI, Anthropic, AWS Bedrock, and more.
  • Customizable models and parameters for each provider
  • Minimal dependencies (only requires the requests library, and boto3 for AWS)
  • Easy installation via pip
  • Direct output to your terminal
  • Streaming responses for real-time output

Installation

Using pip (recommended)

pip install lask

(For dev, do pip install .)

For a user-specific installation:

pip install --user lask

From source

  1. Clone the repository:

    git clone https://github.com/Open-Source-Lodge/lask.git
    
  2. Navigate to the directory:

    cd lask
    
  3. Install the package:

    pip install -e .
    

Setup

Before using lask, you need to set up API keys for your preferred provider:

  1. Get an API key from your chosen provider:

  2. Create a configuration file at ~/.lask-config in INI format:

    [default]
    provider = openai  # Options: openai, anthropic, aws, azure
    system_prompt = Always answer questions concisely.  # Default system prompt for all providers
    
    [openai]
    # OpenAI-specific settings
    api_key = your-api-key-here
    model = gpt-4.1
    system_prompt = You are a helpful AI assistant.  # Overrides default system prompt
    
    [anthropic]
    # Anthropic-specific settings
    api_key = your-api-key-here
    model = claude-3-opus-20240229
    system_prompt = You are Claude, an AI assistant by Anthropic.
    
    [aws]
    # AWS Bedrock settings
    api_key = your-api-key-here
    model_id = anthropic.claude-3-sonnet-20240229-v1:0
    region = us-east-1
    system_prompt = Respond as a technical consultant.
    
    [azure]
    # Azure OpenAI settings
    api_key = your-azure-api-key
    resource_name = your-resource-name
    deployment_id = your-deployment-id
    system_prompt = You are an Azure OpenAI assistant.
    

    This INI configuration file allows you to set your preferred provider, API keys, and customize the models and parameters for each provider.

    An example configuration file with comments is available in the examples/example.lask-config file.

  3. Alternatively, set the appropriate environment variable:

    For OpenAI (default provider):

    export OPENAI_API_KEY='your-api-key-here'
    

    For Anthropic:

    export ANTHROPIC_API_KEY='your-api-key-here'
    

    For AWS Bedrock: Ensure your AWS credentials are properly configured.

    For Azure OpenAI:

    export AZURE_OPENAI_API_KEY='your-api-key-here'
    

    To make these permanent, add the export line to your ~/.bashrc, ~/.zshrc, or equivalent shell configuration file.

    Windows users can use set (CMD) or $env: (PowerShell) instead of export.

API Key Issues

If you see an error about the API key:

  1. Ensure you've configured the API key in the ~/.lask-config file
  2. Alternatively, double-check that you've correctly set the appropriate environment variable for your chosen provider:
    • OpenAI: OPENAI_API_KEY
    • Anthropic: ANTHROPIC_API_KEY
    • AWS: Check your AWS credentials configuration
  3. Verify your API key is valid and has enough credits

Configuration

You can find a fully commented example configuration file in the examples/example.lask-config directory of this repository. Copy it to your home directory as ~/.lask-config and customize it to your needs.

Selecting a Provider

Set your preferred provider in the [default] section:

[default]
provider = openai  # Options: openai, anthropic, aws

Streaming Configuration

By default, responses are streamed in real-time to your terminal. You can disable streaming in your configuration file:

[openai]
streaming = false  # Disable streaming for OpenAI

[anthropic]
streaming = false  # Disable streaming for Anthropic

When streaming is enabled, you'll see the response appearing in real-time as it's generated. When disabled, you'll get the complete response only after it's fully generated.

System Prompts

You can set system prompts at two levels:

  1. Default system prompt for all providers:

    [default]
    system_prompt = Always answer questions concisely.
    
  2. Provider-specific system prompts that override the default:

    [openai]
    system_prompt = You are a helpful AI assistant.
    

System prompts allow you to set consistent behavior across all your interactions with the LLM. For example, you can use them to:

  • Specify a response style: "Always answer as short and concise as possible"
  • Set a persona: "You are a helpful assistant specialized in Python programming"
  • Request responses in a specific language: "Always respond in Spanish"

Provider-specific Configuration

Each provider has its own section where you can set provider-specific options:

OpenAI

[openai]
api_key = your-openai-api-key
model = gpt-4.1
temperature = 0.7
max_tokens = 2000
streaming = true  # Enable streaming (this is the default)
system_prompt = You are a helpful AI assistant.  # Provider-specific system prompt

Anthropic

[anthropic]
api_key = your-anthropic-api-key
model = claude-3-opus-20240229
temperature = 0.7
max_tokens = 4096
streaming = true  # Enable streaming (this is the default)
system_prompt = You are Claude, an AI assistant by Anthropic.  # Provider-specific system prompt

AWS Bedrock

[aws]
model_id = anthropic.claude-3-sonnet-20240229-v1:0
region = us-east-1
temperature = 0.7
max_tokens = 4096
system_prompt = Respond as a technical consultant.  # Provider-specific system prompt

Azure OpenAI

[azure]
api_key = your-azure-api-key
resource_name = your-resource-name
deployment_id = your-deployment-id
api_version = 2023-05-15
temperature = 0.7
max_tokens = 2000
system_prompt = You are an Azure OpenAI assistant.  # Provider-specific system prompt

Developing

Dependencies

This repo uses uv for running scripts and building the package. uv install instruction

To install the development dependencies, run:

uv sync

Build

To build the package, run:

uv build

Install for development

To install the package in development mode, run:

pip install dist/lask-0.1.0-py3-none-any.whl

or

pip install -e .

With the -e flag, you can edit the source code and see changes immediately without reinstalling.

If you want to use AWS Bedrock, also install boto3:

pip install boto3

(I have not tested aws yet, so please report any issues you find)

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.1.9.tar.gz (26.0 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.1.9-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lask-0.1.9.tar.gz
Algorithm Hash digest
SHA256 177b9be74d95123314bd5eacbb2e643f8ec8e27bc7f4f3c6974bb428b70374d8
MD5 da2b5194b41b2dd45ff91de6e7d95821
BLAKE2b-256 7e2b805885116b8f58538b49f1aa2bd98ad441f8df8a91f2f4130ffc8176d5c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lask-0.1.9.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.1.9-py3-none-any.whl.

File metadata

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

File hashes

Hashes for lask-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e75146ab9959ab31340942d9b1eb6616a780301e920e74e924b3aa19a82bb98f
MD5 018c59fe67bf56c3d327bb01a8a415a3
BLAKE2b-256 7b213f9e173a9d4886feb6c140870c6f560facda1d34a4cec99d7f6ccc820e53

See more details on using hashes here.

Provenance

The following attestation bundles were made for lask-0.1.9-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