[고객지원 챗봇 만들기] 김수민 제출합니다.#4
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a RAG-based chatbot using Spring AI, featuring document loading and chunking for FAQs, policies, and chat logs, alongside a REST API for chat interactions. It also refactors Gradle environment variable loading and updates the Python evaluation script for detailed result tracking. Review feedback identifies a potential NullPointerException in response handling, suggests externalizing hardcoded file paths to configuration properties, and recommends implementing vector data caching to reduce application startup latency and API costs.
| return new ChatAnswerResponse( | ||
| response.getResult().getOutput().getText(), | ||
| new ChatAnswerResponse.TokenUsage( | ||
| usage == null || usage.getPromptTokens() == null ? 0 : usage.getPromptTokens(), | ||
| usage == null || usage.getCompletionTokens() == null ? 0 : usage.getCompletionTokens(), | ||
| usage == null || usage.getTotalTokens() == null ? 0 : usage.getTotalTokens() | ||
| ) | ||
| ); |
There was a problem hiding this comment.
LLM 응답 결과가 비어있을 경우 response.getResult()가 null을 반환하여 NullPointerException이 발생할 수 있습니다. 응답 존재 여부를 확인한 후 안전하게 텍스트를 추출하도록 개선이 필요합니다.
String answer = (response.getResult() != null && response.getResult().getOutput() != null)
? response.getResult().getOutput().getText()
: "고객센터에 문의해주세요.";
return new ChatAnswerResponse(
answer,
new ChatAnswerResponse.TokenUsage(
usage == null || usage.getPromptTokens() == null ? 0 : usage.getPromptTokens(),
usage == null || usage.getCompletionTokens() == null ? 0 : usage.getCompletionTokens(),
usage == null || usage.getTotalTokens() == null ? 0 : usage.getTotalTokens()
)
);| private static final Path FAQ_DIRECTORY = Path.of("data/layer1_faq"); | ||
| private static final Path CURRENT_POLICY_DIRECTORY = Path.of("data/layer2_policies/current"); | ||
| private static final Path CHATLOG_DIRECTORY = Path.of("data/layer3_chatlogs"); |
| ) | ||
| ); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to parse chatlog line in file: " + path.getFileName(), e); |
There was a problem hiding this comment.
|
|
||
| @PostConstruct | ||
| void loadFaqContext() { | ||
| vectorStore.add(documentLoader.load()); |
구현 내용
ChatClient를 사용해/api/chat에서 사용자 질문에 대한 답변을 생성하도록 구현했습니다.DocumentLoader에서 읽고 Spring AIDocument로 변환했습니다.###, 정책은##기준으로 chunking하고, 상담 로그는 JSONL을ObjectMapper로 파싱해agent_accuracy=correct인 데이터만 사용했습니다.promptTokens,completionTokens,totalTokens를 포함했습니다.