Skip to main content

A dynamic prompt building library with CLI support.

Project description

prompt-config

PyPI version Python Versions License

prompt-config is a dynamic prompt building library designed for LLM applications. It allows you to define complex prompts in a structured YAML configuration, manage dynamic variables with Jinja2 templating, and construct prompts at runtime using a powerful tagging and filtering system.

Perfect for managing prompts as code, enabling environment-specific prompts, and ensuring reproducibility in your AI applications.


Features

  • YAML Configuration: Centralize your prompt definitions in a clean, readable YAML file.
  • Dynamic Variables: Use Jinja2 syntax ({{ variable }}) for dynamic content insertion.
  • Tag-Based Composition: conditionally include or exclude prompt parts based on tags (e.g., dev, prod, python, web).
  • Validation: Enforce required variables and provide default values.
  • CLI Tool: Built-in promptcfg CLI for easy integration into scripts and CI/CD pipelines.
  • Python API: seamless integration into your Python applications.

Installation

Requires Python 3.11 or higher.

pip install prompt-config

Quick Start

1. Initialize Configuration

Create a starter promptcfg.yaml file in your current directory:

promptcfg init

This will generate a file similar to:

version: "1.0"
prompts:
  - id: "system_intro"
    text: "You are a helpful AI assistant named {{ assistant_name }}."
    default: true
    variables:
      - name: "assistant_name"
        default: "Prompter"

  - id: "coding_capabilities"
    text: "You are an expert in {{ language }} programming."
    tags: ["coding"]
    variables:
      - name: "language"
        required: true

2. Build via CLI

Generate a prompt by activating specific tags and passing variables:

promptcfg build --tags coding --vars assistant_name=Jarvis,language=Python

Output:

--- Generated Prompt ---
You are a helpful AI assistant named Jarvis.
You are an expert in Python programming.
------------------------

3. Build via Python API

Integrate prompt-config directly into your application:

from promptcfg.config import PromptConfig
from promptcfg.builder import PromptBuilder

# Load the configuration
config = PromptConfig.load("promptcfg.yaml")

# Initialize the builder
builder = PromptBuilder(config)

# Build the prompt
prompt = builder.build(
    tags=["coding"],
    variables={
        "assistant_name": "Jarvis",
        "language": "Python"
    }
)

print(prompt)

CLI Usage

The promptcfg generic command line interface supports the following subcommands:

  • init: Create a generic configuration file.
  • build: Construct a prompt based on tags and variables.

Build Options

Option Description
--config Path to the YAML config file (default: promptcfg.yaml)
--tags Comma-separated list of tags to include (e.g., dev,test)
--vars Key-value pairs for variables (e.g., key=value,foo=bar)
--include-ids Explicitly include specific prompt blocks by ID
--exclude-ids Explicitly exclude specific prompt blocks by ID
--exclude-tags Exclude prompt blocks matching these tags
--list-prompts List all available prompt IDs and their status
# Example: Build with exclusions
promptcfg build --tags all --exclude-tags deprecated --vars user_id=123

Development

If you want to contribute or modify the library:

  1. Clone the repository:

    git clone https://github.com/AKSHILMY/prompter.git
    cd prompter
    
  2. Set up a virtual environment:

    python3.12 -m venv venv
    source venv/bin/activate
    
  3. Install in editable mode:

    pip install -e "."
    
  4. Run Tests:

    python -m unittest discover tests
    

License

This project is licensed under the terms of the Apache License 2.0.

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

prompt_config-0.1.7.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

prompt_config-0.1.7-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file prompt_config-0.1.7.tar.gz.

File metadata

  • Download URL: prompt_config-0.1.7.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for prompt_config-0.1.7.tar.gz
Algorithm Hash digest
SHA256 76477a3f763833111f06041fece710316a85efd890940e0ecfbd0f63885d3fd3
MD5 122e759c018b6eca4bcef7e1627d06e2
BLAKE2b-256 cfae2c8d8f15645aef00474dafe284f185f329ea3cee9059d7b670f2f9962071

See more details on using hashes here.

File details

Details for the file prompt_config-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: prompt_config-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for prompt_config-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d56e6f7f18da8ee8d1cccf0238e00674354d124ba00941f12043d389432c5fc2
MD5 a9594612e5fe17074ba9ab61da0f179f
BLAKE2b-256 3a41339d69c98c5d510b11dfa276a8417ef466f1e58b381f3d7079e54cd71ee1

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