Prompt Optimization
Quickstart
Quickstart guide to get your first prompt optimized.
Set up the base prompt
ape-common
provides a Prompt
class to help you manage your prompt templates. Prompt
objects can be instantiated with a dictionary or loaded from a .prompt
file. It is also a functor class, which means it can be called like a function to run the prompt with any inputs. (read more about it here).
Provide training data
The trainset
will be used to evaluate the performance of prompts while Ape is writing new prompts. It will also be used to pick few-shot examples for the prompts.
Set up the evaluation metric
You can define your own evaluation metric by subclassing BaseMetric
and implementing the compute
method. You can also use predefined metrics: JsonMatchMetric
, CosineSimilarityMetric
, and SemanticF1Metric
.
Run the optimization
from weavel import Weavel
from ape.common.metrics import JsonMatchMetric
wv = Weavel()
optimized_prompt = await wv.optimize(
base_prompt=base_prompt,
models=["claude-3-5-sonnet-20240620", "gpt-4o"],
metric=JsonMatchMetric(),
trainset=trainset,
)