Skip to content

Commit d6ada47

Browse files
committed
refactor: del:DTO, GemService,Config & modi:ChatbotService, application.yml
1 parent 0706444 commit d6ada47

File tree

6 files changed

+18
-502
lines changed

6 files changed

+18
-502
lines changed

src/main/java/com/back/domain/chatbot/dto/GeminiRequestDto.java

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/main/java/com/back/domain/chatbot/dto/GeminiResponseDto.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/main/java/com/back/domain/chatbot/service/ChatbotService.java

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
import lombok.extern.slf4j.Slf4j;
99
import org.springframework.ai.chat.client.ChatClient;
1010
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
11-
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
1211
import org.springframework.ai.chat.memory.InMemoryChatMemory;
1312
import org.springframework.ai.chat.model.ChatModel;
1413
import org.springframework.ai.chat.messages.*;
15-
import org.springframework.ai.document.Document;
16-
import org.springframework.ai.vectorstore.VectorStore;
17-
import org.springframework.ai.vectorstore.SearchRequest;
14+
import org.springframework.ai.openai.OpenAiChatOptions;
1815
import org.springframework.beans.factory.annotation.Value;
1916
import org.springframework.core.io.Resource;
2017
import org.springframework.stereotype.Service;
@@ -48,10 +45,10 @@ public class ChatbotService {
4845
@Value("${chatbot.history.max-conversation-count:5}")
4946
private int maxConversationCount;
5047

51-
@Value("${spring.ai.vertex.ai.gemini.chat.options.temperature:0.8}")
52-
private Double temperature;
48+
@Value("${spring.ai.openai.chat.options.temperature:0.8}")
49+
private Float temperature;
5350

54-
@Value("${spring.ai.vertex.ai.gemini.chat.options.max-output-tokens:300}")
51+
@Value("${spring.ai.openai.chat.options.max-tokens:300}")
5552
private Integer maxTokens;
5653

5754
private String systemPrompt;
@@ -72,7 +69,7 @@ public void init() throws IOException {
7269
// ChatClient 고급 설정
7370
this.chatClient = ChatClient.builder(chatModel)
7471
.defaultSystem(systemPrompt)
75-
.defaultOptions(ChatOptionsBuilder.builder()
72+
.defaultOptions(OpenAiChatOptions.builder()
7673
.withTemperature(temperature)
7774
.withMaxTokens(maxTokens)
7875
.build())
@@ -101,13 +98,7 @@ public ChatResponseDto sendMessage(ChatRequestDto requestDto) {
10198
.user(buildUserMessage(requestDto.getMessage(), messageType))
10299
.advisors(new MessageChatMemoryAdvisor(chatMemory, maxConversationCount));
103100

104-
// RAG 기능 활성화 (칵테일 정보 검색)
105-
if (vectorStore != null && shouldUseRAG(messageType)) {
106-
promptBuilder.advisors(new QuestionAnswerAdvisor(
107-
vectorStore,
108-
SearchRequest.defaults().withTopK(3)
109-
));
110-
}
101+
// RAG 기능은 향후 구현 예정 (Vector DB 설정 필요)
111102

112103
// 응답 생성
113104
String response = promptBuilder
@@ -180,31 +171,27 @@ private String buildUserMessage(String userMessage, MessageType type) {
180171
return userMessage + "\n\n" + responseRules;
181172
}
182173

183-
private ChatOptions getOptionsForMessageType(MessageType type) {
174+
private OpenAiChatOptions getOptionsForMessageType(MessageType type) {
184175
return switch (type) {
185-
case RECIPE -> ChatOptionsBuilder.builder()
186-
.withTemperature(0.3) // 정확성 중시
176+
case RECIPE -> OpenAiChatOptions.builder()
177+
.withTemperature(0.3f) // 정확성 중시
187178
.withMaxTokens(400) // 레시피는 길게
188179
.build();
189-
case RECOMMENDATION -> ChatOptionsBuilder.builder()
190-
.withTemperature(0.9) // 다양성 중시
180+
case RECOMMENDATION -> OpenAiChatOptions.builder()
181+
.withTemperature(0.9f) // 다양성 중시
191182
.withMaxTokens(250)
192183
.build();
193-
case QUESTION -> ChatOptionsBuilder.builder()
194-
.withTemperature(0.7) // 균형
184+
case QUESTION -> OpenAiChatOptions.builder()
185+
.withTemperature(0.7f) // 균형
195186
.withMaxTokens(200)
196187
.build();
197-
default -> ChatOptionsBuilder.builder()
188+
default -> OpenAiChatOptions.builder()
198189
.withTemperature(temperature)
199190
.withMaxTokens(maxTokens)
200191
.build();
201192
};
202193
}
203194

204-
private boolean shouldUseRAG(MessageType type) {
205-
// 레시피나 추천 요청시 RAG 활성화
206-
return type == MessageType.RECIPE || type == MessageType.RECOMMENDATION;
207-
}
208195

209196
private String postProcessResponse(String response, MessageType type) {
210197
// 응답 길이 제한 확인
@@ -288,43 +275,3 @@ public void cleanupInactiveSessions() {
288275
}
289276
}
290277

291-
// ChatOptions 빌더 헬퍼 클래스
292-
class ChatOptionsBuilder {
293-
private Double temperature;
294-
private Integer maxTokens;
295-
private Double topP;
296-
private Integer topK;
297-
298-
public static ChatOptionsBuilder builder() {
299-
return new ChatOptionsBuilder();
300-
}
301-
302-
public ChatOptionsBuilder withTemperature(Double temperature) {
303-
this.temperature = temperature;
304-
return this;
305-
}
306-
307-
public ChatOptionsBuilder withMaxTokens(Integer maxTokens) {
308-
this.maxTokens = maxTokens;
309-
return this;
310-
}
311-
312-
public ChatOptionsBuilder withTopP(Double topP) {
313-
this.topP = topP;
314-
return this;
315-
}
316-
317-
public ChatOptionsBuilder withTopK(Integer topK) {
318-
this.topK = topK;
319-
return this;
320-
}
321-
322-
public ChatOptions build() {
323-
// 실제 ChatOptions 객체 생성 로직
324-
// Spring AI의 실제 API에 맞게 조정 필요
325-
return null; // placeholder
326-
}
327-
}
328-
329-
// ChatOptions placeholder (실제 Spring AI API에 맞게 조정 필요)
330-
interface ChatOptions {}

0 commit comments

Comments
 (0)