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.

Create Prompt Templates

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}}
                """)
    ]
)

Connect Prompt Templates to Dataset Inputs

When you use datasets in Galileo, the attributes stored in the input in your dataset are made available to your prompt templates using mustache templating. This allows you to create dynamic prompts that adapt to the data in each row.

Suppose you have the following dataset:

test_data = [
    { "input": { "city": "Rome, Italy", "days": "5" } },
    { "input": { "city": "Paris, France", "days": "3" } },
]

To reference fields from your dataset in your prompt, use double curly braces:

Message(role=MessageRole.user, 
        content="""
        Plan a {{ days }}-day travel itinerary
        for a trip to {{ city }}.
        """)
  • {{ city }} will be replaced with the value of the city field inside the input dictionary.
  • {{ days }} will be replaced with the value of the days field inside the input dictionary.

Get Prompt Templates

Once prompt templates have been created in Galileo, they can be retrieved by name.

from galileo.prompts import get_prompt_template

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

List 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}")

Delete 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"
)

Use Prompts in Experiments

Prompts can be used in experiments to evaluate different prompt templates:

from galileo.datasets import get_dataset
from galileo.experiments import run_experiment
from galileo.prompts import get_prompt_template
from galileo.schema.metrics import GalileoScorers

# Get an existing dataset
dataset = get_dataset(
    name="countries"
)

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

# Run an experiment with the dataset and prompt
results = run_experiment(
    "geography-experiment",
    dataset=dataset,
    prompt_template=prompt_template,
    metrics=[GalileoScorers.Completeness],
    project="my-project",
)

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

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.

Create Prompt Templates

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}}
                """)
    ]
)

Connect Prompt Templates to Dataset Inputs

When you use datasets in Galileo, the attributes stored in the input in your dataset are made available to your prompt templates using mustache templating. This allows you to create dynamic prompts that adapt to the data in each row.

Suppose you have the following dataset:

test_data = [
    { "input": { "city": "Rome, Italy", "days": "5" } },
    { "input": { "city": "Paris, France", "days": "3" } },
]

To reference fields from your dataset in your prompt, use double curly braces:

Message(role=MessageRole.user, 
        content="""
        Plan a {{ days }}-day travel itinerary
        for a trip to {{ city }}.
        """)
  • {{ city }} will be replaced with the value of the city field inside the input dictionary.
  • {{ days }} will be replaced with the value of the days field inside the input dictionary.

Get Prompt Templates

Once prompt templates have been created in Galileo, they can be retrieved by name.

from galileo.prompts import get_prompt_template

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

List 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}")

Delete 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"
)

Use Prompts in Experiments

Prompts can be used in experiments to evaluate different prompt templates:

from galileo.datasets import get_dataset
from galileo.experiments import run_experiment
from galileo.prompts import get_prompt_template
from galileo.schema.metrics import GalileoScorers

# Get an existing dataset
dataset = get_dataset(
    name="countries"
)

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

# Run an experiment with the dataset and prompt
results = run_experiment(
    "geography-experiment",
    dataset=dataset,
    prompt_template=prompt_template,
    metrics=[GalileoScorers.Completeness],
    project="my-project",
)

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