Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Adjust abstract args and fix retrieve

Isaac Millerbed26d951e15
diff --git a/dsp/modules/lm.py b/dsp/modules/lm.py
index 6c4c97dee..7e2626fb5 100644
--- a/dsp/modules/lm.py
+++ b/dsp/modules/lm.py
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
-from typing import Optional
+from typing import Any, Optional
class LM(ABC):
@@ -144,7 +144,7 @@ class LM(ABC):
return self.__class__(model=model, **kwargs)
class FinetuneableLM(LM, ABC):
- def verify_training_arguments(self, training_arguments: dict[str, Any]) -> bool:
+ def verify_training_arguments(self, dataset: dict[str, Any], valset: Optional[dict[str, Any]], training_arguments: dict[str, Any]) -> bool:
return True
@abstractmethod
diff --git a/dsp/modules/openai.py b/dsp/modules/openai.py
index 54235eb8e..a567702d7 100644
--- a/dsp/modules/openai.py
+++ b/dsp/modules/openai.py
@@ -1,3 +1,4 @@
+from copy import deepcopy
from typing import Any, Optional, Literal, Union
import openai
@@ -302,8 +303,6 @@ class OpenAIModel(GPT3, FinetuneableLM):
# probably delete the file after training
def stop_training(self) -> None:
- # TODOSOON: Implement this
-
for file in self.fine_tuning_file_ids.values():
openai.files.delete(file)
@@ -326,8 +325,11 @@ class OpenAIModel(GPT3, FinetuneableLM):
elif temp_job.status == "running":
return False
- def retrieve_trained_model_client(self):
+ def retrieve_trained_model_client(self) -> LM:
assert self.fine_tuning_job_id is not None, "You must start training before retrieving the model"
job = openai.fine_tuning.jobs.retrieve(self.fine_tuning_job_id)
if job.status == "succeeded":
- self.kwargs["model"] = job.fine_tuned_model
+ self_copy = deepcopy(self)
+ self_copy.kwargs["model"] = job.fine_tuned_model
+ return self_copy
+