DSPy: The framework for programming—not prompting—language models
Python
fix rational type in the api documentation.
habanozbd2bbd79802a
diff --git a/docs/api/modules/ChainOfThought.md b/docs/api/modules/ChainOfThought.mdindex ab9bd0e5f..1c73657b1 100644--- a/docs/api/modules/ChainOfThought.md+++ b/docs/api/modules/ChainOfThought.md@@ -13,23 +13,20 @@ class ChainOfThought(Predict):self.activated = activated- signature = self.signature- *keys, last_key = signature.kwargs.keys()-- DEFAULT_RATIONALE_TYPE = dsp.Type(prefix="Reasoning: Let's think step by step in order to",- desc="${produce the " + last_key + "}. We ...")-- rationale_type = rationale_type or DEFAULT_RATIONALE_TYPE-- extended_kwargs = {key: signature.kwargs[key] for key in keys}- extended_kwargs.update({'rationale': rationale_type, last_key: signature.kwargs[last_key]})-- self.extended_signature = dsp.Template(signature.instructions, **extended_kwargs)+ signature = ensure_signature(self.signature)+ *_keys, last_key = signature.output_fields.keys()++ rationale_type = rationale_type or dspy.OutputField(+ prefix="Reasoning: Let's think step by step in order to",+ desc="${produce the " + last_key + "}. We ...",+ )++ self.extended_signature = signature.prepend("rationale", rationale_type, type_=str)```**Parameters:**- `signature` (_Any_): Signature of predictive model.-- `rationale_type` (_dsp.Type_, _optional_): Rationale type for reasoning steps. Defaults to `None`.+- `rationale_type` (_dsp.OutputField_, _optional_): Rationale type for reasoning steps. Defaults to `None`.- `activated` (_bool_, _optional_): Flag for activated chain of thought processing. Defaults to `True`.- `**config` (_dict_): Additional configuration parameters for model.@@ -64,3 +61,15 @@ pred = generate_answer(question=question)print(f"Question: {question}")print(f"Predicted Answer: {pred.answer}")```++The following example shows how to specify your custom rationale.++```python+#define a custom rationale+rationale_type = dspy.OutputField(+ prefix="Reasoning: Let's think step by step in order to",+ desc="${produce the answer}. We ...",+ )+#Pass signature to ChainOfThought module+generate_answer = dspy.ChainOfThought(BasicQA, rationale_type=rationale_type)+```\ No newline at end of filediff --git a/docs/api/modules/ChainOfThoughtWithHint.md b/docs/api/modules/ChainOfThoughtWithHint.mdindex 1b4b964e7..5236b5156 100644--- a/docs/api/modules/ChainOfThoughtWithHint.md+++ b/docs/api/modules/ChainOfThoughtWithHint.md@@ -8,32 +8,23 @@ The constructor initializes the `ChainOfThoughtWithHint` class and sets up its aclass ChainOfThoughtWithHint(Predict):def __init__(self, signature, rationale_type=None, activated=True, **config):super().__init__(signature, **config)-self.activated = activated-signature = self.signature- *keys, last_key = signature.kwargs.keys()-- DEFAULT_HINT_TYPE = dsp.Type(prefix="Hint:", desc="${hint}")-- DEFAULT_RATIONALE_TYPE = dsp.Type(prefix="Reasoning: Let's think step by step in order to",- desc="${produce the " + last_key + "}. We ...")- rationale_type = rationale_type or DEFAULT_RATIONALE_TYPE-- extended_kwargs1 = {key: signature.kwargs[key] for key in keys}- extended_kwargs1.update({'rationale': rationale_type, last_key: signature.kwargs[last_key]})+ *keys, last_key = signature.fields.keys()+ rationale_type = rationale_type or dspy.OutputField(+ prefix="Reasoning: Let's think step by step in order to",+ desc="${produce the " + last_key + "}. We ...",+ )+ self.extended_signature1 = self.signature.insert(-2, "rationale", rationale_type, type_=str)- extended_kwargs2 = {key: signature.kwargs[key] for key in keys}- extended_kwargs2.update({'hint': DEFAULT_HINT_TYPE, 'rationale': rationale_type, last_key: signature.kwargs[last_key]})-- self.extended_signature1 = dsp.Template(signature.instructions, **extended_kwargs1)- self.extended_signature2 = dsp.Template(signature.instructions, **extended_kwargs2)+ DEFAULT_HINT_TYPE = dspy.OutputField()+ self.extended_signature2 = self.extended_signature1.insert(-2, "hint", DEFAULT_HINT_TYPE, type_=str)```**Parameters:**- `signature` (_Any_): Signature of predictive model.-- `rationale_type` (_dsp.Type_, _optional_): Rationale type for reasoning steps. Defaults to `None`.+- `rationale_type` (_dsp.OutputField_, _optional_): Rationale type for reasoning steps. Defaults to `None`.- `activated` (_bool_, _optional_): Flag for activated chain of thought processing. Defaults to `True`.- `**config` (_dict_): Additional configuration parameters for model.