Skip to main content

Parse CLI arguments from natural language using LLMs

Project description

autocli

Parse CLI arguments from natural language descriptions using small LLMs.

Features

  • Natural language CLI description parsing
  • Automatic argument type inference
  • Support for positional and named arguments
  • Built-in help generation
  • Small, efficient LLM (Flan-T5-small, ~250MB)
  • Fallback regex parser for reliability
  • Returns arguments as NamedTuple-like objects

Installation

pip install autocli

Quick Start

import autocli

args = autocli.parse(
    """
    This app greets someone with excitement
    
        $ python greet.py --name Alice --excitement 3
        Hello, Alice!!!
    """
)

print(f"Hello, {args.name}{'!' * args.excitement}")

Examples

Positional args

import autocli

args = autocli.parse(
    """
    This app adds two numbers and prints their sum

        $ python sum.py 1 2
        3
    """
)

print(args[0] + args[1])

Named args and defaults

import autocli

args = autocli.parse(
    """
    This app prints the file with the longest name in the given directory (default: PWD)

        $ ls /tmp
        a.txt ab.txt abc.txt

        $ python longest_filename.py --path /tmp
        abc.txt
    """
)

print(f'finding the longest filename in directory: {args.path})

Named args wth numeric values and allowed ranges

# greet.py

import autocli

args = autocli.parse(
    """
    This app greets the given `name` defaulting to "Earthling" and
    appends `excitement` number of exclamation marks.
    """
)

print(f'{args.name}{'!' * args.excitement}')
$ python greet.py --help
Greets the given name.

Options:

    -n NAME
    --name NAME

        NAME is who is being greeted.

        Default: "Earthling"

    -e EXCITEMENT
    --excitement EXCITEMENT

        EXCITEMENT is a positive integer that contols
        the number of exclamation marks.

        Default: 1
$ python greet.py -e -3
ERROR: The value for EXCITEMENT is too low. The lowest value is 1,
which is also the default.

    -e EXCITEMENT
    --excitement EXCITEMENT

        EXCITEMENT is a positive integer that contols
        the number of exclamation marks.

        Default: 1

Did you mean?
    python greet.py -e 3
$ python greet.py --excitement 42
Greetings, Earthling!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

How It Works

  1. LLM Parsing: Uses Google's Flan-T5-small model to understand your CLI description
  2. Structured Output: Converts natural language to structured argument specifications
  3. Automatic ArgParse: Generates standard Python argparse configuration
  4. NamedTuple-like Access: Returns arguments as an object supporting both attribute and index access

Advanced Usage

Custom Model

from autocli.parser import LLMParser

# Use a different model
parser = LLMParser(model_name="google/flan-t5-base")

Accessing Arguments

args = autocli.parse(description)

# Named arguments via attributes
print(args.name)
print(args.port)

# Positional arguments via indexing
print(args[0])  # First positional arg
print(args[1])  # Second positional arg

Requirements

  • Python 3.8+
  • PyTorch 2.0+
  • Transformers 4.30+

License

MIT

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

autocli_llm-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

autocli_llm-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file autocli_llm-0.1.0.tar.gz.

File metadata

  • Download URL: autocli_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for autocli_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1577460468d9c90d1a082d1c4c7b379862d2ad79e7bfc5bf5301424efb6d1044
MD5 3daa68d90124b7c42d5e032827bae176
BLAKE2b-256 5be0262a1f873efada8ee379848973bba3850f84bc6f95e5666bb98099dd3dc5

See more details on using hashes here.

File details

Details for the file autocli_llm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autocli_llm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for autocli_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bcef5296b5253058933acfc90073a1dfad2ac935f83d7c8e0ec635cd31f8124
MD5 a2186d7b137cdde8e1305241b59b450f
BLAKE2b-256 dc66167b2d02d5d8480c1d81cb4d0fc6fb353d09471fc69cb685627a0a8396d9

See more details on using hashes here.

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