2021-08-02 14:51:24 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
2021-08-31 10:14:55 +02:00
|
|
|
import ray
|
|
|
|
|
2022-01-26 18:12:55 +01:00
|
|
|
from haystack.pipelines import RayPipeline
|
|
|
|
|
|
|
|
from conftest import SAMPLES_PATH
|
2021-08-02 14:51:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("document_store_with_docs", ["elasticsearch"], indirect=True)
|
|
|
|
def test_load_pipeline(document_store_with_docs):
|
|
|
|
pipeline = RayPipeline.load_from_yaml(
|
2022-01-26 18:12:55 +01:00
|
|
|
SAMPLES_PATH/"pipeline"/"test_pipeline.yaml", pipeline_name="ray_query_pipeline", num_cpus=8,
|
2021-08-02 14:51:24 +02:00
|
|
|
)
|
2021-09-10 11:41:16 +02:00
|
|
|
prediction = pipeline.run(query="Who lives in Berlin?", params={"Retriever": {"top_k": 10}, "Reader": {"top_k": 3}})
|
2021-08-31 10:14:55 +02:00
|
|
|
|
|
|
|
assert ray.serve.get_deployment(name="ESRetriever").num_replicas == 2
|
|
|
|
assert ray.serve.get_deployment(name="Reader").num_replicas == 1
|
2021-08-02 14:51:24 +02:00
|
|
|
assert prediction["query"] == "Who lives in Berlin?"
|
2021-10-13 14:23:23 +02:00
|
|
|
assert prediction["answers"][0].answer == "Carla"
|
2021-12-22 17:20:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
|
|
def shutdown_ray():
|
|
|
|
yield
|
|
|
|
try:
|
|
|
|
import ray
|
|
|
|
ray.shutdown()
|
|
|
|
except:
|
|
|
|
pass
|