A delightful Python package for managing LLM prompts with versioning and i18n-style string management
Project description
Prompt Versions Manager ๐
A delightful Python package for managing LLM prompts with versioning and i18n-style string management. Perfect for keeping your AI conversations organized and maintainable!
Why Prompt Versions Manager?
Managing prompts for Large Language Models can quickly become messy. As your application grows, you might find yourself:
- Copy-pasting prompts across different files ๐
- Struggling to maintain consistent versions ๐
- Manually handling string interpolation ๐ง
- Losing track of prompt variations ๐
Prompt Versions Manager solves these problems by providing an elegant, i18n-inspired solution that makes prompt management a breeze!
Use Cases ๐ก
Multi-Model Prompt Management
Use versions to maintain model-specific prompts. For example:
from prompt_versions_manager import PromptVersionsManager
p = PromptVersionsManager()
# GPT-4 specific prompt
gpt4_response = p.version("gpt4").t("system.role")
# Claude specific prompt
claude_response = p.version("claude").t("system.role")
# Llama2 specific prompt
llama_response = p.version("llama2").t("system.role")
# Get all versions for LLM scoring
versions = p.get_all_versions("system.role")
# Returns: [
# {"version": "claude", "value": "You are Claude, an AI assistant..."},
# {"version": "gpt4", "value": "You are GPT-4, a large language model..."},
# {"version": "llama2", "value": "You are Llama 2, an open-source AI..."}
# ]
Multiple Prompt Sets
Use named managers to handle different types of prompts in your project:
# Setup managers for different use cases
chat = PromptVersionsManager.setup("chat")
email = PromptVersionsManager.setup("email")
# Chat prompts in prompts/chat/v1.json
chat.set("greeting", "Hey {name}! How can I help?")
# Email prompts in prompts/email/v1.json
email.set("welcome", "Dear {name}, Welcome aboard!")
Your prompts directory could look like:
prompts/
โโโ chat/
โ โโโ v1.json
โ โโโ v2.json
โโโ email/
โ โโโ v1.json
โ โโโ v2.json
โโโ default/
โโโ v1.json
Features โจ
- Automatic Prompt Creation - Just use prompts and they're automatically saved
- Version Control - Maintain different versions of your prompts
- Variable Interpolation - Use placeholders like
{name}in your prompts - Named Managers - Organize prompts by use case or feature
- JSON Storage - Simple, human-readable storage format
- FastAPI Integration - Ready-to-use REST endpoints for your prompts
- Zero Configuration - Works out of the box with sensible defaults
Quick Start ๐โโ๏ธ
from prompt_versions_manager import PromptVersionsManager
# Get the default prompt manager
p = PromptVersionsManager()
# Use prompts with variables
welcome = p.t("welcome.message.{name}", name="Alice")
# Creates and returns: "welcome.message.Alice"
# Update existing prompts
p.set("welcome.message", "Hello {name}! Welcome aboard!")
welcome = p.t("welcome.message", name="Alice")
# Returns: "Hello Alice! Welcome aboard!"
# Switch versions
complex_prompt = (p.version("v2")
.t("debug.code.{language}.{aspect}",
language="Python",
aspect="performance"))
# List all versions
versions = p.versions() # ['v1', 'v2']
# Find all versions of a prompt
welcome_versions = p.versions_for("welcome.message")
FastAPI Integration ๐
from fastapi import FastAPI
from prompt_versions_manager import PromptVersionsManager
app = FastAPI()
chat = PromptVersionsManager("chat")
email = PromptVersionsManager("email")
@app.get("/prompts/{manager}/{version}/{prompt_id}")
async def get_prompt(manager: str, version: str, prompt_id: str, **params):
p = PromptVersionsManager(manager)
return {"prompt": p.version(version).t(prompt_id, **params)}
@app.get("/versions/{manager}")
async def list_versions(manager: str):
return {"versions": PromptVersionsManager(manager).versions()}
Configuration ๐ ๏ธ
Configure through environment variables:
export PROMPTS_DIR="./prompts" # Base directory for all prompt managers
export PROMPT_VERSION="v1" # Default version
Directory Structure ๐
Each named manager gets its own subdirectory:
prompts/
โโโ chat/ # Chat prompts
โ โโโ v1.json
โ โโโ v2.json
โโโ email/ # Email prompts
โโโ v1.json
โโโ v2.json
Example chat/v1.json:
{
"greeting": "Hey {name}! How can I help?",
"farewell": "Thanks {name}! Have a great day!"
}
Installation ๐ฆ
pip install prompt-versions-manager
Contributing ๐ค
We love contributions! Feel free to:
- Fork the repository
- Create a feature branch
- Submit a pull request
License ๐
MIT License - feel free to use this in your projects!
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 prompt_versions_manager-0.0.1.tar.gz.
File metadata
- Download URL: prompt_versions_manager-0.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
269b46794b296c71664de35430f665bc4cf586929a9bd448901dc9ddb337c442
|
|
| MD5 |
eb0b62685399680793f2c8ccc313638b
|
|
| BLAKE2b-256 |
b720e801beea7f953e5a6389969fe05eb83cddecd1a4df4a906e1efacafc48b6
|
File details
Details for the file prompt_versions_manager-0.0.1-py3-none-any.whl.
File metadata
- Download URL: prompt_versions_manager-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
761a1035074f552f4db2812d8f7615757e5a04f76596503e08e1bb35e71525c1
|
|
| MD5 |
8925a826b5679fcb8776368a2283fb7e
|
|
| BLAKE2b-256 |
57461c98e9aee915f96d12703e7e13b35963fccada06eeb07c9e12eed42eb0b9
|