DSPy: The framework for programming—not prompting—language models
Python
Add Custom Rationale Type option in TypedChainOfThought Module
Herumb Shandilya9b00ba23cf0a
diff --git a/dspy/functional/functional.py b/dspy/functional/functional.pyindex 92f7c5a15..cf2fe6977 100644--- a/dspy/functional/functional.py+++ b/dspy/functional/functional.py@@ -53,17 +53,21 @@ class FunctionalModule(dspy.Module):self.__dict__[name] = attr.copy()-def TypedChainOfThought(signature, instructions=None, *, max_retries=3) -> dspy.Module: # noqa: N802+def TypedChainOfThought(signature, instructions=None, rationale_type=None, *, max_retries=3) -> dspy.Module: # noqa: N802"""Just like TypedPredictor, but adds a ChainOfThought OutputField."""signature = ensure_signature(signature, instructions)output_keys = ", ".join(signature.output_fields.keys())++ DEFAULT_RATIONALE = dspy.OutputField(+ prefix="Rationale: Let's think step by step in order to",+ desc="${produce the " + output_keys + "}. We ...",+ )+ rationale_type = rationale_type or DEFAULT_RATIONALE+return TypedPredictor(signature.prepend("reasoning",- dspy.OutputField(- prefix="Reasoning: Let's think step by step in order to",- desc="${produce the " + output_keys + "}. We ...",- ),+ rationale_type,),max_retries=max_retries,)