Skip to content

Commit 9a31a8f

Browse files
committed
Upgraded to dspy-ai==2.5.7 resolved ValueError via inclusion of basic prompt instruction for critique signature and typed CoT
1 parent 5372949 commit 9a31a8f

File tree

7 files changed

+63624
-501
lines changed

7 files changed

+63624
-501
lines changed

mcts_llm/mctsr.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class CritiqueAnswer(dspy.Signature):
4545

4646

4747
class RefineAnswer(dspy.Signature):
48+
"""[[ ## proposed_instruction ## ]] Given a mathematical problem, a current answer, and a critique of that answer,
49+
refine the current answer to provide a more accurate and well-reasoned solution. Begin by carefully analyzing the
50+
problem and the critique, then think step by step to derive the correct answer. Ensure that your reasoning is clear
51+
and logical, and that the final answer is justified by the steps taken.
52+
53+
[[ ## completed ## ]]
54+
"""
55+
4856
problem: str = dspy.InputField()
4957
current_answer: str = dspy.InputField()
5058
critique: str = dspy.InputField()
@@ -59,7 +67,7 @@ class EvaluateAnswer(dspy.Signature):
5967

6068
class ZeroShotCoT(dspy.Module):
6169
def __init__(self):
62-
self.cot = dspy.ChainOfThought(ZeroShotAnswer)
70+
self.cot = dspy.TypedChainOfThought(ZeroShotAnswer)
6371

6472
def forward(self, problem) -> dspy.Prediction:
6573
return dspy.Prediction(answer=self.cot(problem=problem).answer)
@@ -69,8 +77,8 @@ class MultipleTurnSelfRefine(dspy.Module):
6977
def __init__(self, num_turns: int = 1):
7078
super().__init__()
7179
self.zero_shot_cot = ZeroShotCoT()
72-
self.critique_answer = dspy.ChainOfThought(CritiqueAnswer)
73-
self.refine_answer = dspy.ChainOfThought(RefineAnswer)
80+
self.critique_answer = dspy.TypedChainOfThought(CritiqueAnswer)
81+
self.refine_answer = dspy.TypedChainOfThought(RefineAnswer)
7482
self.num_turns = num_turns
7583

7684
def forward(self, problem) -> dspy.Prediction:
@@ -140,9 +148,9 @@ def __init__(
140148
self.samples_per_node = samples_per_node
141149

142150
self.zero_shot = ZeroShotCoT()
143-
self.critique = dspy.ChainOfThought(CritiqueAnswer)
144-
self.evaluate = dspy.ChainOfThought(EvaluateAnswer)
145-
self.refine = dspy.ChainOfThought(RefineAnswer)
151+
self.critique = dspy.TypedChainOfThought(CritiqueAnswer)
152+
self.evaluate = dspy.TypedChainOfThought(EvaluateAnswer)
153+
self.refine = dspy.TypedChainOfThought(RefineAnswer)
146154

147155
def initialize(self, S: MCTSrState) -> MCTSrNode:
148156
if self.initialize_strategy == InitializeStrategy.ZERO_SHOT:

notebooks/evaluate_qwen25-7b-instruct.ipynb

Lines changed: 1524 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/finetune_qwen25-7b-instruct.ipynb

Lines changed: 60572 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/miprov2_mctsr_qwen25-7b-instruct.json

Lines changed: 444 additions & 0 deletions
Large diffs are not rendered by default.

poetry.lock

Lines changed: 1066 additions & 491 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717

1818
[tool.poetry.dependencies]
1919
python = ">=3.12,<3.13"
20-
dspy-ai = "2.4.17"
20+
dspy-ai = "^2.5.6"
2121
python-dotenv = "^1.0.1"
2222

2323
[tool.poetry.group.dev.dependencies]

tests/test_mctsr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def mock_parse_integer_answer():
2424

2525
@pytest.fixture
2626
def mock_chain_of_thought():
27-
with patch("dspy.ChainOfThought") as mock:
27+
with patch("dspy.TypedChainOfThought") as mock:
2828
mock_instance = Mock()
2929
mock_instance.return_value = Mock(answer="Mocked answer", critique="Mock critique")
3030
mock.return_value = mock_instance
@@ -57,7 +57,7 @@ def mctsr(mock_parse_integer_answer, mock_chain_of_thought):
5757

5858

5959
def test_zero_shot_cot():
60-
with patch("mcts_llm.mctsr.dspy.ChainOfThought") as mock_chain_of_thought:
60+
with patch("mcts_llm.mctsr.dspy.TypedChainOfThought") as mock_chain_of_thought:
6161
mock_cot = Mock()
6262
mock_chain_of_thought.return_value = mock_cot
6363
mock_cot.return_value = dspy.Prediction(answer="Test answer")
@@ -72,7 +72,7 @@ def test_zero_shot_cot():
7272

7373
@pytest.mark.parametrize("num_turns", [1, 3])
7474
def test_multiple_turn_self_refine(num_turns):
75-
with patch("mcts_llm.mctsr.dspy.ChainOfThought") as mock_chain_of_thought:
75+
with patch("mcts_llm.mctsr.dspy.TypedChainOfThought") as mock_chain_of_thought:
7676
mock_zero_shot = Mock()
7777
mock_critique = Mock()
7878
mock_refine = Mock()

0 commit comments

Comments
 (0)