DSPy: The framework for programming—not prompting—language models
Python
PR Cleaining
Isaac Millerb44de8807570
diff --git a/dspy/__init__.py b/dspy/__init__.pyindex 0ffd7b81c..3f27611bf 100644--- a/dspy/__init__.py+++ b/dspy/__init__.py@@ -13,10 +13,6 @@ from dspy.evaluate import Evaluate # isort: skipfrom dspy.clients import * # isort: skipfrom dspy.adapters import * # isort: skip-from . import evaluate--from . import evaluate-settings = dsp.settings# LM = dsp.LM@@ -59,9 +55,6 @@ AWSMeta = dsp.AWSMetaWatsonx = dsp.WatsonxPremAI = dsp.PremAI-# VLLMOfflineEngine = dsp.VLLMOfflineEngine-# VLLMOfflineEngine2 = dsp.VLLMOfflineEngine2-# VLLMOfflineEngine3 = dsp.VLLMOfflineEngine3You = dsp.Youconfigure = settings.configurediff --git a/dspy/datasets/hotpotqa.py b/dspy/datasets/hotpotqa.pyindex 04684ac57..89d5ed221 100644--- a/dspy/datasets/hotpotqa.py+++ b/dspy/datasets/hotpotqa.py@@ -11,8 +11,8 @@ class HotPotQA(Dataset):assert only_hard_examples, "Care must be taken when adding support for easy examples." \"Dev must be all hard to match official dev, but training can be flexible."- hf_official_train = load_dataset("hotpot_qa", 'fullwiki', split='train')- hf_official_dev = load_dataset("hotpot_qa", 'fullwiki', split='validation')+ hf_official_train = load_dataset("hotpot_qa", 'fullwiki', split='train', trust_remote_code=True)+ hf_official_dev = load_dataset("hotpot_qa", 'fullwiki', split='validation', trust_remote_code=True)official_train = []for raw_example in hf_official_train:diff --git a/dspy/predict/predict.py b/dspy/predict/predict.pyindex 906ea76e8..88a74861a 100644--- a/dspy/predict/predict.py+++ b/dspy/predict/predict.py@@ -1,11 +1,12 @@+from __future__ import annotations # Used for self type hintsimport random+from typing import Optionalfrom pydantic import BaseModelimport dspfrom dspy.predict.parameter import Parameterfrom dspy.primitives.program import Module-from dspy.primitives.prediction import Predictionfrom dspy.signatures.signature import ensure_signature, signature_to_template@@ -17,6 +18,35 @@ def warn_once(msg: str):logging.warning(msg)+#-------------------------------------------------------------------------------+# Helper functions+#-------------------------------------------------------------------------------++def assert_structural_equivalency_for_predictors(+ predictor1: object,+ predictor2: object,+ ) -> Optional[AssertionError]:+ """Assert that the two predictors are structurally equivalent to each other.++ Args:+ predictor1: The predictor to compare with.+ predictor2: The predictor to compare with.++ Raises:+ AssertionError: If the predictors are not structurally equivalent.+ """+ # Assert that the objects are predictors+ assert isinstance(predictor1, Predict)+ assert isinstance(predictor2, Predict)++ # Assert that the predictors have equivalent signatures+ assert predictor1.signature.equals(predictor2.signature)+++#-------------------------------------------------------------------------------+# Classes+#-------------------------------------------------------------------------------+class Predict(Module, Parameter):def __init__(self, signature, _parse_values=True, **config):self.stage = random.randbytes(8).hex()@@ -109,7 +139,6 @@ class Predict(Module, Parameter):# Get the right LM to use.lm = kwargs.pop("lm", self.lm) or dsp.settings.lm- # print(dsp.settings)assert lm is not None, "No LM is loaded."# If temperature is 0.0 but its n > 1, set temperature to 0.7.@@ -238,4 +267,4 @@ def v2_5_generate(lm, lm_kwargs, signature, demos, inputs, _parse_values=True):# # TODO: FIXME: Hmm, I guess expected behavior is that contexts can# affect execution. Well, we need to determine whether context dominates, __init__ demoninates, or forward dominates.# Generally, unless overwritten, we'd see n=None, temperature=None.-# That will eventually mean we have to learn them.\ No newline at end of file+# That will eventually mean we have to learn them.