From 8ea597a40b4f8e307a151290a1eef5cfd94af6c8 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Tue, 6 Oct 2026 15:31:42 +0900 Subject: [PATCH] fix(chat): answer greetings without search --- B01_Dashboard/B01_Dashboard_Knowledge_Chat.py | 3 +++ resources/tester/test_b01_knowledge_chat.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/B01_Dashboard/B01_Dashboard_Knowledge_Chat.py b/B01_Dashboard/B01_Dashboard_Knowledge_Chat.py index 42179624c..b7ce3006a 100644 --- a/B01_Dashboard/B01_Dashboard_Knowledge_Chat.py +++ b/B01_Dashboard/B01_Dashboard_Knowledge_Chat.py @@ -76,6 +76,9 @@ def search(question: str) -> list[dict[str, str]]: @router.post("") async def ask_knowledge_chat(payload: ChatRequest, _session=Depends(verify_session)): + if re.fullmatch(r"\s*(안녕|안녕하세요|하이|hi|hello)[!!??.\s]*", payload.question, re.I): + return {"answer": "안녕하세요! 법령이나 지침에 대해 궁금한 점을 물어보세요.", "sources": []} + sources = search(payload.question) if not sources: return { diff --git a/resources/tester/test_b01_knowledge_chat.py b/resources/tester/test_b01_knowledge_chat.py index bf7667c07..bd9c15873 100644 --- a/resources/tester/test_b01_knowledge_chat.py +++ b/resources/tester/test_b01_knowledge_chat.py @@ -3,6 +3,18 @@ import asyncio from B01_Dashboard import B01_Dashboard_Knowledge_Chat as chat +def test_greeting_answers_without_search_or_api_key(monkeypatch): + monkeypatch.delenv("GEMINI_API_KEY", raising=False) + monkeypatch.setattr( + chat, "search", lambda _question: (_ for _ in ()).throw(AssertionError("searched")) + ) + result = asyncio.run(chat.ask_knowledge_chat(chat.ChatRequest(question="안녕!"), {})) + assert result == { + "answer": "안녕하세요! 법령이나 지침에 대해 궁금한 점을 물어보세요.", + "sources": [], + } + + def test_chat_searches_all_knowledge_markdown_except_excluded_folders(monkeypatch, tmp_path): public = tmp_path / "original" / "법률" guide = tmp_path / "technical_info"