Skip to main content

🎸 Rock your prompts! Simple, powerful prompt optimization with minimal boilerplate

Project description

School of Prompt 🎸

Simple, powerful prompt optimization with minimal boilerplate.

Inspired by School of Rock - where every prompt can become a legend.

Quick Start

from school_of_prompt import optimize

# That's it! One function call to optimize prompts
results = optimize(
    data="band_reviews.csv",
    task="classify sentiment", 
    prompts=["How does this fan feel about our band?", "Is this review positive or negative?"],
    api_key="sk-..."
)

print(f"Best prompt: {results['best_prompt']}")
print(f"Accuracy: {results['best_score']:.2f}")

Installation

pip install school-of-prompt

Features

Features

🚀 Level 0: Dead Simple

Perfect for quick experiments and getting started.

results = optimize(
    data="band_reviews.csv",
    task="classify sentiment",
    prompts=["How do fans feel about this?", "Analyze sentiment"],
    api_key="sk-..."
)

🎛️ Level 1: More Control

Add configuration without complexity.

results = optimize(
    data="student_performances.csv",
    task="rate performance from 1-10",
    prompts="prompts/performance_variants.txt",  # Read from file
    model={
        "name": "gpt-4", 
        "temperature": 0.1,
        "max_tokens": 50
    },
    metrics=["mae", "accuracy"],
    sample_size=1000,
    api_key="sk-..."
)

🔧 Level 2: Full Extension

Custom everything for advanced use cases.

from school_of_prompt import optimize, CustomMetric, CustomDataSource

class RockStarMetric(CustomMetric):
    name = "rock_star_score"
    
    def calculate(self, predictions, actuals):
        # Your domain-specific metric
        return calculate_rock_star_potential(predictions, actuals)

results = optimize(
    data=CustomDataSource(my_database),
    task=MyCustomTask(),
    prompts=dynamic_prompt_generator,
    model=my_llm_wrapper,
    metrics=[RockStarMetric(), "accuracy"],
    api_key="sk-..."
)

Smart Defaults

The framework automatically handles common scenarios:

📊 Auto Data Loading

  • CSV files: data="band_reviews.csv"
  • JSONL files: data="performances.jsonl"
  • DataFrames: data=my_dataframe
  • Custom sources: data=MyDataSource()

🎯 Auto Task Detection

  • "classify sentiment" → Sentiment classification
  • "rate from 1-10" → Performance rating task
  • "categorize content" → Multi-class classification
  • "generate summary" → Text generation

📏 Auto Metrics Selection

  • Classification → Accuracy, F1-score
  • Regression → MAE, RMSE
  • Generation → BLEU, ROUGE (coming soon)

🤖 Auto Model Setup

  • String: model="gpt-4"
  • Config: model={"name": "gpt-4", "temperature": 0.1}
  • Custom: model=MyModel()

Rock Star Examples

🎸 Band Review Sentiment Analysis

results = optimize(
    data="fan_reviews.csv",
    task="classify sentiment",
    prompts=[
        "How does this fan feel about our band performance?",
        "Is this review positive, negative, or neutral?",
        "Fan reaction analysis: {review}"
    ],
    api_key=os.getenv("OPENAI_API_KEY")
)

🥁 Student Performance Rating

results = optimize(
    data="student_performances.csv", 
    task="rate performance from 1-10",
    prompts=[
        "Rate this {instrument} performance from 1-10: {performance}",
        "As a rock teacher, how would you score this?",
        "School of Rock grade: {performance}"
    ],
    model="gpt-4",
    metrics=["mae", "accuracy"]
)

🛡️ Content Safety for Young Rockers

results = optimize(
    data="song_lyrics.csv",
    task="classify content as school-appropriate", 
    prompts="prompts/safety_check.txt",
    model={
        "name": "gpt-4",
        "temperature": 0.0,
        "max_tokens": 20
    },
    sample_size=500
)

🎬 Age Rating Classification

