Skip to content

Commit 96251c4

Browse files
committed
♻️ All models should use nexent.core.model instead of smolagent #1971
[Specification Details] 1.add test cases.
1 parent a858828 commit 96251c4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/backend/test_document_vector_utils.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
consts_const_mock.NEXENT_POSTGRES_PASSWORD = "test_password"
2626
consts_const_mock.POSTGRES_DB = "test_db"
2727
consts_const_mock.POSTGRES_PORT = 5432
28+
consts_const_mock.LANGUAGE = {"ZH": "zh", "EN": "en"}
2829
consts_mock.const = consts_const_mock
2930
sys.modules['consts'] = consts_mock
3031
sys.modules['consts.const'] = consts_const_mock
@@ -253,6 +254,28 @@ def test_summarize_document_with_model_placeholder(self):
253254
assert isinstance(result, str)
254255
assert len(result) > 0
255256

257+
def test_summarize_document_with_model_success(self):
258+
"""Test document summarization when model config exists and LLM returns value"""
259+
with patch('backend.utils.document_vector_utils.get_model_by_model_id') as mock_get_model, \
260+
patch('backend.utils.document_vector_utils.call_llm_for_system_prompt') as mock_llm:
261+
mock_get_model.return_value = {"id": 1}
262+
mock_llm.return_value = "Generated summary\n"
263+
264+
result = summarize_document(
265+
document_content="LLM content",
266+
filename="doc.pdf",
267+
language="en",
268+
max_words=50,
269+
model_id=1,
270+
tenant_id="tenant"
271+
)
272+
273+
assert result == "Generated summary"
274+
mock_llm.assert_called_once()
275+
call_args = mock_llm.call_args.kwargs
276+
assert call_args["model_id"] == 1
277+
assert call_args["tenant_id"] == "tenant"
278+
256279

257280
class TestSummarizeCluster:
258281
"""Test cluster summarization"""
@@ -277,6 +300,27 @@ def test_summarize_cluster_with_model_placeholder(self):
277300
assert isinstance(result, str)
278301
assert len(result) > 0
279302

303+
def test_summarize_cluster_with_model_success(self):
304+
"""Test cluster summarization when model config exists and LLM returns value"""
305+
with patch('backend.utils.document_vector_utils.get_model_by_model_id') as mock_get_model, \
306+
patch('backend.utils.document_vector_utils.call_llm_for_system_prompt') as mock_llm:
307+
mock_get_model.return_value = {"id": 1}
308+
mock_llm.return_value = "Cluster summary text "
309+
310+
result = summarize_cluster(
311+
document_summaries=["Doc 1 summary", "Doc 2 summary"],
312+
language="en",
313+
max_words=120,
314+
model_id=1,
315+
tenant_id="tenant"
316+
)
317+
318+
assert result == "Cluster summary text"
319+
mock_llm.assert_called_once()
320+
call_args = mock_llm.call_args.kwargs
321+
assert call_args["model_id"] == 1
322+
assert call_args["tenant_id"] == "tenant"
323+
280324

281325
class TestSummarizeClustersMapReduce:
282326
"""Test map-reduce cluster summarization"""

0 commit comments

Comments
 (0)