DSPy: The framework for programming—not prompting—language models
Python
linter fixes
Michael Ryanbf68f64e0189
diff --git a/dspy/propose/grounded_proposer.py b/dspy/propose/grounded_proposer.pyindex 1bd85b05e..493fdfdce 100644--- a/dspy/propose/grounded_proposer.py+++ b/dspy/propose/grounded_proposer.py@@ -1,5 +1,4 @@import random-import reimport dspyfrom dspy.propose.dataset_summary_generator import create_dataset_summarydiff --git a/dspy/teleprompt/mipro_optimizer_v2.py b/dspy/teleprompt/mipro_optimizer_v2.pyindex 49edca7c7..ab758f7e6 100644--- a/dspy/teleprompt/mipro_optimizer_v2.py+++ b/dspy/teleprompt/mipro_optimizer_v2.py@@ -1,6 +1,3 @@-import logging-import os-import pickleimport randomimport sysimport textwrap@@ -21,7 +18,6 @@ from dspy.teleprompt.utils import (get_task_model_history_for_full_example,print_full_program,save_candidate_program,- save_file_to_log_dir,set_signature,)@@ -236,12 +232,12 @@ class MIPROv2(Teleprompter):max_labeled_demos_for_candidate_gen = max_labeled_demos# Generate N few shot example sets (these will inform instruction creation, and be used as few-shot examples in our prompt)- print(f"Beginning MIPROv2 optimization process...")- print(f"\n==> STEP 1: BOOTSTRAP FEWSHOT EXAMPLES <==")+ print("Beginning MIPROv2 optimization process...")+ print("\n==> STEP 1: BOOTSTRAP FEWSHOT EXAMPLES <==")if max_bootstrapped_demos > 0:- print(f"These will be used for as few-shot examples candidates for our program and for creating instructions.\n")+ print("These will be used for as few-shot examples candidates for our program and for creating instructions.\n")else:- print(f"These will be used for informing instruction proposal.\n")+ print("These will be used for informing instruction proposal.\n")print(f"Bootstrapping N={self.num_candidates} sets of demonstrations...")try:demo_candidates = create_n_fewshot_demo_sets(@@ -487,7 +483,7 @@ class MIPROv2(Teleprompter):# Run the trialoptuna.logging.set_verbosity(optuna.logging.WARNING)- print(f"==> STEP 3: FINDING OPTIMAL PROMPT PARAMETERS <==")+ print("==> STEP 3: FINDING OPTIMAL PROMPT PARAMETERS <==")print("In this step, we will evaluate the program over a series of trials with different combinations of instructions and few-shot examples to find the optimal combination. Bayesian Optimization will be used for this search process.\n")objective_function = create_objective(program, instruction_candidates, demo_candidates, evaluate, valset,diff --git a/dspy/teleprompt/utils.py b/dspy/teleprompt/utils.pyindex 7973f9b89..ebcabe229 100644--- a/dspy/teleprompt/utils.py+++ b/dspy/teleprompt/utils.py@@ -15,7 +15,6 @@ except ImportError:extract_symbols = Noneimport dspy-from dspy.predict.parameter import Parameterfrom dspy.teleprompt.bootstrap import BootstrapFewShot, LabeledFewShot"""diff --git a/examples/coding/hackercup.py b/examples/coding/hackercup.pyindex 9bb2e55a8..a7e5e29b5 100644--- a/examples/coding/hackercup.py+++ b/examples/coding/hackercup.py@@ -1,23 +1,15 @@import datasets-import time-import asyncio-from typing import List, Optionalimport osimport openaiimport dspyfrom dspy import InputField, OutputField, Signature-from dspy.functional import TypedPredictor-import pydanticfrom dspy import Examplefrom dspy.evaluate.evaluate import Evaluatefrom dspy.teleprompt.random_search import BootstrapFewShotWithRandomSearch-import re-import tracebackfrom datetime import datetimeimport randomfrom dspy.teleprompt import MIPROv2from hackercup_utils import extract_code, run, check_solution-from datetime import datetimeopenai.api_key = os.environ.get("OPENAI_API_KEY")openai.api_base = os.environ.get("OPENAI_API_BASE")@@ -290,12 +282,12 @@ if __name__ == "__main__":# Try out a simple program (7.5% on 40 ex)simple_program = SimpleGenerateCode()- print(f"Evaluating Simple Program on test...")+ print("Evaluating Simple Program on test...")evaluate(program=simple_program, devset=testset)# Try out more advanced pipeline | ~25%multi_stage_program = GenerateCode(max_tries=3, num_ensembles=3)- print(f"Evaluating Multi-Stage Program on test...")+ print("Evaluating Multi-Stage Program on test...")evaluate(program=multi_stage_program, devset=testset)# Try out more advanced pipeline | ~30%diff --git a/examples/coding/hackercup_utils.py b/examples/coding/hackercup_utils.pyindex bb192f8a9..ec443dfd7 100644--- a/examples/coding/hackercup_utils.py+++ b/examples/coding/hackercup_utils.py@@ -2,7 +2,7 @@ import reimport asyncioimport multiprocessingimport concurrent.futures-from typing import List, Optional+from typing import Optional"""Note that this code is largely based off of the code here:@@ -91,7 +91,7 @@ async def arun(return {"error": f"Function call timed out after {timeout} seconds","result": None,- "stack_trace": f"Function call timed out. Code needs to be more efficient.",+ "stack_trace": "Function call timed out. Code needs to be more efficient.",}except Exception as e:return {"error": str(e), "result": None}