diff --git a/haystack/testing/sample_components/accumulate.py b/haystack/testing/sample_components/accumulate.py index c288fa4961..eee718e0df 100644 --- a/haystack/testing/sample_components/accumulate.py +++ b/haystack/testing/sample_components/accumulate.py @@ -19,15 +19,17 @@ def _default_function(first: int, second: int) -> int: class Accumulate: """ Accumulates the value flowing through the connection into an internal attribute. - The sum function can be customized. - Example of how to deal with serialization when some of the parameters + The sum function can be customized. Example of how to deal with serialization when some of the parameters are not directly serializable. """ def __init__(self, function: Optional[Callable] = None): """ - :param function: the function to use to accumulate the values. + Class constructor + + :param function: + the function to use to accumulate the values. The function must take exactly two values. If it's a callable, it's used as it is. If it's a string, the component will look for it in sys.modules and @@ -36,7 +38,8 @@ def __init__(self, function: Optional[Callable] = None): self.state = 0 self.function: Callable = _default_function if function is None else function # type: ignore - def to_dict(self) -> Dict[str, Any]: # pylint: disable=missing-function-docstring + def to_dict(self) -> Dict[str, Any]: + """Converts the component to a dictionary""" module = sys.modules.get(self.function.__module__) if not module: raise ValueError("Could not locate the import module.") @@ -48,7 +51,8 @@ def to_dict(self) -> Dict[str, Any]: # pylint: disable=missing-function-docstri return default_to_dict(self, function=function_name) @classmethod - def from_dict(cls, data: Dict[str, Any]) -> "Accumulate": # pylint: disable=missing-function-docstring + def from_dict(cls, data: Dict[str, Any]) -> "Accumulate": + """Loads the component from a dictionary""" if "type" not in data: raise ComponentDeserializationError("Missing 'type' in component serialization data") if data["type"] != f"{cls.__module__}.{cls.__name__}": @@ -70,6 +74,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "Accumulate": # pylint: disable=mis def run(self, value: int): """ Accumulates the value flowing through the connection into an internal attribute. + The sum function can be customized. """ self.state = self.function(self.state, value) diff --git a/haystack/testing/sample_components/greet.py b/haystack/testing/sample_components/greet.py index 1eb844ec10..54753a8b69 100644 --- a/haystack/testing/sample_components/greet.py +++ b/haystack/testing/sample_components/greet.py @@ -18,6 +18,8 @@ class Greet: def __init__(self, message: str = "\nGreeting component says: Hi! The value is {value}\n", log_level: str = "INFO"): """ + Class constructor + :param message: the message to log. Can use `{value}` to embed the value. :param log_level: the level to log at. """ diff --git a/haystack/testing/sample_components/hello.py b/haystack/testing/sample_components/hello.py index ece58022d4..41d6860858 100644 --- a/haystack/testing/sample_components/hello.py +++ b/haystack/testing/sample_components/hello.py @@ -8,8 +8,5 @@ class Hello: @component.output_types(output=str) def run(self, word: str): - """ - Takes a string in input and returns "Hello, !" - in output. - """ + """Takes a string in input and returns "Hello, !"in output.""" return {"output": f"Hello, {word}!"} diff --git a/haystack/testing/sample_components/joiner.py b/haystack/testing/sample_components/joiner.py index 9488c1158d..f17c9e27c9 100644 --- a/haystack/testing/sample_components/joiner.py +++ b/haystack/testing/sample_components/joiner.py @@ -12,9 +12,9 @@ class StringJoiner: @component.output_types(output=str) def run(self, input_str: Variadic[str]): """ - Take strings from multiple input nodes and join them - into a single one returned in output. Since `input_str` - is Variadic, we know we'll receive a List[str]. + Take strings from multiple input nodes and join them into a single one returned in output. + + Since `input_str` is Variadic, we know we'll receive a List[str]. """ return {"output": " ".join(input_str)} @@ -24,9 +24,9 @@ class StringListJoiner: @component.output_types(output=str) def run(self, inputs: Variadic[List[str]]): """ - Take list of strings from multiple input nodes and join them - into a single one returned in output. Since `input_str` - is Variadic, we know we'll receive a List[List[str]]. + Take list of strings from multiple input nodes and join them into a single one returned in output. + + Since `input_str` is Variadic, we know we'll receive a List[List[str]]. """ retval: List[str] = [] for list_of_strings in inputs: diff --git a/haystack/testing/sample_components/self_loop.py b/haystack/testing/sample_components/self_loop.py index 1554294309..76089d1da9 100644 --- a/haystack/testing/sample_components/self_loop.py +++ b/haystack/testing/sample_components/self_loop.py @@ -6,6 +6,7 @@ class SelfLoop: """ Decreases the initial value in steps of 1 until the target value is reached. + For no good reason it uses a self-loop to do so :) """ @@ -14,9 +15,7 @@ def __init__(self, target: int = 0): @component.output_types(current_value=int, final_result=int) def run(self, values: Variadic[int]): - """ - Decreases the input value in steps of 1 until the target value is reached. - """ + """Decreases the input value in steps of 1 until the target value is reached.""" value = values[0] # type: ignore value -= 1 if value == self.target: diff --git a/haystack/testing/sample_components/subtract.py b/haystack/testing/sample_components/subtract.py index f9c2d8af1f..286cd3c510 100644 --- a/haystack/testing/sample_components/subtract.py +++ b/haystack/testing/sample_components/subtract.py @@ -13,6 +13,8 @@ class Subtract: @component.output_types(difference=int) def run(self, first_value: int, second_value: int): """ + Run the component. + :param first_value: name of the connection carrying the value to subtract from. :param second_value: name of the connection carrying the value to subtract. """ diff --git a/haystack/testing/sample_components/text_splitter.py b/haystack/testing/sample_components/text_splitter.py index d24b0ec274..43ee123444 100644 --- a/haystack/testing/sample_components/text_splitter.py +++ b/haystack/testing/sample_components/text_splitter.py @@ -10,8 +10,5 @@ class TextSplitter: @component.output_types(output=List[str]) def run(self, sentence: str): - """ - Takes a sentence in input and returns its words" - in output. - """ + """Takes a sentence in input and returns its words in output.""" return {"output": sentence.split()} diff --git a/haystack/testing/sample_components/threshold.py b/haystack/testing/sample_components/threshold.py index aab64399c8..1f0b4ba04c 100644 --- a/haystack/testing/sample_components/threshold.py +++ b/haystack/testing/sample_components/threshold.py @@ -9,8 +9,7 @@ @component class Threshold: # pylint: disable=too-few-public-methods """ - Redirects the value, unchanged, along a different connection whether the value is above - or below the given threshold. + Redirects the value, along a different connection whether the value is above or below the given threshold. :param threshold: the number to compare the input value against. This is also a parameter. """ @@ -24,8 +23,7 @@ def __init__(self, threshold: int = 10): @component.output_types(above=int, below=int) def run(self, value: int, threshold: Optional[int] = None): """ - Redirects the value, unchanged, along a different connection whether the value is above - or below the given threshold. + Redirects the value, along a different connection whether the value is above or below the given threshold. :param threshold: the number to compare the input value against. This is also a parameter. """