Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

Copy edits

dilara25f04c180643
diff --git a/dspy/clients/finetune.py b/dspy/clients/finetune.py
index 0acaa4bb4..a6e6e0005 100644
--- a/dspy/clients/finetune.py
+++ b/dspy/clients/finetune.py
@@ -15,8 +15,6 @@ from dspy import logger
def get_finetune_directory() -> str:
"""Get the directory to save the fine-tuned models."""
alternative_path = os.path.join(os.getcwd(), '.dspy_finetune')
- # TODO: Should the parent directory be different than those used for
- # inference
return os.environ.get('DSPY_FINETUNEDIR') or alternative_path
@@ -105,14 +103,14 @@ def validate_finetune_data(
def save_data(
- data: Any,
- provider: Optional[str]=None,
+ data: List[Dict[str, Any]],
+ provider_name: Optional[str]=None,
) -> str:
"""Save the fine-tuning data to a file."""
# Construct the file name based on the data hash
hash = Hasher.hash(data)
file_name = f"{hash}.jsonl"
- file_name = f"{provider}_{file_name}" if provider else file_name
+ file_name = f"{provider_name}_{file_name}" if provider_name else file_name
# Find the directory to save the fine-tuning data
finetune_parent_dir = get_finetune_directory()
diff --git a/dspy/clients/lm.py b/dspy/clients/lm.py
index 2c35cadd8..b72fc41f7 100644
--- a/dspy/clients/lm.py
+++ b/dspy/clients/lm.py
@@ -56,6 +56,7 @@ class LM:
launch_kwargs=None,
**kwargs
):
+ # Remember to update LM.copy() if you modify the constructor!
self.model = model
self.model_type = model_type
self.cache = cache
@@ -140,7 +141,7 @@ class LM:
# Get the fine-tuning provider, if it is supported
try:
provider = _get_supported_finetune_provider(self.model)
- except ValueError as err:
+ except Exception as err:
raise err
# Initialize the finetune job
@@ -299,12 +300,8 @@ def execute_finetune_job(
cache_finetune: bool=True
):
"""Execute the finetune job in a blocking manner."""
- # Input validation
- launch_kwargs = launch_kwargs or {}
-
- # Execute finetune job
- job_kwargs = job.get_kwargs()
try:
+ job_kwargs = job.get_kwargs()
if cache_finetune:
model = cached_finetune(job=job, **job_kwargs)
else:
diff --git a/dspy/clients/openai.py b/dspy/clients/openai.py
index 5a54604e6..95af1f16f 100644
--- a/dspy/clients/openai.py
+++ b/dspy/clients/openai.py
@@ -152,7 +152,7 @@ def finetune_openai(
# Save to a file
logger.info("[Finetune] Saving the data to a file")
- data_path = save_data(train_data, provider=PROVIDER_OPENAI)
+ data_path = save_data(train_data, provider_name=PROVIDER_OPENAI)
logger.info("[Finetune] Done!")
# Upload the data to the cloud
diff --git a/dspy/teleprompt/finetune_teleprompter.py b/dspy/teleprompt/finetune_teleprompter.py
index 421053073..36544b34d 100644
--- a/dspy/teleprompt/finetune_teleprompter.py
+++ b/dspy/teleprompt/finetune_teleprompter.py
@@ -123,7 +123,7 @@ def build_prompt_completion_data_from_trace(
- The `predictor_name` field corresponds to the index of the predictor
in the list returned by the the named_predictor() method of the
program used to generate the trace. This field is included only if
- the `pred_ind_to_name` argument is provided.
+ the `pred_ind_to_name` argument is provided.
- The `lm_kwargs` field corresponds to the LM kwargs that generated the
prompt-completion pair. Included only if the `record_lm_kwargs` is
set and there is an active LM.
@@ -376,6 +376,7 @@ def bootstrap_data_for_round(
to the dictionaries:
- The `round` field corresponds to the `sampling_round` argument.
"""
+ # TODO: [DSPy 2.5] Migrate to using "seed" for sampling
# Helper function to adjust the temperature of the LM. If a None temperature
# is passed, keep the LM's temperature as is as the base temperature, then
# adjust the temperature for the given round.