dspy
dspy copied to clipboard
[Bug] Argument type mismatch
What happened?
Trying the math example code causes a Pylance warning:
Argument of type "Literal['question -> answer: float']" cannot be assigned to parameter "signature" of type "type[Signature]" in function "__init__"
Type "Literal['question -> answer: float']" is not assignable to type "type[Signature]"Pylance[reportArgumentType](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md)
The code still runs, but the Pylance warning is irritating. Is there any way to fix it by explicitly declaring types?
Steps to reproduce
Use the math demo code:
math = dspy.ChainOfThought(signature="question -> answer: float")
predict = math(question="Two dice are tossed. What is the probability that the sum equals two?")
DSPy version
2.6.27
I cannot reproduce the issue:
import dspy
dspy.settings.configure(lm=dspy.LM("openai/gpt-4o-mini"))
math = dspy.ChainOfThought(signature="question -> answer: float")
print(math(question="Two dice are tossed. What is the probability that the sum equals two?"))
produces the following with no warning.
(dspy) [main][~/Documents/mlflow_team/dspy]$ python3 debug_issue_tmp/8373_tmp.py
Prediction(
reasoning='When two dice are tossed, each die has 6 faces, resulting in a total of 6 * 6 = 36 possible outcomes. The only way to achieve a sum of 2 is by rolling a 1 on both dice (1,1). There is only 1 favorable outcome for this event. Therefore, the probability of the sum equaling 2 is the number of favorable outcomes divided by the total number of outcomes, which is 1/36.',
answer=0.027777777777777776
)
Might this be tied to a specific python version? I am using python3.10.x