@@ -70,23 +70,24 @@ def load_state(self, state):
70
70
71
71
return self
72
72
73
+ def _get_positional_args_error_message (self ):
74
+ input_fields = list (self .signature .input_fields .keys ())
75
+ return (
76
+ "Positional arguments are not allowed when calling `dspy.Predict`, must use keyword arguments "
77
+ f"that match your signature input fields: '{ ', ' .join (input_fields )} '. For example: "
78
+ f"`predict({ input_fields [0 ]} =input_value, ...)`."
79
+ )
80
+
73
81
def __call__ (self , * args , ** kwargs ):
74
82
if args :
75
- raise ValueError (
76
- "Positional arguments are not allowed when calling `dspy.Predict`, must use keyword arguments "
77
- "that match your signature input fields. For example: "
78
- "dspy.Predict('question -> answer')(question='What is the capital of France?')"
79
- )
83
+ raise ValueError (self ._get_positional_args_error_message ())
80
84
81
85
return super ().__call__ (** kwargs )
82
86
83
87
async def acall (self , * args , ** kwargs ):
84
88
if args :
85
- raise ValueError (
86
- "Positional arguments are not allowed when calling `dspy.Predict`, must use keyword arguments "
87
- "that match your signature input fields. For example: "
88
- "dspy.Predict('question -> answer').acall(question='What is the capital of France?')"
89
- )
89
+ raise ValueError (self ._get_positional_args_error_message ())
90
+
90
91
return await super ().acall (** kwargs )
91
92
92
93
def _forward_preprocess (self , ** kwargs ):
0 commit comments