@@ -46,6 +46,11 @@ def run(self, messages: list[ChatMessage]) -> dict[str, str]:
4646class SimpleComponent :
4747 """A simple component that generates text."""
4848
49+ def warm_up (self ):
50+ """
51+ Prepare the component for use.
52+ """
53+
4954 @component .output_types (reply = str )
5055 def run (self , text : str ) -> dict [str , str ]:
5156 """
@@ -143,7 +148,7 @@ def run(self, documents: list[Document], top_k: int = 5) -> dict[str, str]:
143148 :param top_k: The number of top documents to concatenate
144149 :returns: Dictionary containing the concatenated document contents
145150 """
146- return {"concatenated" : "\n " .join (doc .content for doc in documents [:top_k ])}
151+ return {"concatenated" : "\n " .join (doc .content for doc in documents [:top_k ] if doc . content )}
147152
148153
149154@component
@@ -215,7 +220,7 @@ def test_from_component_with_inputs_from_state_different_names(self):
215220 def test_from_component_with_invalid_inputs_from_state_nested_dict (self ):
216221 """Test that ComponentTool rejects nested dict format for inputs_from_state"""
217222 with pytest .raises (TypeError , match = "must be str, not dict" ):
218- ComponentTool (component = SimpleComponent (), inputs_from_state = {"documents" : {"source" : "documents" }})
223+ ComponentTool (component = SimpleComponent (), inputs_from_state = {"documents" : {"source" : "documents" }}) # type: ignore[dict-item]
219224
220225 def test_from_component_with_outputs_to_state (self ):
221226 tool = ComponentTool (component = SimpleComponent (), outputs_to_state = {"replies" : {"source" : "reply" }})
@@ -369,13 +374,13 @@ def test_from_component_with_dynamic_input_types(self):
369374
370375 def test_from_component_with_invalid_component (self ):
371376 class NotAComponent :
372- def foo (self , text : str ):
377+ def foo (self , text : str ) -> dict [ str , str ] :
373378 return {"reply" : f"Hello, { text } !" }
374379
375380 not_a_component = NotAComponent ()
376381
377382 with pytest .raises (TypeError ):
378- ComponentTool (component = not_a_component , name = "invalid_tool" , description = "This should fail" )
383+ ComponentTool (component = not_a_component , name = "invalid_tool" , description = "This should fail" ) # type: ignore[arg-type]
379384
380385 def test_component_invoker_with_chat_message_input (self ):
381386 tool = ComponentTool (
@@ -392,7 +397,7 @@ class AnnotatedComponent:
392397 """An annotated component with descriptive parameter docstrings."""
393398
394399 @component .output_types (result = str )
395- def run (self , text : str , number : int = 42 ):
400+ def run (self , text : str , number : int = 42 ) -> dict [ str , str ] :
396401 """
397402 Process inputs and return result.
398403
@@ -447,7 +452,7 @@ class ComponentA:
447452 """Component A with descriptive docstrings."""
448453
449454 @component .output_types (output_a = str )
450- def run (self , query : str ):
455+ def run (self , query : str ) -> dict [ str , str ] :
451456 """
452457 Process query in component A.
453458
@@ -460,7 +465,7 @@ class ComponentB:
460465 """Component B with descriptive docstrings."""
461466
462467 @component .output_types (output_b = str )
463- def run (self , text : str ):
468+ def run (self , text : str ) -> dict [ str , str ] :
464469 """
465470 Process text in component B.
466471
@@ -503,20 +508,20 @@ def run(self, text: str):
503508
504509 def test_warm_up_is_idempotent (self ):
505510 """Test that calling warm_up multiple times only warms up the component once."""
506- from unittest .mock import MagicMock
511+ from unittest .mock import MagicMock , patch
507512
508513 component = SimpleComponent ()
509- component .warm_up = MagicMock ()
510514
511515 tool = ComponentTool (component = component )
512516
513- # Call warm_up multiple times
514- tool .warm_up ()
515- tool .warm_up ()
516- tool .warm_up ()
517+ with patch .object (component , "warm_up" , MagicMock ()) as mock_warm_up :
518+ # Call warm_up multiple times
519+ tool .warm_up ()
520+ tool .warm_up ()
521+ tool .warm_up ()
517522
518- # Component's warm_up should only be called once
519- component . warm_up .assert_called_once ()
523+ # Component's warm_up should only be called once
524+ mock_warm_up .assert_called_once ()
520525
521526 def test_from_component_with_callable_params_skipped (self , monkeypatch ):
522527 monkeypatch .setenv ("OPENAI_API_KEY" , "test-api-key" )
0 commit comments