Skip to main content

Structured Prompt Engineering for LLM Apps

Project description

PromptKit

A production-grade library for structured prompt engineering for LLMs. Define, validate, and execute LLM prompts using YAML files with input validation, engine abstraction, and CLI support.

Features

  • 📝 YAML-based prompt definitions with Jinja2 templating
  • 🔍 Input validation using Pydantic schemas
  • 🏗️ Engine abstraction supporting OpenAI and local models
  • 💰 Token estimation and cost calculation
  • 🖥️ CLI interface for quick prompt execution
  • 🧪 Fully tested with comprehensive test suite

Installation

pip install promptkit-core

For development:

pip install promptkit-core[dev]

📚 Documentation

For detailed usage and examples, please refer to the PromptKit Documentation.

Repository

Source code: https://github.com/ochotzas/promptkit

Quick Start

1. Define a prompt in YAML

Create greet_user.yaml:

name: greet_user
description: Basic greeting
template: |
  Hello {{ name }}, how can I help you today?
input_schema:
  name: str

2. Use in Python

from promptkit.core.loader import load_prompt
from promptkit.core.runner import run_prompt
from promptkit.engines.openai import OpenAIEngine

# Load prompt from YAML
prompt = load_prompt("greet_user")

# Configure engine
engine = OpenAIEngine(api_key="sk-...")

# Run prompt
response = run_prompt(prompt, {"name": "Alice"}, engine)
print(response)

3. Use the CLI

# Run a prompt
promptkit run greet_user --key sk-... --name Alice

# Just render the template
promptkit render greet_user --name Alice

# Validate prompt structure
promptkit lint greet_user

Prompt YAML Structure

name: prompt_identifier
description: What this prompt does
template: |
  Your Jinja2 template here with {{ variables }}
input_schema:
  variable_name: str
  another_var: int
  optional_var: "str | None"

Supported Engines

  • OpenAI: Complete OpenAI API support
  • Ollama: Local model support (work in progress)

Token Estimation

from promptkit.utils.tokens import estimate_tokens, estimate_cost

tokens = estimate_tokens("Your prompt text here")
cost = estimate_cost(tokens, "gpt-4")
print(f"Estimated cost: ${cost:.4f}")

Development

# Clone the repository
git clone https://github.com/ochotzas/promptkit.git
cd promptkit

# Install development dependencies
pip install -e .[dev]

# Run tests
pytest

# Format code
black .
isort .

# Type checking
mypy promptkit/

License

MIT License - see LICENSE file for details.

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

promptkit_core-0.1.0.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

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

promptkit_core-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptkit_core-0.1.0.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for promptkit_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26af392d2654c5c2e3f2d371d2a8583cf0bd5111a7b06019fe3900158dc4c3d7
MD5 82fb69c38acccbbdd9ec62c94967f7ae
BLAKE2b-256 67a58f389c765c3b7d426fa297046c2ca4c5610bef55af5ec669406c38f7e61d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: promptkit_core-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for promptkit_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed3bfefebaaa707baa2e8ada9621a4fb7e3ee53b19bccf3802397f2336865a5c
MD5 f05f4c3b9bb2cca294502acbfecda5f7
BLAKE2b-256 4d4eb03d85c32c7fd258cc580dc65f6394254b1dd4d9be79762259bb88260e7b

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