Skip to main content

A Python library for managing and organizing prompts for Large Language Models (LLMs)

Project description

Promptsy

Promptsy is a Python library designed for managing and organizing prompts for language models in a structured way. It provides a convenient method to store, retrieve, and format prompts using YAML files.

Features

  • Save prompts to YAML files with a specified name and directory structure
  • Load prompts from YAML files by name
  • Format prompts with dynamic values using keyword arguments
  • Automatically create directories for prompts if they don't exist
  • List all available prompts in the specified base directory
  • Colorized error messages for better visibility
  • Enhance prompts using OpenAI's language model

Installation

To install Promptsy, you can use pip:

pip install promptsy

Configuration

Before using the PromptEnhancer, you need to set up your OpenAI API key. You can do this by setting the OPENAI_API_KEY environment variable. Here’s how to set it:

On Windows

set OPENAI_API_KEY=your_api_key_here

On macOS/Linux

export OPENAI_API_KEY=your_api_key_here

Replace your_api_key_here with your actual OpenAI API key.

Usage

Here's a basic example of how to use Promptsy:

from promptsy.prompt import Prompt
from promptsy.prompt_manager import PromptManager

# Create an instance of PromptManager
manager = PromptManager()

# Create an instance of Prompt
prompt = Prompt(
    name="hello_world",
    description="An example prompt",
    template="Hello, {name}!"
)

# Save the prompt using the PromptManager
prompt.save(manager)

# Load the prompt using the PromptManager
loaded_prompt = Prompt.load(manager, "hello_world")

print(loaded_prompt)  # Output: hello_world: An example prompt
print(loaded_prompt.format(name="Taylor Swift"))  # Output: Hello, Taylor Swift!

Prompt Manager

The PromptManager class is responsible for managing the storage and retrieval of prompts. It provides methods for saving prompts to YAML files, loading prompts from YAML files, and listing all available prompts.

Initialization

manager = PromptManager(base_directory='prompts')
  • base_directory (optional): The base directory where the prompts will be stored. Defaults to 'prompts'.

Saving a Prompt

manager.save(prompt, name)
  • prompt (dict): The prompt data to be saved.
  • name (str): The name of the prompt.

Loading a Prompt

loaded_prompt = manager.load(name)
  • name (str): The name of the prompt to load.
  • Returns: The loaded prompt data.

Listing Prompts

prompts = manager.list_prompts()
  • Returns: A list of prompt names.

Prompt Enhancer

The PromptEnhancer class allows you to enhance prompts using OpenAI's language model. It generates improved versions of prompts based on the original template.

Initialization

enhancer = PromptEnhancer(api_key='your_api_key_here')
  • api_key (str, optional): OpenAI API key. If None, it tries to retrieve from the environment variable.
  • model_name (str, optional): The name of the model to be used (default: "gpt-4o-mini").

Enhancing a Prompt

enhanced_prompt = enhancer.enhance_prompt(prompt)
  • prompt (Prompt): A Prompt object containing the original prompt template.
  • Returns: A new Prompt object with the enhanced template.

Example Usage of Prompt Enhancer

Here’s an example of how to use the PromptEnhancer with the prompt_toddlers_story_time:

from promptsy.prompt import Prompt
from promptsy.prompt_manager import PromptManager
from promptsy.prompt_enhancer import PromptEnhancer

# Create an instance of PromptManager
manager = PromptManager()

# Create an instance of Prompt for toddlers story time
prompt_toddlers_story_time = Prompt(
    name="toddlers_story_time",
    description="Write a bedtime story for toddlers",
    template="You are a bedtime story teller for toddlers. Write a story for a toddler about a {animal} that goes on an adventure to {place}."
)

# Save the original prompt
prompt_toddlers_story_time.save(manager)

# Create an instance of PromptEnhancer
enhancer = PromptEnhancer()

# Enhance the prompt
enhanced_prompt = enhancer.enhance_prompt(prompt_toddlers_story_time)

print("Enhanced Prompt:")
print(enhanced_prompt.template)

Saving Enhanced Prompts

The enhanced prompts are automatically saved in the enhanced_prompts directory.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

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

promptsy-0.1.3.5.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

promptsy-0.1.3.5-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file promptsy-0.1.3.5.tar.gz.

File metadata

  • Download URL: promptsy-0.1.3.5.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for promptsy-0.1.3.5.tar.gz
Algorithm Hash digest
SHA256 e3094821b7d903d1cb4d6921079c72b3d8d35a23e1272ad690ef7f5560ef27b8
MD5 e89ee51fb24fc7058a8fd7721d9b1156
BLAKE2b-256 d480c8ad06a7c708b839216e872a37b1470d6219d1f0df77b7b19e0cd8a62911

See more details on using hashes here.

File details

Details for the file promptsy-0.1.3.5-py3-none-any.whl.

File metadata

  • Download URL: promptsy-0.1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for promptsy-0.1.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b2aebc37b265974b526524e211678e78edcac82bf8bdee594aa81aeb9eb18e21
MD5 a051b3697e3209bc4f5704c07d09dc2b
BLAKE2b-256 9d1d6ed3df9e675e40f062b108f5bf61b0cd47ff942641a90b93b98b4158411d

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