from dspy.teleprompt import BootstrapFewShotWithRandomSearch # Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 8-shot examples of our CoT program. # The optimizer will repeat this 10 times (plus some initial attempts) before selecting its best attempt on the devset. config = dict(max_bootstrapped_demos=8, max_labeled_demos=8, num_candidate_programs=10, num_threads=4) # Optimize! Use the `gms8k_metric` here. In general, the metric is going to tell the optimizer how well it's doing. teleprompter = BootstrapFewShotWithRandomSearch(metric=gsm8k_metric, **config) optimized_cot = teleprompter.compile(CoT(), trainset=trainset, valset=devset)