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
9 changes: 7 additions & 2 deletions dspy/predict/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ def __init__(self, signature, max_iters=5, num_results=3, tools=None):
inputs_ = ", ".join([f"`{k}`" for k in self.input_fields.keys()])
outputs_ = ", ".join([f"`{k}`" for k in self.output_fields.keys()])

instr = [
instr = []

if self.signature.instructions is not None:
instr.append(f"{self.signature.instructions}\n")

instr.extend([
f"You will be given {inputs_} and you will respond with {outputs_}.\n",
"To do this, you will interleave Thought, Action, and Observation steps.\n",
"Thought can reason about the current situation, and Action can be the following types:\n",
]
])

self.tools["Finish"] = dspy.Example(
name="Finish",
Expand Down
13 changes: 13 additions & 0 deletions tests/predict/test_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ def test_custom_tools():
"Thought 3: Even more thoughts\n\n"
"Action 3: Finish[baz]"
)


def test_signature_instructions():
class ExampleSignature(dspy.Signature):
"""You are going to generate output based on input."""

input = dspy.InputField()
output = dspy.OutputField()

react = dspy.ReAct(ExampleSignature)

assert react.react[0].signature.instructions is not None
assert react.react[0].signature.instructions.startswith("You are going to generate output based on input.")