Learn how to create and use prompt templates in experiments
Prompts 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.
from galileo import Message, MessageRolefrom galileo.prompts import create_prompt# Create a prompt with system and user messagesprompt = create_prompt( name="storyteller-prompt", template=[ 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}} """) ])
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:
from galileo.prompts import get_prompts# List all prompt templates in a projecttemplates = get_prompts()# Print template namesfor template in templates: print(f"Template: {template.name}")
Prompts can be used in experiments to evaluate different prompt templates:
Copy
Ask AI
from galileo.datasets import get_datasetfrom galileo.experiments import run_experimentfrom galileo.prompts import get_promptfrom galileo.schema.metrics import GalileoScorers# Get an existing datasetdataset = get_dataset( name="countries")# Get an existing prompt prompt = get_prompt( name="geography-prompt")# Run an experiment with the dataset and promptresults = run_experiment( "geography-experiment", dataset=dataset, prompt_template=prompt, metrics=[GalileoScorers.completeness], project="my-project",)