stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
14.43k stars 1.11k forks source link

error while setting rationale_type in ChainOfThought #846

Open DSLituiev opened 3 months ago

DSLituiev commented 3 months ago

I am trying to provide a custom rationale_type kwarg into ChainOfThought as described here and running into a cryptic error. The same example works w/o rationale_type.

rationale_type = dsp.Type(prefix="Reasoning: Let's think step by step in order to",
                         desc="${understand whether the two inputs match and provide correction if needed}. We ...")
dspy.ChainOfThought(Equivalence, rationale_type=rationale_type)(source=source, target=target)

File ~/.conda/envs/dspy/lib/python3.11/site-packages/dspy/predict/chain_of_thought.py:45, in ChainOfThought.init(self, signature, rationale_type, activated, *config) 38 _keys, last_key = signature.output_fields.keys() 40 rationale_type = rationale_type or dspy.OutputField( 41 prefix="Reasoning: Let's think step by step in order to", 42 desc="${produce the " + last_key + "}. We ...", 43 ) ---> 45 self.extended_signature = signature.prepend("rationale", rationaletype, type=str)

File ~/.conda/envs/dspy/lib/python3.11/site-packages/dspy/signatures/signature.py:128, in SignatureMeta.prepend(cls, name, field, type) 127 def prepend(cls, name, field, type=None) -> Type["Signature"]: --> 128 return cls.insert(0, name, field, type_)

File ~/.conda/envs/dspy/lib/python3.11/site-packages/dspy/signatures/signature.py:145, in SignatureMeta.insert(cls, index, name, field, type_) 142 output_fields = list(cls.output_fields.items()) 144 # Choose the list to insert into based on the field type --> 145 lst = input_fields if field.json_schema_extra["__dspy_field_type"] == "input" else output_fields 146 # We support negative insert indices 147 if index < 0:

AttributeError: 'Type' object has no attribute 'json_schema_extra'

DSLituiev commented 3 months ago

This seems to be the issue with the documentation. dsp.Type should be changed to dspy.OutputField

chiragshah285 commented 2 months ago

minding a PR to fix this? thanks!