Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_prompt_builder-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file philiprehberger_prompt_builder-0.1.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_prompt_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35fe00a763a9012607fef5fb9395c528312974b42dd8ef561260fb50141020e8
MD5 1aba646f63361d85a5a3212391482d3f
BLAKE2b-256 66dd4ce281e97e5bf2f55d2c671fa1644ccb40bed855de57ad5c4b2ae865c26b

See more details on using hashes here.

File details

Details for the file philiprehberger_prompt_builder-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_prompt_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c03146a436556c714d9e1a738e4969af0cee70a0f221e0eeaae09e955a7e349
MD5 5bcbb189879f178d02c8cd587053672a
BLAKE2b-256 1602d2476127f5dddf3edf74b8a3ea7d73461bde25792e731a12121e276ecdb7

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