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 import Message, MessageRole
from galileo.prompts import create_prompt_template
# 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:
- Use descriptive names that reflect the template’s purpose
- Include clear system messages to set context
- Document any required input variables
- Version your templates appropriately
- Test templates with various inputs before using in production