Skip to content

Commit

Permalink
Merge changes into unit test for DocsSummarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jan 27, 2025
1 parent b9bc7eb commit a3decd2
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions tests/unit/query_helpers/test_docs_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@
from langchain_core.messages import AIMessage, HumanMessage

from ols import config
from ols.app.models.config import LoggingConfig
from ols.src.query_helpers.docs_summarizer import DocsSummarizer, QueryHelper
from ols.utils import suid
from ols.utils.logging_configurator import configure_logging
from tests import constants
from tests.mock_classes.mock_langchain_interface import mock_langchain_interface
from tests.mock_classes.mock_llama_index import MockLlamaIndex
from tests.mock_classes.mock_llm_chain import mock_llm_chain
from tests.mock_classes.mock_llm_loader import mock_llm_loader

# needs to be setup there before is_user_authorized is imported
config.ols_config.authentication_config.module = "k8s"


from ols.app.models.config import LoggingConfig # noqa:E402
from ols.src.query_helpers.docs_summarizer import ( # noqa:E402
DocsSummarizer,
QueryHelper,
)
from ols.utils import suid # noqa:E402
from ols.utils.logging_configurator import configure_logging # noqa:E402
from tests import constants # noqa:E402
from tests.mock_classes.mock_langchain_interface import ( # noqa:E402
mock_langchain_interface,
)
from tests.mock_classes.mock_llama_index import MockLlamaIndex # noqa:E402
from tests.mock_classes.mock_llm_chain import mock_llm_chain # noqa:E402
from tests.mock_classes.mock_llm_loader import mock_llm_loader # noqa:E402

conversation_id = suid.get_suid()

Expand Down Expand Up @@ -51,6 +61,18 @@ def test_if_system_prompt_was_updated():
assert summarizer.system_prompt == expected_prompt


def test_docs_summarizer_streaming_parameter():
"""Test if optional streaming parameter is stored."""
summarizer = DocsSummarizer(llm_loader=mock_llm_loader(None))
assert summarizer.streaming is False

summarizer = DocsSummarizer(llm_loader=mock_llm_loader(None), streaming=False)
assert summarizer.streaming is False

summarizer = DocsSummarizer(llm_loader=mock_llm_loader(None), streaming=True)
assert summarizer.streaming is True


@patch("ols.utils.token_handler.RAG_SIMILARITY_CUTOFF", 0.4)
@patch("ols.utils.token_handler.MINIMUM_CONTEXT_TOKEN_LIMIT", 1)
@patch("ols.src.query_helpers.docs_summarizer.LLMChain", new=mock_llm_chain(None))
Expand Down

0 comments on commit a3decd2

Please sign in to comment.