Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dspy/adapters/chat_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
5 changes: 2 additions & 3 deletions dspy/adapters/json_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions dspy/predict/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", " ")
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion dspy/teleprompt/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading