Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Add `metric_threshold` argument to BootstrapFewShot

Connor Shorten68fe0644a014
diff --git a/dspy/teleprompt/bootstrap.py b/dspy/teleprompt/bootstrap.py
index b885bea0f..92e0e7be7 100644
--- a/dspy/teleprompt/bootstrap.py
+++ b/dspy/teleprompt/bootstrap.py
@@ -34,8 +34,9 @@ from dspy.evaluate.evaluate import Evaluate
class BootstrapFewShot(Teleprompter):
- def __init__(self, metric=None, teacher_settings={}, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=5):
+ def __init__(self, metric=None, metric_threshold=None, teacher_settings={}, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=5):
self.metric = metric
+ self.metric_threshold = metric_threshold
self.teacher_settings = teacher_settings
self.max_bootstrapped_demos = max_bootstrapped_demos
@@ -147,8 +148,11 @@ class BootstrapFewShot(Teleprompter):
for name, predictor in teacher.named_predictors():
predictor.demos = predictor_cache[name]
-
- success = (self.metric is None) or self.metric(example, prediction, trace)
+
+ if self.metric and self.metric_threshold:
+ success = self.metric(example, prediction, trace) > self.metric_threshold
+ else:
+ success = True
# print(success, example, prediction)
except Exception as e:
success = False