25 lines
1009 B
Python
25 lines
1009 B
Python
import pytest
|
||
|
||
from config.env import SearchConfig
|
||
from module_admin.service.search_service import SearchService
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
async def test_classify_intent_smalltalk_forces_rag(monkeypatch):
|
||
# 防止触发外部请求:即便配置里有 key,也应被 smalltalk guard 拦住
|
||
monkeypatch.setattr(SearchConfig, "ZHIPUAI_API_KEY", "dummy")
|
||
|
||
assert await SearchService.classify_intent("hello") == "RAG"
|
||
assert await SearchService.classify_intent("你好") == "RAG"
|
||
assert await SearchService.classify_intent("谢谢") == "RAG"
|
||
assert await SearchService.classify_intent("再见") == "RAG"
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
async def test_classify_intent_fallback_keyword_router(monkeypatch):
|
||
# 关闭意图模型,走 should_handle 分支
|
||
monkeypatch.setattr(SearchConfig, "ZHIPUAI_API_KEY", "")
|
||
|
||
assert await SearchService.classify_intent("今天上海的天气怎么样") == "SEARCH"
|
||
assert await SearchService.classify_intent("康达什么时候成立的") == "RAG"
|