Conversation
- Spring AI의 응답을 .content()이 아닌, .entity()로 변경 - 응답 형식을 json 형식으로 즉, 객체 형태로 받을 수 있도록 강제했습니다.
There was a problem hiding this comment.
Pull request overview
Spring AI 기반 주간 루틴 추천에서 LLM 응답을 문자열(.content) 파싱 대신 객체(.entity)로 직접 역직렬화하도록 리팩터링하여, 응답 처리 로직을 단순화하고 중복 JSON 변환을 줄이려는 PR입니다. 또한 프롬프트 로딩 방식을 Resource 주입으로 변경했습니다.
Changes:
- LLM 응답 처리 방식을
.content()+ 수동 파싱에서.entity(WeeklyRecommendResponse.class)로 변경 toJson(request)중복 호출 제거- 프롬프트 로딩을 파일 read 방식에서
@Value기반Resource주입 방식으로 변경
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
39
to
+44
| stopWatch.start("1. Semaphore Acquire"); | ||
| llmSemaphore.acquire(); | ||
| stopWatch.stop(); | ||
|
|
||
| stopWatch.start("2. Prompt & JSON Prep"); | ||
| String systemMessage = loadPrompt("prompt/routineV4.prompt"); | ||
| String userJson = toJson(request); |
Comment on lines
55
to
72
| stopWatch.start("3. LLM API Call (External)"); | ||
| String llmResponse = chatClient | ||
| .prompt() | ||
| .system(systemMessage) | ||
| .user(userMessage) | ||
| .call() | ||
| .content(); | ||
| stopWatch.stop(); | ||
|
|
||
| stopWatch.start("4. Response Parsing"); | ||
| WeeklyRecommendResponse response = objectMapper.readValue(sanitize(llmResponse), WeeklyRecommendResponse.class); | ||
| WeeklyRecommendResponse response = chatClient | ||
| .prompt() | ||
| .system(s -> s.text(systemPromptResource)) | ||
| .user(userMessage) | ||
| .call() | ||
| .entity(WeeklyRecommendResponse.class); | ||
| stopWatch.stop(); | ||
|
|
||
| log.info(stopWatch.prettyPrint()); | ||
|
|
||
| return response; | ||
|
|
||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new CustomException(LLM_INTERRUPT_ERROR); | ||
| } catch (JsonProcessingException e) { | ||
| log.error("JSON 파싱 실패. Raw Response: {}", e.getMessage()); | ||
| throw new CustomException(INVALID_JSON_RESPONSE); | ||
| } catch (Exception e) { | ||
| log.error("LLM 호출 중 알 수 없는 에러 발생", e); | ||
| throw new CustomException(LLM_INTERRUPT_ERROR); |
| private final ChatClient chatClient; | ||
| private final ObjectMapper objectMapper; | ||
| private final Semaphore llmSemaphore = new Semaphore(5); | ||
| private final int MAX_CONCURRENT_LLM_CALLS = 5; |
Comment on lines
+32
to
+33
| @Value("classpath:prompt/routineV4.prompt") | ||
| private Resource systemPromptResource; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#️⃣ 연관된 이슈
#23
📝 작업 내용
💬 리뷰 요구사항