Generative AI Prompt extensions
A flexible, composable library for constructing and transforming LLM prompts with a fluent interface.
Installation
pip install aipp
Development Setup
uv venv
source .venv/bin/activate
uv sync --group e
pytest -s
code .
Overview
Generative AI Prompt extensions helps you build complex prompts with:
- Chain-of-thought reasoning instructions
- Variable substitution
- Few-shot examples
- Role/persona assignment
- JSON data formatting
- Structured output requirements
- And more...
Quick Start
from aipp import PromptBuilder
# Simple example
prompt = (
PromptBuilder()
.configure_variables(model="GPT-4", task="summarization")
.step_by_step(detailed=True)
.prompt("Create a summary using {model} for {task} task.")
)
print(str(prompt))
Output:
Please provide a detailed, step-by-step explanation with thorough reasoning at each step.
Create a summary using GPT-4 for summarization task.
Features
Variable Substitution
prompt = (
PromptBuilder()
.configure_variables(model="GPT-4", task="summarization", length="short")
.prompt("Create a {length} summary using {model} for {task} task.")
)
JSON Data
data = {
"user": {"name": "Alice", "preferences": ["science", "history"]},
"settings": {"language": "en", "format": "paragraph"}
}
prompt = (
PromptBuilder()
.prompt("Generate content based on user preferences")
.with_json(data)
)
Few-Shot Examples
examples = [
("Summarize: The quick brown fox jumps over the lazy dog.",
"A fox quickly jumps over a dog that is resting."),
("Summarize: The study showed significant results with p<0.05.",
"The research findings were statistically significant.")
]
prompt = (
PromptBuilder()
.prompt("Summarize the following text")
.with_few_shot(examples)
)
Structured Output
schema = {
"type": "object",
"properties": {
"summary": {"type": "string"},
"length": {"type": "integer"},
"topics": {"type": "array", "items": {"type": "string"}}
}
}
prompt = (
PromptBuilder()
.prompt("Analyze the following text")
.structured_output(schema)
)
Chain of Thought
prompt = (
PromptBuilder()
.prompt("Solve this math problem")
.chain_of_thought()
)
Role/Persona Assignment
prompt = (
PromptBuilder()
.prompt("Explain quantum computing")
.as_role("quantum physicist", "with expertise in quantum information theory")
)
Lambda Processors
Use inline lambda functions for custom transformations:
prompt = (
PromptBuilder()
.prompt("Standard prompt text")
.process(lambda content, _: f"IMPORTANT: {content}")
.process(lambda content, _: f"{content}\n\nPlease be thorough.")
)
Combining Processors
Processors can be combined in any order:
prompt = (
PromptBuilder()
.prompt("Summarize the following article")
.chain_of_thought()
.with_few_shot(examples)
.structured_output(schema)
.as_role("professional writer")
.process(lambda content, _: f"{content}\n\nLimit response to 3 paragraphs.")
)
Advanced Usage
Custom Processors
Create your own processors:
from aipp.processors.base import SimpleProcessor
def create_custom_processor(options):
def transform(content, context=None):
# Transform the content based on options
return f"Custom prefix: {content}"
return SimpleProcessor(transform, name="custom_processor")
prompt = (
PromptBuilder()
.prompt("Base content")
.add_processor(create_custom_processor({"option": "value"}))
)
Processing Context
Processors can share context:
def create_metadata_processor():
def transform(content, context=None):
if context is not None:
context['processed_at'] = "2023-01-01"
return content
return SimpleProcessor(transform, name="metadata")
prompt = PromptBuilder()
prompt.add_processor(create_metadata_processor())
prompt.prompt("Content")
print(prompt.metadata) # Contains processed_at
Contributing
We welcome contributions to improve Generative AI Prompt extensions! See CONTRIBUTING.md for detailed information on:
- Architecture overview
- Core concepts
- How to extend the library
- Design patterns used
- Best practices
- Testing guidelines
Please submit issues and pull requests following our guidelines.
License
MIT
Metadata
Release files for aipp 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aipp-0.1.3.tar.gz | 11.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aipp-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.0 kB
Release files / aipp-0.1.3.tar.gz
| Download URL | aipp-0.1.3.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd0c0df7944f4ead741c28f00d44c966a214f94b58c7e1e04e1bb806260a50a0
|
|
BLAKE2b-256 checksum How to use checksums |
3c18bdcac6c9e87be455e45af42162e3101a7439843a928e3b4411792302cb46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.4
|
Release files / aipp-0.1.3-py3-none-any.whl
| Download URL | aipp-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95e5b8caedb4f8f437174f29e1ec35f0345fffb4fece15034d870edad7d63a85
|
|
BLAKE2b-256 checksum How to use checksums |
2887349c4075c37112d402b82e91fb61159f5339d79c1a81ba003373ab10c224
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.4
|
Security for aipp 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.