Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

fix(adapters): accept main_request in TwoStepAdapter.format_user_message_content (#10628)

Isaac Miller2cd502ada038
diff --git a/dspy/adapters/two_step_adapter.py b/dspy/adapters/two_step_adapter.py
index 1ce1f4e88..40ef22ecf 100644
--- a/dspy/adapters/two_step_adapter.py
+++ b/dspy/adapters/two_step_adapter.py
@@ -194,7 +194,10 @@ class TwoStepAdapter(Adapter):
inputs: dict[str, Any],
prefix: str = "",
suffix: str = "",
+ main_request: bool = False,
) -> str:
+ # `main_request` is accepted for compatibility with the base Adapter contract; the first-stage prompt has no
+ # output-format reminder to add.
parts = [prefix]
for name in signature.input_fields.keys():
diff --git a/tests/adapters/test_two_step_adapter.py b/tests/adapters/test_two_step_adapter.py
index 3ae99e222..4d4abc47a 100644
--- a/tests/adapters/test_two_step_adapter.py
+++ b/tests/adapters/test_two_step_adapter.py
@@ -31,6 +31,23 @@ def test_two_step_adapter_format_exact_messages_for_simple_signature_with_demo()
assert lm_kwargs == expected_lm_kwargs
+def test_two_step_adapter_format_conversation_history():
+ class QA(dspy.Signature):
+ question: str = dspy.InputField()
+ answer: str = dspy.OutputField()
+
+ adapter = dspy.TwoStepAdapter(dspy.utils.DummyLM([{"answer": "x"}]))
+ history = dspy.History(messages=[{"question": "Q1", "answer": "A1"}, {"answer": "A2"}])
+
+ messages = adapter.format_conversation_history(QA, "history", {"question": "Q3", "history": history})
+
+ assert messages == [
+ {"role": "user", "content": "question: Q1"},
+ {"role": "assistant", "content": "answer: A1"},
+ {"role": "assistant", "content": "answer: A2"},
+ ]
+
+
def test_two_step_adapter_format_exact_messages_with_typed_outputs():
class TypedSignature(dspy.Signature):
question: str = dspy.InputField()