DSPy: The framework for programming—not prompting—language models
Python
remove requires_permission_to_run (#8552)
TomuHiratad44b65f70e67
diff --git a/docs/docs/api/optimizers/MIPROv2.md b/docs/docs/api/optimizers/MIPROv2.mdindex 3eedf8e5e..f1ebd22ed 100644--- a/docs/docs/api/optimizers/MIPROv2.md+++ b/docs/docs/api/optimizers/MIPROv2.md@@ -47,7 +47,6 @@ gsm8k = GSM8K()optimized_program = teleprompter.compile(dspy.ChainOfThought("question -> answer"),trainset=gsm8k.train,- requires_permission_to_run=False,)# Save optimize program for future usediff --git a/docs/docs/cheatsheet.md b/docs/docs/cheatsheet.mdindex f445f6d60..34f8a83e1 100644--- a/docs/docs/cheatsheet.md+++ b/docs/docs/cheatsheet.md@@ -307,7 +307,6 @@ optimized_program = teleprompter.compile(trainset=trainset,max_bootstrapped_demos=3,max_labeled_demos=4,- requires_permission_to_run=False,)# Save optimize program for future use@@ -337,7 +336,6 @@ optimized_program = teleprompter.compile(trainset=trainset,max_bootstrapped_demos=0,max_labeled_demos=0,- requires_permission_to_run=False,)# Save optimize program for future usediff --git a/docs/docs/tutorials/entity_extraction/index.ipynb b/docs/docs/tutorials/entity_extraction/index.ipynbindex 8391791c9..f8c5c25f4 100644--- a/docs/docs/tutorials/entity_extraction/index.ipynb+++ b/docs/docs/tutorials/entity_extraction/index.ipynb@@ -567,7 +567,6 @@" people_extractor,\n"," trainset=train_set,\n"," max_bootstrapped_demos=4,\n",- " requires_permission_to_run=False,\n"," minibatch=False\n",")"]diff --git a/docs/docs/tutorials/games/index.ipynb b/docs/docs/tutorials/games/index.ipynbindex 354779924..279d49cf0 100644--- a/docs/docs/tutorials/games/index.ipynb+++ b/docs/docs/tutorials/games/index.ipynb@@ -572,7 +572,7 @@"optimizer = dspy.MIPROv2(metric=metric, auto=\"light\", num_threads=16, prompt_model=gpt4o)\n","\n","config = dict(max_bootstrapped_demos=1, max_labeled_demos=0, minibatch_size=40)\n",- "optimized_4o = optimizer.compile(agent_4o, trainset=trainset, **config, requires_permission_to_run=False)"+ "optimized_4o = optimizer.compile(agent_4o, trainset=trainset, **config)"]},{diff --git a/docs/docs/tutorials/math/index.ipynb b/docs/docs/tutorials/math/index.ipynbindex 10de528de..5a6c3a853 100644--- a/docs/docs/tutorials/math/index.ipynb+++ b/docs/docs/tutorials/math/index.ipynb@@ -414,7 +414,7 @@"kwargs = dict(num_threads=THREADS, teacher_settings=dict(lm=gpt4o), prompt_model=gpt4o_mini)\n","optimizer = dspy.MIPROv2(metric=dataset.metric, auto=\"medium\", **kwargs)\n","\n",- "kwargs = dict(requires_permission_to_run=False, max_bootstrapped_demos=4, max_labeled_demos=4)\n",+ "kwargs = dict(max_bootstrapped_demos=4, max_labeled_demos=4)\n","optimized_module = optimizer.compile(module, trainset=dataset.train, **kwargs)"]},diff --git a/docs/docs/tutorials/multihop_search/index.ipynb b/docs/docs/tutorials/multihop_search/index.ipynbindex 00ed91e82..8f2886948 100644--- a/docs/docs/tutorials/multihop_search/index.ipynb+++ b/docs/docs/tutorials/multihop_search/index.ipynb@@ -574,7 +574,7 @@"models = dict(prompt_model=gpt4o, teacher_settings=dict(lm=gpt4o))\n","tp = dspy.MIPROv2(metric=top5_recall, auto=\"medium\", num_threads=16, **models)\n","\n",- "kwargs = dict(minibatch_size=40, minibatch_full_eval_steps=4, requires_permission_to_run=False)\n",+ "kwargs = dict(minibatch_size=40, minibatch_full_eval_steps=4)\n","optimized = tp.compile(Hop(), trainset=trainset, max_bootstrapped_demos=4, max_labeled_demos=4, **kwargs)"]},diff --git a/docs/docs/tutorials/rag/index.ipynb b/docs/docs/tutorials/rag/index.ipynbindex e97cdf27d..b8ba663ef 100644--- a/docs/docs/tutorials/rag/index.ipynb+++ b/docs/docs/tutorials/rag/index.ipynb@@ -1143,8 +1143,7 @@"tp = dspy.MIPROv2(metric=metric, auto=\"medium\", num_threads=24) # use fewer threads if your rate limit is small\n","\n","optimized_rag = tp.compile(RAG(), trainset=trainset,\n",- " max_bootstrapped_demos=2, max_labeled_demos=2,\n",- " requires_permission_to_run=False)"+ " max_bootstrapped_demos=2, max_labeled_demos=2)"]},{diff --git a/dspy/teleprompt/mipro_optimizer_v2.py b/dspy/teleprompt/mipro_optimizer_v2.pyindex 7dae8bf4f..edb9e4f03 100644--- a/dspy/teleprompt/mipro_optimizer_v2.py+++ b/dspy/teleprompt/mipro_optimizer_v2.py@@ -1,8 +1,5 @@import loggingimport random-import sys-import textwrap-import timefrom collections import defaultdictfrom typing import TYPE_CHECKING, Any, Callable, Literal@@ -112,7 +109,7 @@ class MIPROv2(Teleprompter):view_data_batch_size: int = 10,tip_aware_proposer: bool = True,fewshot_aware_proposer: bool = True,- requires_permission_to_run: bool = True,+ requires_permission_to_run: bool = True, # deprecatedprovide_traceback: bool | None = None,) -> Any:effective_max_errors = (@@ -162,20 +159,6 @@ class MIPROv2(Teleprompter):if minibatch and minibatch_size > len(valset):raise ValueError(f"Minibatch size cannot exceed the size of the valset. Valset size: {len(valset)}.")- # Estimate LM calls and get user confirmation- if requires_permission_to_run:- if not self._get_user_confirmation(- student,- num_trials,- minibatch,- minibatch_size,- minibatch_full_eval_steps,- valset,- program_aware_proposer,- ):- logger.info("Compilation aborted by the user.")- return student # Return the original student program-# Initialize program and evaluatorprogram = student.deepcopy()evaluate = Evaluate(@@ -336,80 +319,6 @@ class MIPROv2(Teleprompter):return prompt_model_line, task_model_line- def _get_user_confirmation(- self,- program: Any,- num_trials: int,- minibatch: bool,- minibatch_size: int,- minibatch_full_eval_steps: int,- valset: list,- program_aware_proposer: bool,- ) -> bool:- prompt_model_line, task_model_line = self._estimate_lm_calls(- program,- num_trials,- minibatch,- minibatch_size,- minibatch_full_eval_steps,- valset,- program_aware_proposer,- )-- user_message = textwrap.dedent(- f"""\- {YELLOW}{BOLD}Projected Language Model (LM) Calls{ENDC}-- Based on the parameters you have set, the maximum number of LM calls is projected as follows:-- {prompt_model_line}- {task_model_line}-- {YELLOW}{BOLD}Estimated Cost Calculation:{ENDC}-- {YELLOW}Total Cost = (Number of calls to task model * (Avg Input Token Length per Call * Task Model Price per Input Token + Avg Output Token Length per Call * Task Model Price per Output Token)- + (Number of program calls * (Avg Input Token Length per Call * Task Prompt Price per Input Token + Avg Output Token Length per Call * Prompt Model Price per Output Token).{ENDC}-- For a preliminary estimate of potential costs, we recommend you perform your own calculations based on the task- and prompt models you intend to use. If the projected costs exceed your budget or expectations, you may consider:-- {YELLOW}- Reducing the number of trials (`num_trials`), the size of the valset, or the number of LM calls in your program.{ENDC}- {YELLOW}- Using a cheaper task model to optimize the prompt.{ENDC}- {YELLOW}- Setting `minibatch=True` if you haven't already.{ENDC}\n"""- )-- user_confirmation_message = textwrap.dedent(- f"""\- To proceed with the execution of this program, please confirm by typing {BLUE}'y'{ENDC} for yes or {BLUE}'n'{ENDC} for no.- If no input is received within 20 seconds, the program will proceed automatically.-- If you would like to bypass this confirmation step in future executions, set the {YELLOW}`requires_permission_to_run`{ENDC} flag to {YELLOW}`False`{ENDC} when calling compile.-- {YELLOW}Awaiting your input...{ENDC}- """- )-- print(f"{user_message}\n{user_confirmation_message}\nDo you wish to continue? (y/n): ", end="", flush=True)-- # Wait for input with timeout- start_time = time.time()- while time.time() - start_time < 20:- if sys.platform == "win32":- import msvcrt- if msvcrt.kbhit():- user_input = msvcrt.getch().decode("utf-8").strip().lower()- print(user_input) # Echo the input- return user_input == "y"- else:- import select- if select.select([sys.stdin], [], [], 0.1)[0]:- user_input = sys.stdin.readline().strip().lower()- return user_input == "y"- time.sleep(0.1)-- print("\nNo input received within 20 seconds. Proceeding with execution...")- return True-def _bootstrap_fewshot_examples(self, program: Any, trainset: list, seed: int, teacher: Any) -> list | None:logger.info("\n==> STEP 1: BOOTSTRAP FEWSHOT EXAMPLES <==")if self.max_bootstrapped_demos > 0: