diff --git a/dspy/adapters/chat_adapter.py b/dspy/adapters/chat_adapter.py index 81e037c576..8d73b6d3f3 100644 --- a/dspy/adapters/chat_adapter.py +++ b/dspy/adapters/chat_adapter.py @@ -86,7 +86,7 @@ def parse(self, signature, completion, _parse_values=True): def format_turn(self, signature, values, role, incomplete=False): return format_turn(signature, values, role, incomplete) - def format_fields(self, signature, values): + def format_fields(self, signature, values, role): fields_with_values = { FieldInfoWithName(name=field_name, info=field_info): values.get( field_name, "Not supplied for this particular example." diff --git a/dspy/adapters/json_adapter.py b/dspy/adapters/json_adapter.py index f319d40fec..a1b1bedd34 100644 --- a/dspy/adapters/json_adapter.py +++ b/dspy/adapters/json_adapter.py @@ -90,7 +90,7 @@ def parse(self, signature, completion, _parse_values=True): def format_turn(self, signature, values, role, incomplete=False): return format_turn(signature, values, role, incomplete) - def format_fields(self, signature, values): + def format_fields(self, signature, values, role): fields_with_values = { FieldInfoWithName(name=field_name, info=field_info): values.get( field_name, "Not supplied for this particular example." @@ -99,8 +99,7 @@ def format_fields(self, signature, values): if field_name in values } - return format_fields(role='user', fields_with_values=fields_with_values) - + return format_fields(role=role, fields_with_values=fields_with_values) def parse_value(value, annotation): diff --git a/dspy/predict/react.py b/dspy/predict/react.py index 2095d9ba6e..a26f538f0b 100644 --- a/dspy/predict/react.py +++ b/dspy/predict/react.py @@ -47,7 +47,7 @@ def __init__(self, signature, tools: list[Callable], max_iters=5): finish_desc = f"Signals that the final outputs, i.e. {outputs_}, are now available and marks the task as complete." finish_args = {} #k: v.annotation for k, v in signature.output_fields.items()} - tools["finish"] = Tool(func=lambda **kwargs: kwargs, name="finish", desc=finish_desc, args=finish_args) + tools["finish"] = Tool(func=lambda **kwargs: "Completed.", name="finish", desc=finish_desc, args=finish_args) for idx, tool in enumerate(tools.values()): desc = tool.desc.replace("\n", " ") @@ -77,10 +77,8 @@ def forward(self, **input_args): def format(trajectory_: dict[str, Any], last_iteration: bool): adapter = dspy.settings.adapter or dspy.ChatAdapter() - blob = adapter.format_fields(dspy.Signature(f"{', '.join(trajectory_.keys())} -> x"), trajectory_) - warning = f"\n\nWarning: The maximum number of iterations ({self.max_iters}) has been reached." - warning += " You must now produce the finish action." - return blob + (warning if last_iteration else "") + signature_ = dspy.Signature(f"{', '.join(trajectory_.keys())} -> x") + return adapter.format_fields(signature_, trajectory_, role='user') for idx in range(self.max_iters): pred = self.react(**input_args, trajectory=format(trajectory, last_iteration=(idx == self.max_iters-1))) diff --git a/dspy/teleprompt/bootstrap.py b/dspy/teleprompt/bootstrap.py index d6787cc628..b172448288 100644 --- a/dspy/teleprompt/bootstrap.py +++ b/dspy/teleprompt/bootstrap.py @@ -150,7 +150,7 @@ def _bootstrap(self, *, max_bootstraps=None): for round_idx in range(self.max_rounds): bootstrap_attempts += 1 - if success := self._bootstrap_one_example(example, round_idx): + if self._bootstrap_one_example(example, round_idx): bootstrapped[example_idx] = True break