kangda-robot-backend/ruoyi-fastapi-backend/test/test_intent_guard_unit.py
2026-01-31 16:38:27 +08:00

25 lines
1009 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"