Skip to content

Commit

Permalink
Merge branch 'main' into docstrings-linting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsbatista authored Apr 23, 2024
2 parents 724c6cd + 32db7eb commit 71a6d30
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
12 changes: 6 additions & 6 deletions haystack/components/evaluators/llm_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def validate_init_parameters(
# Validate inputs
if (
not isinstance(inputs, list)
or not all(isinstance(input, tuple) for input in inputs)
or not all(isinstance(input[0], str) and input[1] is not list and len(input) == 2 for input in inputs)
or not all(isinstance(_input, tuple) for _input in inputs)
or not all(isinstance(_input[0], str) and _input[1] is not list and len(_input) == 2 for _input in inputs)
):
msg = (
f"LLM evaluator expects inputs to be a list of tuples. Each tuple must contain an input name and "
Expand Down Expand Up @@ -272,17 +272,17 @@ def validate_input_parameters(expected: Dict[str, Any], received: Dict[str, Any]
raise ValueError(msg)

# Validate that all received inputs are lists
if not all(isinstance(input, list) for input in received.values()):
msg = f"LLM evaluator expects all input values to be lists but received {[type(input) for input in received.values()]}."
if not all(isinstance(_input, list) for _input in received.values()):
msg = f"LLM evaluator expects all input values to be lists but received {[type(_input) for _input in received.values()]}."
raise ValueError(msg)

# Validate that all received inputs are of the same length
inputs = received.values()
length = len(next(iter(inputs)))
if not all(len(input) == length for input in inputs):
if not all(len(_input) == length for _input in inputs):
msg = (
f"LLM evaluator expects all input lists to have the same length but received {inputs} with lengths "
f"{[len(input) for input in inputs]}."
f"{[len(_input) for _input in inputs]}."
)
raise ValueError(msg)

Expand Down
6 changes: 3 additions & 3 deletions haystack/components/extractors/named_entity_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _BackendEnumMeta(EnumMeta):
Metaclass for fine-grained error handling of backend enums.
"""

def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1):
def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1): # noqa: A002
if names is None:
try:
return EnumMeta.__call__(cls, value, names, module=module, qualname=qualname, type=type, start=start)
Expand Down Expand Up @@ -244,13 +244,13 @@ class _NerBackend(ABC):

def __init__(
self,
type: NamedEntityExtractorBackend,
_type: NamedEntityExtractorBackend,
device: ComponentDevice,
pipeline_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
super().__init__()

self._type = type
self._type = _type
self._device = device
self._pipeline_kwargs = pipeline_kwargs if pipeline_kwargs is not None else {}

Expand Down
4 changes: 2 additions & 2 deletions haystack/components/joiners/document_joiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def _reciprocal_rank_fusion(self, document_lists):

# Normalize scores. Note: len(results) / k is the maximum possible score,
# achieved by being ranked first in all doc lists with non-zero weight.
for id in scores_map:
scores_map[id] /= len(document_lists) / k
for _id in scores_map:
scores_map[_id] /= len(document_lists) / k

for doc in documents_map.values():
doc.score = scores_map[doc.id]
Expand Down
2 changes: 1 addition & 1 deletion haystack/core/component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class _Component:
def __init__(self):
self.registry = {}

def set_input_type(self, instance, name: str, type: Any, default: Any = _empty):
def set_input_type(self, instance, name: str, type: Any, default: Any = _empty): # noqa: A002
"""
Add a single input socket to the component instance.
Expand Down
10 changes: 4 additions & 6 deletions test/components/evaluators/test_faithfulness_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def test_live_run(self):
evaluator = FaithfulnessEvaluator()
result = evaluator.run(questions=questions, contexts=contexts, responses=responses)

assert result["score"] == 0.5
assert result["individual_scores"] == [0.5]
assert result["results"][0]["score"] == 0.5
assert result["results"][0]["statement_scores"] == [1, 0]
assert "programming language" in result["results"][0]["statements"][0]
assert "George Lucas" in result["results"][0]["statements"][1]
required_fields = {"individual_scores", "results", "score"}
assert all(field in result for field in required_fields)
nested_required_fields = {"score", "statement_scores", "statements"}
assert all(field in result["results"][0] for field in nested_required_fields)

0 comments on commit 71a6d30

Please sign in to comment.