Type-safe prompt template builder for LLM APIs
Project description
philiprehberger-prompt-builder
Type-safe prompt template builder for LLM APIs.
Install
pip install philiprehberger-prompt-builder
Usage
Fluent Builder
from philiprehberger_prompt_builder import Prompt
messages = (
Prompt()
.system("You are a helpful assistant.")
.user("Summarize this article: {article}")
.render(article="Long article text here...")
)
# [{"role": "system", "content": "You are a helpful assistant."},
# {"role": "user", "content": "Summarize this article: Long article text here..."}]
Few-Shot Examples
messages = (
Prompt()
.system("Classify the sentiment.")
.example(user="I love this!", assistant="positive")
.example(user="Terrible product.", assistant="negative")
.user("{text}")
.render(text="Pretty good actually")
)
Reusable Templates
from philiprehberger_prompt_builder import PromptTemplate
summarizer = PromptTemplate(
system="You are a {tone} summarizer. Output in {format}.",
user="Summarize: {content}",
defaults={"tone": "concise", "format": "bullet points"},
)
# Use with defaults
messages = summarizer.render(content="Article text...")
# Override defaults
messages = summarizer.render(content="...", tone="detailed", format="paragraphs")
# Create variant
verbose = summarizer.extend(tone="thorough", format="essay")
Token Estimation
prompt = Prompt().system("...").user("{text}")
estimated = prompt.estimate_tokens(text="Hello world")
API
| Method | Description |
|---|---|
.system(content) |
Add a system message |
.user(content) |
Add a user message |
.assistant(content) |
Add an assistant message |
.example(user, assistant) |
Add a few-shot example pair |
.render(**kwargs) |
Render with variable substitution → list of dicts |
.estimate_tokens(**kwargs) |
Rough token count (~4 chars/token) |
License
MIT
Project details
Release history Release notifications | RSS feed
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 philiprehberger_prompt_builder-0.1.2.tar.gz.
File metadata
- Download URL: philiprehberger_prompt_builder-0.1.2.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91b35da1c96bd416c210f848b606262877d04cb4d3b58083ff0e62b7a1288f23
|
|
| MD5 |
44e4e9e4e71f5ee7c593f89b3603e4ab
|
|
| BLAKE2b-256 |
283c08347e63f6fd0b001140b8fe5435b43964efe25557c06866d17587776adf
|
File details
Details for the file philiprehberger_prompt_builder-0.1.2-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_prompt_builder-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d90f334e61817f886df41f6211a11d6eb49e2622cd9d9447ef4c347a2456034e
|
|
| MD5 |
7855272b678aef5d00d87474563b0580
|
|
| BLAKE2b-256 |
37ad2ffd35491a39d24df563b96d4bbf28d2f5c157dcc86249179f191223a3d1
|