2024-01-08 17:15:10 +01:00
|
|
|
import os
|
|
|
|
|
2023-12-04 14:25:29 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from haystack.dataclasses import Answer
|
|
|
|
from haystack.document_stores import InMemoryDocumentStore
|
|
|
|
from haystack.pipeline_utils.rag import build_rag_pipeline
|
2023-12-21 16:21:24 +01:00
|
|
|
from haystack.testing.factory import document_store_class
|
2023-12-04 14:25:29 +00:00
|
|
|
|
|
|
|
|
2024-01-08 17:15:10 +01:00
|
|
|
@pytest.mark.skipif("OPENAI_API_KEY" not in os.environ, reason="OPENAI_API_KEY is not set")
|
2023-12-21 08:51:54 +01:00
|
|
|
@pytest.mark.integration
|
2023-12-04 14:25:29 +00:00
|
|
|
def test_rag_pipeline(mock_chat_completion):
|
|
|
|
rag_pipe = build_rag_pipeline(document_store=InMemoryDocumentStore())
|
|
|
|
answer = rag_pipe.run(query="question")
|
|
|
|
assert isinstance(answer, Answer)
|
|
|
|
|
|
|
|
|
|
|
|
def test_rag_pipeline_other_docstore():
|
|
|
|
FakeStore = document_store_class("FakeStore")
|
|
|
|
with pytest.raises(ValueError, match="InMemoryDocumentStore"):
|
|
|
|
assert build_rag_pipeline(document_store=FakeStore())
|
|
|
|
|
|
|
|
|
|
|
|
def test_rag_pipeline_embedder_exist_if_model_is_given():
|
|
|
|
rag_pipe = build_rag_pipeline(
|
|
|
|
document_store=InMemoryDocumentStore(), embedding_model="sentence-transformers/all-mpnet-base-v2"
|
|
|
|
)
|
|
|
|
assert "text_embedder" in rag_pipe.pipeline.graph.nodes
|