sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -2947,6 +2947,114 @@ async def test_mixed_tool_keeps_assistant_hit_when_ordinary_search_fails(
|
||||
assert trace["zero_result_reason"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_classic_tool_scopes_one_library_and_assigns_stable_global_ranks(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
ordinary_service = _ToolTraceOrdinaryService(
|
||||
{
|
||||
"mode": "vector",
|
||||
"results": [
|
||||
{
|
||||
"id": "lower-score",
|
||||
"knowledge_base_id": "ordinary-two",
|
||||
"title": "次相关页面",
|
||||
"content": "次相关证据",
|
||||
"score": 0.71,
|
||||
},
|
||||
{
|
||||
"id": "higher-score",
|
||||
"knowledge_base_id": "ordinary-two",
|
||||
"title": "最相关页面",
|
||||
"content": "最相关证据",
|
||||
"score": 0.95,
|
||||
},
|
||||
],
|
||||
"partial": False,
|
||||
"warnings": [],
|
||||
}
|
||||
)
|
||||
tool_module = _configure_search_tool_trace(
|
||||
monkeypatch,
|
||||
mapping_store=_ToolTraceMappingStore(
|
||||
{
|
||||
"ordinary-one": {"id": "ordinary-one", "name": "一号库"},
|
||||
"ordinary-two": {"id": "ordinary-two", "name": "二号库"},
|
||||
}
|
||||
),
|
||||
ordinary_service=ordinary_service,
|
||||
assistant_store=None,
|
||||
)
|
||||
runtime = SimpleNamespace(
|
||||
context={
|
||||
"knowledge_retrieval_mode": "classic",
|
||||
"llmwiki_knowledge_base_ids": ["ordinary-one", "ordinary-two"],
|
||||
"assistant_knowledge_base_ids": [],
|
||||
}
|
||||
)
|
||||
|
||||
first = json.loads(
|
||||
await tool_module.llmwiki_search_tool.coroutine(
|
||||
"治理进展",
|
||||
runtime,
|
||||
knowledge_base_id="ordinary-two",
|
||||
)
|
||||
)
|
||||
second = json.loads(
|
||||
await tool_module.llmwiki_search_tool.coroutine(
|
||||
"治理进展",
|
||||
runtime,
|
||||
knowledge_base_id="ordinary-two",
|
||||
)
|
||||
)
|
||||
|
||||
assert ordinary_service.calls == [["ordinary-two"], ["ordinary-two"]]
|
||||
assert first["selection"] == ["ordinary-two"]
|
||||
assert [item["id"] for item in first["results"]] == [
|
||||
"higher-score",
|
||||
"lower-score",
|
||||
]
|
||||
assert [item["relevance_rank"] for item in first["results"]] == [1, 2]
|
||||
assert [item["citation_id"] for item in first["results"]] == [
|
||||
item["citation_id"] for item in second["results"]
|
||||
]
|
||||
assert all(
|
||||
item["citation_id"].startswith("llmwiki:") for item in first["results"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_classic_search_tool_rejects_smart_mode_even_if_called_directly(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
ordinary_service = _ToolTraceOrdinaryService(
|
||||
{"mode": "vector", "results": [_tool_trace_ordinary_hit()]}
|
||||
)
|
||||
tool_module = _configure_search_tool_trace(
|
||||
monkeypatch,
|
||||
mapping_store=_ToolTraceMappingStore(
|
||||
{"ordinary-kb": {"id": "ordinary-kb", "name": "普通 Wiki"}}
|
||||
),
|
||||
ordinary_service=ordinary_service,
|
||||
assistant_store=None,
|
||||
)
|
||||
runtime = SimpleNamespace(
|
||||
context={
|
||||
"knowledge_retrieval_mode": "smart_reasoning",
|
||||
"llmwiki_knowledge_base_ids": ["ordinary-kb"],
|
||||
"assistant_knowledge_base_ids": [],
|
||||
}
|
||||
)
|
||||
|
||||
trace = json.loads(
|
||||
await tool_module.llmwiki_search_tool.coroutine("散热故障", runtime)
|
||||
)
|
||||
|
||||
assert trace["results"] == []
|
||||
assert trace["zero_result_reason"] == "CLASSIC_MODE_REQUIRED"
|
||||
assert ordinary_service.calls == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("provider_missing", [False, True])
|
||||
async def test_mixed_tool_keeps_ordinary_hit_when_assistant_channel_fails(
|
||||
|
||||
Reference in new issue
Block a user