DSPy: The framework for programming—not prompting—language models
Python
Update random_search.py by moving stop_score after program update
arnavsinghvi11ab8bedc3b078
diff --git a/dspy/teleprompt/random_search.py b/dspy/teleprompt/random_search.pyindex 9aec12612..c2baf3785 100644--- a/dspy/teleprompt/random_search.py+++ b/dspy/teleprompt/random_search.py@@ -100,10 +100,6 @@ class BootstrapFewShotWithRandomSearch(Teleprompter):print(f"Scores so far: {scores}")- if self.stop_at_score is not None and score >= self.stop_at_score:- print(f"Stopping early because score {score} is >= stop_at_score {self.stop_at_score}")- break-if score >= max(scores):print('New best score:', score, 'for seed', seed)best_program = program2@@ -122,6 +118,10 @@ class BootstrapFewShotWithRandomSearch(Teleprompter):print(f'Average of max per entry across top {k} scores: {avg_of_max_per_entry}')+ if self.stop_at_score is not None and score >= self.stop_at_score:+ print(f"Stopping early because score {score} is >= stop_at_score {self.stop_at_score}")+ break+return best_program@@ -129,7 +129,7 @@ class BootstrapFewShotWithRandomSearch(Teleprompter):# sample between 4 and 10 examples from traces# TODO: FIXME: The max number of demos should be determined in part by the LM's tokenizer + max_length.-# This does require excecuting the program, or at least the predictor.+# This does require executing the program, or at least the predictor.# # # # # # (Actually we can just combine the token counts of the traces, when formatted via signature/adapter).# Alternatively, we can keep track of the (zero-shot) number of tokens when we bootstrap.# As another option, we can just try a wide range and handle failures as penalties on the score.