Prompt templates in Galileo allow you to create, store, and reuse prompts across your experiments. They provide a structured way to manage your prompts and ensure consistency in your LLM interactions.

Creating Prompt Templates

To create a prompt template, use the create_prompt_template function:

from galileo.prompts import create_prompt_template
from galileo_core.schemas.logging.llm import Message, MessageRole

# Create a prompt template with system and user messages
prompt_template = create_prompt_template(
    name="storyteller-prompt",
    project="my-project",
    messages=[
        Message(role=MessageRole.SYSTEM, content="You are a great storyteller."),
        Message(role=MessageRole.USER, content="Please write a short story about the following topic: {{topic}}")
    ]
)

Getting Prompt Templates

You can retrieve existing prompt templates using the get_prompt_template function:

from galileo.prompts import get_prompt_template

# Get an existing prompt template
prompt_template = get_prompt_template(
    project="my-project",
    name="storyteller-prompt"
) 

Listing Prompt Templates

To list all prompt templates in a project:

from galileo.prompts import list_prompt_templates

# List all prompt templates in a project
templates = list_prompt_templates(project="my-project")

# Print template names
for template in templates:
    print(f"Template: {template.name}")

Deleting Prompt Templates

To delete a prompt template:

from galileo.prompts import delete_prompt_template

# Delete a prompt template
delete_prompt_template(
    project="my-project",
    name="storyteller-prompt"
)

Best Practices

When working with prompt templates:

  1. Use descriptive names that reflect the template’s purpose
  2. Include clear system messages to set context
  3. Document any required input variables
  4. Version your templates appropriately
  5. Test templates with various inputs before using in production