A lightweight prompt template system for LLM-based projects
Project description
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
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 hyperprompts-0.1.0.tar.gz.
File metadata
- Download URL: hyperprompts-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb51d9c6c948f988a455661309adebf49a6f4a75c771585ee637655661b1f918
|
|
| MD5 |
61da14aaa74304091a266b8b49221312
|
|
| BLAKE2b-256 |
1fdcfb4f635469e73b2bcb0e20b6af91bdbf3d99e67c5ee1a326b36d6a4f1d2a
|
File details
Details for the file hyperprompts-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hyperprompts-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65e858e06a0cfa814ea3341bdee9d23ffad5429bbde4fb1c5f7c144e6617c1e6
|
|
| MD5 |
4b2952f94b60610305d3fc62c6a502ce
|
|
| BLAKE2b-256 |
a581e01395e4d2445c3657fe84013fe895b16dc665c2abdc20c77949a931e6d3
|