Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

minor fixes

manishshettym94fcb74c3092
diff --git a/dspy/predict/retry.py b/dspy/predict/retry.py
index 55a0ad8f8..a4ffaa46b 100644
--- a/dspy/predict/retry.py
+++ b/dspy/predict/retry.py
@@ -18,9 +18,7 @@ class Retry(Predict):
modified_output_fields = {}
for key, value in output_fields.items():
modified_output_fields[f"past_{key}"] = dspy.OutputField(
- prefix='Past ' + value.prefix,
- desc=value.desc,
- format=value.format
+ prefix="Past " + value.prefix, desc=value.desc, format=value.format
)
extended_signature.update(input_fields)
extended_signature.update(modified_output_fields)
@@ -37,5 +35,5 @@ class Retry(Predict):
return extended_signature
def forward(self, *args, **kwargs):
- kwargs['signature'] = self.new_signature
+ kwargs["signature"] = self.new_signature
return self.module.forward(**kwargs)
diff --git a/dspy/primitives/assertions.py b/dspy/primitives/assertions.py
index 86e4689fe..0c741bfbd 100644
--- a/dspy/primitives/assertions.py
+++ b/dspy/primitives/assertions.py
@@ -35,14 +35,13 @@ def _build_error_msg(feedback_msgs):
def _build_trace_passages(failure_traces):
"""Build a list of trace passages from a list of failure traces."""
+ trace_template = """Failed Instruction: {} | Output: {}"""
+ trace_passages = []
- # print("Traces:")
- # for id, (ip, op, msg) in failure_traces.items():
- # print(id, op, msg)
- # print()
+ for id, (ip, op, msg) in failure_traces.items():
+ trace_passages.append(trace_template.format(msg, op))
- # TODO complete this
- return failure_traces
+ return trace_passages
def _extend_predictor_signature(predictor, **kwargs):
@@ -236,14 +235,16 @@ def suggest_backtrack_handler(func, max_backtracks=10, **handler_args):
predictors_to_original_forward[backtrack_to] = backtrack_to.forward
# set the new fields
- #TODO some handling of the past_outputs fields within Retry module?
+ # TODO some handling of the past_outputs fields within Retry module?
feedback_msg = _build_error_msg(predictor_feedbacks[backtrack_to])
trace_passages = _build_trace_passages(failure_traces[backtrack_to])
kwargs["feedback"] = feedback_msg
kwargs["traces"] = trace_passages
# TODO: verify if this correctly - replace backtrack_to.forward in the user's program with retry_module.forward
- func = retry_module.forward.__get__(backtrack_to, backtrack_to.__class__)
+ func = retry_module.forward.__get__(
+ backtrack_to, backtrack_to.__class__
+ )
# setattr(backtrack_to, 'forward', func)
# NOTE: this replacement needs to be thread safe if possible
@@ -300,7 +301,7 @@ def suggest_backtrack_handler(func, max_backtracks=10, **handler_args):
if predictors_to_original_forward:
for predictor, original_forward in predictors_to_original_forward.items():
_revert_predictor_signature(predictor, "feedback")
- setattr(predictor, 'forward', original_forward.__get__(predictor))
+ setattr(predictor, "forward", original_forward.__get__(predictor))
return result
@@ -345,4 +346,4 @@ def assert_transform_module(
module
)
- return module
\ No newline at end of file
+ return module