A dynamic prompt building library with CLI support.
Project description
prompt-config
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
promptcfgCLI 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:
-
Clone the repository:
git clone https://github.com/AKSHILMY/prompter.git cd prompter
-
Set up a virtual environment:
python3.12 -m venv venv source venv/bin/activate
-
Install in editable mode:
pip install -e "."
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prompt_config-0.1.5.tar.gz.
File metadata
- Download URL: prompt_config-0.1.5.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a643c2114bd6fd19a162aee9239852de90a1f3329c13de89297a1074959e8726
|
|
| MD5 |
e41e9fbec567ab483dec25b2e5c86bc8
|
|
| BLAKE2b-256 |
560dbc773df881b0a95cd0d21d90239d680c97bafe92577e13b815a0c8d50d0e
|
File details
Details for the file prompt_config-0.1.5-py3-none-any.whl.
File metadata
- Download URL: prompt_config-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14562a37f98c0620bfc205f114715ec8f1ce33111e5e9d27644c182dff6ea518
|
|
| MD5 |
09df07bb0cd711f4744bd791509758a8
|
|
| BLAKE2b-256 |
6d684a1fed6882a66ce412d853fa060bb34bb2f9d212746033abd6048a75226f
|