results = optimize(
    data="youtube_videos.csv",
    task="rate appropriate age from 0-18",
    prompts=[
        "What age is appropriate for: {title} - {description}",
        "Age rating for: {title}. Content: {description}",
        "Minimum age for this content: {title}"
    ],
    model="gpt-3.5-turbo",
    metrics=["mae", "accuracy"]
)

API Reference

optimize()

The main optimization function - rock your prompts!

Parameters:

  • data (str|DataFrame|CustomDataSource): Your dataset
  • task (str|CustomTask): Task description or custom task
  • prompts (str|List[str]|Path): Prompt variants to test
  • model (str|dict|CustomModel): Model configuration
  • metrics (List[str]|List[CustomMetric]): Evaluation metrics
  • api_key (str): API key (or set OPENAI_API_KEY env var)
  • sample_size (int): Limit evaluation to N samples
  • random_seed (int): For reproducible sampling
  • output_dir (str): Save detailed results
  • verbose (bool): Print progress

Returns:

{
    "best_prompt": "How does this fan feel about our band?",
    "best_score": 0.892,
    "prompts": {
        "prompt_1": {"scores": {"accuracy": 0.856, "f1_score": 0.834}},
        "prompt_2": {"scores": {"accuracy": 0.892, "f1_score": 0.889}}
    },
    "summary": {"metrics": {...}},
    "details": [...]
}

Environment Setup

# Set your API key
export OPENAI_API_KEY="sk-your-key-here"

# Or pass directly
results = optimize(..., api_key="sk-your-key-here")

Data Format

Your data should have:

  • Input columns: Text or features to analyze
  • Label column: Ground truth (named label, target, class, etc.)

CSV Example:

review,sentiment
"The band was amazing!",positive
"Terrible performance.",negative
"It was okay.",neutral

JSONL Example:

{"review": "The band was amazing!", "sentiment": "positive"}
{"review": "Terrible performance.", "sentiment": "negative"}

Extension Points

For advanced rockers who need custom behavior:

from school_of_prompt import CustomMetric, CustomDataSource, CustomModel, CustomTask

class MyRockMetric(CustomMetric):
    name = "rock_factor"
    def calculate(self, predictions, actuals):
        return calculate_rock_awesomeness(predictions, actuals)

class MyDataSource(CustomDataSource):
    def load(self):
        return load_from_rock_database()

class MyModel(CustomModel):
    def generate(self, prompt):
        return my_rock_llm_call(prompt)

class MyTask(CustomTask):
    def format_prompt(self, template, sample):
        return template.format(**sample)
    
    def extract_prediction(self, response):
        return parse_rock_response(response)
    
    def get_ground_truth(self, sample):
        return sample["rock_rating"]

Roadmap

  • More Models: Anthropic Claude, local models, Azure OpenAI
  • More Metrics: BLEU, ROUGE, custom domain metrics
  • Auto Optimization: Genetic algorithms, Bayesian optimization
  • Batch Processing: Handle large datasets efficiently
  • Caching: Speed up repeated evaluations

Contributing

We'd love your help! Rock on and contribute to make this even better.

License

MIT License. Rock freely! 🤘


School of Prompt: Where prompts learn to rock! 🎸

"You're not hardcore unless you optimize hardcore!" - Dewey Finn (probably)

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

school_of_prompt-0.2.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

school_of_prompt-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file school_of_prompt-0.2.0.tar.gz.

File metadata

  • Download URL: school_of_prompt-0.2.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for school_of_prompt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a823a10dee88149b3eaf8335a1289bd89ae906a85b5d49cc9de0d52e4d2f3a7d
MD5 28b5283c7facb8f1e0df8e47f6aaa9c0
BLAKE2b-256 ae8284062cf897ca72cca3b31485882e2b5a3fb1f474c898dae02eed61ae4d3e

See more details on using hashes here.

File details

Details for the file school_of_prompt-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for school_of_prompt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c4300a42cdda0db6ca974c90e685ee0004d588b3d9fff964422b8a86abf9187
MD5 e96d07ae68edef605f6b114dd3cdbcf8
BLAKE2b-256 1f81ea515bdbf63516e14be8f82fb127f65966db262e125840ed35024b56c14e

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