haystack/examples/test_basic_faq_pipeline.py
Tuana Celik e1502c8029
Adding Example Scripts to Haystack (#3588)
* add 2 example scripts

* fixing faq script

* updating PR based on comments

* black

* updating s3 buckets

* first attempt at testing

* Add basic tests to two scripts

PR: #3588

* make tests runnable

* reformat files

* only run in PRs touching an example

Co-authored-by: bilgeyucel <bilgeyucel96@gmail.com>
Co-authored-by: Massimiliano Pippi <mpippi@gmail.com>
2023-01-27 14:54:59 +01:00

20 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from examples.basic_faq_pipeline import basic_faq_pipeline
from haystack.schema import Answer, Document
def test_basic_faq_pipeline():
prediction = basic_faq_pipeline()
assert prediction is not None
assert prediction["query"] == "How is the virus spreading?"
assert len(prediction["answers"]) == 10 # top-k of Retriever
assert type(prediction["answers"][0]) == Answer
assert (
prediction["answers"][0].answer
== """This virus was first detected in Wuhan City, Hubei Province, China. The first infections were linked to a live animal market, but the virus is now spreading from person-to-person. Its important to note that person-to-person spread can happen on a continuum. Some viruses are highly contagious (like measles), while other viruses are less so.\n\nThe virus that causes COVID-19 seems to be spreading easily and sustainably in the community (“community spread”) in some affected geographic areas. Community spread means people have been infected with the virus in an area, including some who are not sure how or where they became infected.\n\nLearn what is known about the spread of newly emerged coronaviruses."""
)
assert prediction["answers"][0].score <= 1
assert prediction["answers"][0].score >= 0