Skip to main content

A lightweight prompt template system for LLM-based projects

Project description

hyperprompt

hyperprompt is a lightweight Python package designed for creating dynamic and customizable text templates using Pythonic logic.

With hyperprompt, you define meta-prompts using pure Python, compile them with configuration inputs to produce templates with placeholders, and then compile these templates with actual data to generate the final output.

Installation

Install hyperprompt using pip:

pip install hyperprompt

Features

  • 🚀 Pythonic and Intuitive: Define meta-prompts using standard Python functions and control structures.
  • 🛠️ Conditional Logic: Leverage Python's control flow to create dynamic and context-aware templates.

Usage Example

Defining the Meta-Prompt

from hyperprompt import hyperprompt

# Step One: Define the meta-prompt
@hyperprompt
def greeting_template(user_role: str, language: str):
    match language:
        case "English":
            greeting = "Hello, {name}!"
        case "Spanish":
            greeting = "¡Hola, {name}!"    
    
    role_info = "You have {tasks} tasks pending" if user_role == "admin" else None
    footer = "Have a great day!"

Compiling

template, placeholders = greeting_template(user_role="admin", language="English")
print(placeholders) # ['name', 'tasks']

final_prompt = template.format(name="Alice", tasks="5")
print(final_prompt) # Hello, Alice! You have 5 tasks pending. Have a great day!

template, placeholders = greeting_template(user_role="user", language="Spanish")
print(placeholders) # ['name']

final_prompt = template.format(name="Carlos") 
print(final_prompt) # Hello, Carlos! Have a great day!

License

This project is licensed under the MIT License. See the 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

hyperprompts-0.1.0.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

hyperprompts-0.1.0-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page