Skip to main content

A collection of prompts

Project description

bartste-prompts

A command-line tool to generate prompts for Large Language Models (LLMs) using customizable instruction templates.

Introduction

bartste-prompts is a CLI tool designed for developers to generate prompts for Large Language Models (LLMs). It uses a set of predefined instructions that can be customized per command and per file type. The tool is built with extensibility in mind, allowing users to define their own instructions. The CLI will adapt to custom instructions as a fixed directory structure is assumed.

Key features include:

  • Dynamic prompt assembly from markdown instruction templates
  • Support for multiple default commands (e.g., explain, fix, refactor, etc.) and file types
  • Integration with tools like aider for code editing and explanation
  • Can be extended with custom instructions
  • The CLI adapts to new instructions. No changes in code are necessary.

Installation

You can install bartste-prompts using pip:

pip install bartste-prompts

For development dependencies (testing, linting, etc.), install with:

pip install bartste-prompts[dev]

This will install the prompts command-line tool.

Usage

The basic command structure is:

prompts <command> [options]

Available Commands

The tool comes with these default commands:

  • docstrings: Generate docstrings for given files
  • explain: Explain code functionality
  • fix: Fix code issues
  • refactor: Improve code structure
  • typehints: Add type hints to code
  • unittests: Generate unit tests
  • commit: Generate conventional commit messages

Common Options

All commands support these options:

  • --action <tool>: Specify output tool (print, json, or aider)
  • --loglevel <level>: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • --logfile <path>: Specify log file location

Command-Specific Options

Each command has additional options that correspond to instruction templates. For example:

# Explain command options
prompts explain --files <files> --filetype <type> --user <text>

# Fix command options
prompts fix --files <files> --filetype <type> --user <text>

Examples

Print prompt for explaining Python code:

prompts explain --files main.py --filetype python

Generate JSON output for adding type hints:

prompts typehints --files utils.py --filetype python --action json

Run aider to fix Lua code:

prompts fix --files script.lua --filetype lua --user "Fix memory leak" --action aider

Craft a Conventional Commit message for staged changes:

prompts commit --user "$(git diff)"

Custom Instructions

You can use custom instructions by specifying the --dir option. The custom directory must follow the same structure as the default _instructions directory. Here's how it works:

Directory Structure

custom_instructions/
├── commands/
│   ├── <command1>/
│   │   ├── command.md
│   │   ├── <key1>.md --> "Text with {value1} as placeholder."
│   │   └── <key2>/
│   │       └── <value2>.md
│   ├── <command2>/
│   │   └── command.md
│   └── ...
└── default/
    ├── <key1>.md
    └── <key2>/
        └── <value2>.md
  • commands/: Contains subdirectories for each command (e.g., explain, fix, etc.)

    • Each command directory must contain a command.md file (base instruction)
    • Additional markdown files or subdirectories correspond to command options (e.g., --files, --user, etc.). Here, the files and subdirectories handle the cli values differently:
      • File: The content of the value can be inserted in the markdown using a python placeholder. For example, for the cli option --files=foo.py, the "files.md" file contains a placeholder {files} which will be replaced by foo.py.
      • Subdirectory: The value represents a filename (without extension) of a markdown file within the subdirectory, which will be read.
  • default/: Contains fallback instructions in case an instruction is not found in the command directory.

Using a fixed directory structure allows the CLI to adapt to the custom instructions. For example, the directory structure above results in the following CLI:

prompts <command1> --key1 <value1> --key2 <value2>
prompts <command2> --key1 <value1> --key2 <value2>

Here, command2 will fallback to the default directory for options, key1 represents a file, value1 will be inserted in key1.md, key2 represents a directory and value2 is a file within the key2 directory.

Troubleshooting

If you encounter any issues, please report them on the issue tracker at: bartste-prompts issues

Contributing

Contributions are welcome! Please see CONTRIBUTING for more information.

License

Distributed under the MIT License.

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

bartste_prompts-1.2.0a0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

bartste_prompts-1.2.0a0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file bartste_prompts-1.2.0a0.tar.gz.

File metadata

  • Download URL: bartste_prompts-1.2.0a0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bartste_prompts-1.2.0a0.tar.gz
Algorithm Hash digest
SHA256 7cff7eee66b35628e2203791bafd8e6d12a7af3444035d843a6f3151665af85c
MD5 fc12f5d7b106d85bc8cb41dde0b7caeb
BLAKE2b-256 93b6d4ddb11fc67a9e82e93f43322f2fac967abc147ba30b2940fd164a031e55

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartste_prompts-1.2.0a0.tar.gz:

Publisher: release.yml on BartSte/bartste-prompts

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

File details

Details for the file bartste_prompts-1.2.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for bartste_prompts-1.2.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 4db4653df6259fea9c8d02771a6a723ced851c4d79d6fa4ae132f373afb2ad5f
MD5 0c3524e6388fa62f3483badb0dc289da
BLAKE2b-256 2df3a72591788caced998d9fea54d784a03ace5456756f679d00d668306ba2e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartste_prompts-1.2.0a0-py3-none-any.whl:

Publisher: release.yml on BartSte/bartste-prompts

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