Closed cognitivetech closed 4 weeks ago
I'm having the same issue. I'd love it if someone would fix it... I've spent about 40 hours on this one problem. I've tried fixing this every which way I can.
cc @XenonMolecule @klopsahlong
Thanks for reporting this @cognitivetech @bryonmccoy . Can we get a full stack trace of the error?
Seeing a full trace of the error stack will probably make this pretty easy to spot
I took a look at this, and managed to recreate it with a relatively small subset.
import dspy
class Notes(dspy.Signature):
"""Bulleted Markdown Notes, Headings and Terms in Bold"""
document = dspy.InputField()
notes = dspy.OutputField()
Notes()
I am including the Notes()
, cause you are passing the Signature directly into the Teleprompt, in this way.
If you take a look at the way __new__
and __init__
are set up for dspy.Signature
, it appears that simply declaring the Notes class itself, instantiates the object.
Ie. Calling only the below
import dspy
class Notes(dspy.Signature):
"""Bulleted Markdown Notes, Headings and Terms in Bold"""
document = dspy.InputField()
notes = dspy.OutputField()
Will call both the dspy.Signature.__new__
, and then dspy.Signature.__init__
, without instantiation in the python file directly.
Later on when Notes()
is being called, this is not instantiating the Notes object, but rather calling the Notes.__call__
method. It is at this point that __call__
requires an 'example' argument to pass to `TemplateV2'.
If for example, you get around this by Simply passing Notes
as opposed to Notes()
into the teleprompt, you bypass the Example error, but the teleprompt tries to deepcopy the signature. A deepcopy method is used for dspy.Module
but not dspy.Signature
.
Should a dspy.Signature
be directly passed into Teleprompters?
Yep I suspect this is the issue. BayesianSignatureOptimizer takes a dspy.Module
to optimize. I acknowledge the naming is a bit confusing and we are likely going to update the optimizers soon with the official optimizer release.
Good sleuthing @KCaverly!
For this example making a dspy.Module
wrapper for the Notes() signature should resolve this particular problem. You can use either dspy.ChainOfThought or dspy.Predict.
You can either pass dspy.Predict(Notes)()
to the optimizer, or create a custom wrapper module:
class WriteNotes(dspy.Module):
def __init__(self):
super().__init__()
self.generate_notes = dspy.Predict(Notes)
def forward(self, document):
return self.generate_notes(document=document)
as explained in the title, I'm getting this error from the following code:
TypeError: TemplateV2.__call__() missing 1 required positional argument: 'example'