|
1 | 1 | """Unit tests for DocsSummarizer class."""
|
2 | 2 |
|
3 | 3 | import logging
|
4 |
| -from unittest.mock import ANY, patch |
| 4 | +from unittest.mock import ANY, call, patch |
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 |
|
@@ -121,6 +121,30 @@ def test_summarize_truncation():
|
121 | 121 | assert summary.history_truncated
|
122 | 122 |
|
123 | 123 |
|
| 124 | +@patch("ols.utils.token_handler.RAG_SIMILARITY_CUTOFF", 0.4) |
| 125 | +@patch("ols.src.query_helpers.docs_summarizer.LLMChain", new=mock_llm_chain(None)) |
| 126 | +def test_prepare_prompt_context(): |
| 127 | + """Basic test for DocsSummarizer to check re-structuring of context for the 'temp' prompt.""" |
| 128 | + summarizer = DocsSummarizer(llm_loader=mock_llm_loader(None)) |
| 129 | + question = "What's the ultimate question with answer 42?" |
| 130 | + history = ["human: What is Kubernetes?"] |
| 131 | + rag_index = MockLlamaIndex() |
| 132 | + |
| 133 | + with patch( |
| 134 | + "ols.src.query_helpers.docs_summarizer.restructure_rag_context", |
| 135 | + return_value="patched_history", |
| 136 | + ) as restructure_rag_context: |
| 137 | + summarizer.create_response(question, rag_index, history) |
| 138 | + restructure_rag_context.assert_has_calls([call("sample", ANY)]) |
| 139 | + |
| 140 | + with patch( |
| 141 | + "ols.src.query_helpers.docs_summarizer.restructure_history", |
| 142 | + return_value="patched_history", |
| 143 | + ) as restructure_history: |
| 144 | + summarizer.create_response(question, rag_index, history) |
| 145 | + restructure_history.assert_has_calls([call("ai: sample", ANY)]) |
| 146 | + |
| 147 | + |
124 | 148 | @patch("ols.src.query_helpers.docs_summarizer.LLMChain", new=mock_llm_chain(None))
|
125 | 149 | def test_summarize_no_reference_content():
|
126 | 150 | """Basic test for DocsSummarizer using mocked index and query engine."""
|
|
0 commit comments