Skip to main content

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:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License ๐Ÿ“„

MIT License - feel free to use this in your projects!

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

prompt_versions_manager-0.0.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

prompt_versions_manager-0.0.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

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

Hashes for prompt_versions_manager-0.0.1.tar.gz
Algorithm Hash digest
SHA256 269b46794b296c71664de35430f665bc4cf586929a9bd448901dc9ddb337c442
MD5 eb0b62685399680793f2c8ccc313638b
BLAKE2b-256 b720e801beea7f953e5a6389969fe05eb83cddecd1a4df4a906e1efacafc48b6

See more details on using hashes here.

File details

Details for the file prompt_versions_manager-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_versions_manager-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 761a1035074f552f4db2812d8f7615757e5a04f76596503e08e1bb35e71525c1
MD5 8925a826b5679fcb8776368a2283fb7e
BLAKE2b-256 57461c98e9aee915f96d12703e7e13b35963fccada06eeb07c9e12eed42eb0b9

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