haystack/test/test_summarizer_translation.py
Sara Zan a59bca3661
Apply black formatting (#2115)
* Testing black on ui/

* Applying black on docstores

* Add latest docstring and tutorial changes

* Create a single GH action for Black and docs to reduce commit noise to the minimum, slightly refactor the OpenAPI action too

* Remove comments

* Relax constraints on pydoc-markdown

* Split temporary black from the docs. Pydoc-markdown was obsolete and needs a separate PR to upgrade

* Fix a couple of bugs

* Add a type: ignore that was missing somehow

* Give path to black

* Apply Black

* Apply Black

* Relocate a couple of type: ignore

* Update documentation

* Make Linux CI run after applying Black

* Triggering Black

* Apply Black

* Remove dependency, does not work well

* Remove manually double trailing commas

* Update documentation

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-02-03 13:43:18 +01:00

39 lines
1.6 KiB
Python

import pytest
from haystack.pipelines import TranslationWrapperPipeline, SearchSummarizationPipeline
from haystack.nodes import DensePassageRetriever, EmbeddingRetriever
from test_summarizer import SPLIT_DOCS
# Keeping few (retriever,document_store) combination to reduce test time
@pytest.mark.slow
@pytest.mark.elasticsearch
@pytest.mark.summarizer
@pytest.mark.parametrize(
"retriever,document_store",
[("embedding", "memory"), ("elasticsearch", "elasticsearch")],
indirect=True,
)
def test_summarization_pipeline_with_translator(
document_store, retriever, summarizer, en_to_de_translator, de_to_en_translator
):
document_store.write_documents(SPLIT_DOCS)
if isinstance(retriever, EmbeddingRetriever) or isinstance(retriever, DensePassageRetriever):
document_store.update_embeddings(retriever=retriever)
query = "Wo steht der Eiffelturm?"
base_pipeline = SearchSummarizationPipeline(retriever=retriever, summarizer=summarizer)
pipeline = TranslationWrapperPipeline(
input_translator=de_to_en_translator, output_translator=en_to_de_translator, pipeline=base_pipeline
)
output = pipeline.run(
query=query, params={"Retriever": {"top_k": 2}, "Summarizer": {"generate_single_summary": True}}
)
# SearchSummarizationPipeline return answers but Summarizer return documents
documents = output["documents"]
assert len(documents) == 1
assert documents[0].content in [
"Der Eiffelturm ist ein Wahrzeichen in Paris, Frankreich.",
"Der Eiffelturm, der 1889 in Paris, Frankreich, erbaut wurde, ist das höchste freistehende Bauwerk der Welt.",
]