@@ -8,32 +8,23 @@ The constructor initializes the `ChainOfThoughtWithHint` class and sets up its a
88class ChainOfThoughtWithHint (Predict ):
99 def __init__ (self , signature , rationale_type = None , activated = True , ** config ):
1010 super ().__init__ (signature, ** config)
11-
1211 self .activated = activated
13-
1412 signature = self .signature
15- * keys, last_key = signature.kwargs.keys()
16-
17- DEFAULT_HINT_TYPE = dsp.Type(prefix = " Hint:" , desc = " ${hint} " )
18-
19- DEFAULT_RATIONALE_TYPE = dsp.Type(prefix = " Reasoning: Let's think step by step in order to" ,
20- desc = " ${produce the " + last_key + " }. We ..." )
2113
22- rationale_type = rationale_type or DEFAULT_RATIONALE_TYPE
23-
24- extended_kwargs1 = {key: signature.kwargs[key] for key in keys}
25- extended_kwargs1.update({' rationale' : rationale_type, last_key: signature.kwargs[last_key]})
14+ * keys, last_key = signature.fields.keys()
15+ rationale_type = rationale_type or dspy.OutputField(
16+ prefix = " Reasoning: Let's think step by step in order to" ,
17+ desc = " ${produce the " + last_key + " }. We ..." ,
18+ )
19+ self .extended_signature1 = self .signature.insert(- 2 , " rationale" , rationale_type, type_ = str )
2620
27- extended_kwargs2 = {key: signature.kwargs[key] for key in keys}
28- extended_kwargs2.update({' hint' : DEFAULT_HINT_TYPE , ' rationale' : rationale_type, last_key: signature.kwargs[last_key]})
29-
30- self .extended_signature1 = dsp.Template(signature.instructions, ** extended_kwargs1)
31- self .extended_signature2 = dsp.Template(signature.instructions, ** extended_kwargs2)
21+ DEFAULT_HINT_TYPE = dspy.OutputField()
22+ self .extended_signature2 = self .extended_signature1.insert(- 2 , " hint" , DEFAULT_HINT_TYPE , type_ = str )
3223```
3324
3425** Parameters:**
3526- ` signature ` (_ Any_ ): Signature of predictive model.
36- - ` rationale_type ` (_ dsp.Type _ , _ optional_ ): Rationale type for reasoning steps. Defaults to ` None ` .
27+ - ` rationale_type ` (_ dsp.OutputField _ , _ optional_ ): Rationale type for reasoning steps. Defaults to ` None ` .
3728- ` activated ` (_ bool_ , _ optional_ ): Flag for activated chain of thought processing. Defaults to ` True ` .
3829- ` **config ` (_ dict_ ): Additional configuration parameters for model.
3930
0 commit comments