Skip to content

armgit / dspy

Public Imported from GitHub
0

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.py
index 1bd85b05e..493fdfdce 100644
--- a/dspy/propose/grounded_proposer.py
+++ b/dspy/propose/grounded_proposer.py
@@ -1,5 +1,4 @@
import random
-import re
import dspy
from dspy.propose.dataset_summary_generator import create_dataset_summary
diff --git a/dspy/teleprompt/mipro_optimizer_v2.py b/dspy/teleprompt/mipro_optimizer_v2.py
index 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 pickle
import random
import sys
import 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 trial
optuna.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.py
index 7973f9b89..ebcabe229 100644
--- a/dspy/teleprompt/utils.py
+++ b/dspy/teleprompt/utils.py
@@ -15,7 +15,6 @@ except ImportError:
extract_symbols = None
import dspy
-from dspy.predict.parameter import Parameter
from dspy.teleprompt.bootstrap import BootstrapFewShot, LabeledFewShot
"""
diff --git a/examples/coding/hackercup.py b/examples/coding/hackercup.py
index 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, Optional
import os
import openai
import dspy
from dspy import InputField, OutputField, Signature
-from dspy.functional import TypedPredictor
-import pydantic
from dspy import Example
from dspy.evaluate.evaluate import Evaluate
from dspy.teleprompt.random_search import BootstrapFewShotWithRandomSearch
-import re
-import traceback
from datetime import datetime
import random
from dspy.teleprompt import MIPROv2
from hackercup_utils import extract_code, run, check_solution
-from datetime import datetime
openai.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.py
index bb192f8a9..ec443dfd7 100644
--- a/examples/coding/hackercup_utils.py
+++ b/examples/coding/hackercup_utils.py
@@ -2,7 +2,7 @@ import re
import asyncio
import multiprocessing
import 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}