DSPy: The framework for programming—not prompting—language models
Python
Smaller changes
Isaac Miller8d246554bb26
diff --git a/dsp/modules/gpt3.py b/dsp/modules/gpt3.pyindex 853cfabbb..024f7192f 100644--- a/dsp/modules/gpt3.py+++ b/dsp/modules/gpt3.py@@ -62,7 +62,7 @@ class GPT3(LM):super().__init__(model)self.provider = "openai"openai.api_type = api_provider- openai.default_headers = default_headers+ openai.default_headers = default_headers or {}self.system_prompt = system_prompt@@ -114,7 +114,7 @@ class GPT3(LM):def basic_request(self, prompt: str, **kwargs):raw_kwargs = kwargs- kwargs = {**(self.kwargs if self.kwargs else {}), **(kwargs if kwargs else {})}+ kwargs = {**self.kwargs, **kwargs}if self.model_type == "chat":# caching mechanism requires hashable kwargsmessages = [{"role": "user", "content": prompt}]diff --git a/dsp/modules/openai.py b/dsp/modules/openai.pyindex a1a3f1cd2..58abb381d 100644--- a/dsp/modules/openai.py+++ b/dsp/modules/openai.py@@ -342,7 +342,7 @@ class OpenAIModel(GPT3, FinetunableLM):try:if method != "SFT":raise NotImplementedError("Only SFT finetuning is supported at the moment.")- # TODO: Data validation+traindataset = ujson.load(open(train_path))valdataset = ujson.load(open(val_path)) if val_path else Noneself.verify_training_arguments(traindataset, valdataset, kwargs)@@ -376,6 +376,8 @@ class OpenAIModel(GPT3, FinetunableLM):**kwargs: Additional arguments to pass to the API provider."""job = openai.fine_tuning.jobs.retrieve(job_id)+ if job.status != "succeeded":+ raise RuntimeError("Job not completed yet, cannot retrieve model")model = OpenAIModel(model=job.fine_tuned_model, **kwargs)model.fine_tuning_job_id = job_idreturn model\ No newline at end of filediff --git a/dspy/teleprompt/random_search.py b/dspy/teleprompt/random_search.pyindex 23e3e03dd..74d5afb12 100644--- a/dspy/teleprompt/random_search.py+++ b/dspy/teleprompt/random_search.py@@ -134,7 +134,7 @@ class BootstrapFewShotWithRandomSearch(Teleprompter):print("Score:", score, "for set:", [len(predictor.demos) for predictor in program2.predictors()])if len(scores) == 0 or score > max(scores):- print("New best sscore:", score, "for seed", seed)+ print("New best score:", score, "for seed", seed)best_program = program2scores.append(score)