@@ -25,7 +25,7 @@ def _configure_dspy_lm(model: str, api_base: str | None = None, **kwargs: Any) -
2525 return lm
2626
2727
28- def _get_dspy_module_class (module_type : str ):
28+ def _get_dspy_module_class (module_type : str ) -> type :
2929 """
3030 Map a module type string to the corresponding DSPy module class.
3131
@@ -148,7 +148,7 @@ def __init__(
148148 module_class = _get_dspy_module_class (self .module_type )
149149 self ._module = module_class (self .signature , ** self .module_kwargs )
150150
151- def _build_dspy_inputs (self , prompt : str , ** kwargs ) -> dict [str , Any ]:
151+ def _build_dspy_inputs (self , prompt : str , ** kwargs : Any ) -> dict [str , Any ]:
152152 """Build the input dict for the DSPy module call."""
153153 if self .input_mapping :
154154 dspy_inputs = {}
@@ -180,8 +180,8 @@ def _extract_last_user_message(messages: list[ChatMessage]) -> str:
180180 """Extract the text of the last user message from a list of chat messages."""
181181 for msg in reversed (messages ):
182182 if msg .role == ChatRole .USER :
183- return msg .text
184- return messages [- 1 ].text
183+ return msg .text or ""
184+ return messages [- 1 ].text or ""
185185
186186 def _signature_to_string (self ) -> str :
187187 """
@@ -227,7 +227,7 @@ def run(
227227 self ,
228228 messages : list [ChatMessage ],
229229 generation_kwargs : dict [str , Any ] | None = None ,
230- ** kwargs ,
230+ ** kwargs : Any ,
231231 ) -> dict [str , Any ]:
232232 """
233233 Run the DSPy module on the given messages.
@@ -256,7 +256,7 @@ async def run_async(
256256 self ,
257257 messages : list [ChatMessage ],
258258 generation_kwargs : dict [str , Any ] | None = None ,
259- ** kwargs ,
259+ ** kwargs : Any ,
260260 ) -> dict [str , Any ]:
261261 """
262262 Asynchronously run the DSPy module on the given messages.
0 commit comments