fix(chat): answer greetings without search

This commit is contained in:
2026-10-06 15:31:42 +09:00
parent 6d3a1be428
commit 8ea597a40b
2 changed files with 15 additions and 0 deletions
@@ -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 {
@@ -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"