From 6bda7e3c63a39fb2c068ffd0d1150164407d3026 Mon Sep 17 00:00:00 2001 From: hardwoong Date: Sun, 17 Aug 2025 01:50:26 +0900 Subject: [PATCH] =?UTF-8?q?Refact=20:=20=EC=B1=97=EB=B4=87=20=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../be/domain/chat/converter/ClovaApiConverter.java | 9 +++++---- .../perfact/be/domain/chat/service/ChatServiceImpl.java | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/perfact/be/domain/chat/converter/ClovaApiConverter.java b/src/main/java/com/perfact/be/domain/chat/converter/ClovaApiConverter.java index f9ad2db..ac1412a 100644 --- a/src/main/java/com/perfact/be/domain/chat/converter/ClovaApiConverter.java +++ b/src/main/java/com/perfact/be/domain/chat/converter/ClovaApiConverter.java @@ -36,16 +36,17 @@ public class ClovaApiConverter { private String CLOVA_API_KEY; // 채팅 API 호출을 위한 요청을 생성 - public ClovaChatRequestDTO createChatRequest(String chatbotContext, String userInput) { + public ClovaChatRequestDTO createChatRequest(String chatbotContext, String articleContent, String userInput) { List messages = new ArrayList<>(); messages.add(ClovaChatRequestDTO.Message.builder() .role("system") .content( - "Important: The service name is 'Perfact' (P-e-r-f-a-c-t). This is the correct spelling, not 'Perfect'. You must always use the name 'Perfact' when referring to the service.\n\nYou are a friendly and helpful AI assistant for the 'Perfact' service. Your role is to answer user questions based ONLY on the provided analysis report summary. Do not make up information. If the answer is not in the provided context, say you don't know. Answer in Korean.") + "Important: The service name is 'Perfact' (P-e-r-f-a-c-t). This is the correct spelling, not 'Perfect'. You must always use the name 'Perfact' when referring to the service.\n\nYou are a friendly and helpful AI assistant for the 'Perfact' service. Your role is to answer user questions by referring to both the original news article (`기사 원문`) and the provided AI analysis report summary (`AI 분석 리포트 요약`). Use the original article as the primary source for facts and the analysis report for context about reliability. Do not make up information. If the answer is not in the provided context, say you don't know. Answer in Korean.") .build()); - // 사용자 메시지 (리포트 컨텍스트 + 질문) - String userContent = chatbotContext + "\n\n[질문]\n" + userInput; + // 사용자 메시지 (기사 원문 + 분석 리포트 요약 + 질문) + String userContent = "[분석 대상 기사 원문]\n" + articleContent + "\n\n---\n\n[AI 분석 리포트 요약]\n" + chatbotContext + + "\n\n이 내용을 기반으로 사용자의 질문에 상세히 답변하세요.\n\n---\n\n[사용자 질문]\n" + userInput; messages.add(ClovaChatRequestDTO.Message.builder() .role("user") .content(userContent) diff --git a/src/main/java/com/perfact/be/domain/chat/service/ChatServiceImpl.java b/src/main/java/com/perfact/be/domain/chat/service/ChatServiceImpl.java index 20cc80b..2925991 100644 --- a/src/main/java/com/perfact/be/domain/chat/service/ChatServiceImpl.java +++ b/src/main/java/com/perfact/be/domain/chat/service/ChatServiceImpl.java @@ -55,7 +55,8 @@ public ChatResponseDTO sendMessage(Long reportId, ChatRequestDTO request) { chatLogRepository.save(userChatLog); // 3. Clova API 호출을 위한 요청 생성 - var clovaRequest = clovaApiConverter.createChatRequest(report.getChatbotContext(), request.getUserInput()); + var clovaRequest = clovaApiConverter.createChatRequest(report.getChatbotContext(), report.getArticleContent(), + request.getUserInput()); // 4. Clova API 호출 var clovaResponse = clovaApiConverter.callChatAPI(clovaRequest);