-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] 게시물 아카이브 대응 및 리팩토링 #43
Changes from 1 commit
fc460b3
5b0c312
dcecc40
cb0a9cf
84354a6
847aa1b
bf1578a
67da58b
81aba92
1434bce
2f224db
27fb0e7
34f0518
affb298
9150a91
baabedc
a8545c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package project.backend.business.post.implement; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.springframework.ai.chat.model.ChatResponse; | ||
import org.springframework.ai.chat.prompt.Prompt; | ||
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel; | ||
|
@@ -12,6 +15,8 @@ | |
import project.backend.business.post.request.summary.SummaryOption; | ||
import project.backend.business.post.response.dto.SummaryResultDto; | ||
import project.backend.business.post.util.JsonParser; | ||
import project.backend.common.error.CustomException; | ||
import project.backend.common.error.ErrorCode; | ||
|
||
@Slf4j | ||
@Component | ||
|
@@ -27,11 +32,12 @@ public SummaryResultDto getSummary(CreatePostServiceRequest createPostServiceReq | |
.getOutput() | ||
.getContent(); | ||
|
||
Map<String, String> result = JsonParser.convertString2Json(responseContent); | ||
JSONObject jsonObject = JsonParser.parseJsonFromText(responseContent); | ||
Map<String, String> summaryResult = extractSummaryDataFromJson(jsonObject); | ||
|
||
return SummaryResultDto.builder() | ||
.title(result.get("title")) | ||
.content(result.get("content")) | ||
.title(summaryResult.get("title")) | ||
.content(summaryResult.get("content")) | ||
.build(); | ||
} | ||
|
||
|
@@ -54,4 +60,21 @@ private Prompt getPrompt(CreatePostServiceRequest createPostServiceRequest) { | |
.withModel(VertexAiGeminiChatModel.ChatModel.GEMINI_1_5_FLASH) | ||
.build()); | ||
} | ||
|
||
private Map<String, String> extractSummaryDataFromJson(JSONObject jsonObject) { | ||
try { | ||
String title = jsonObject.getString("title"); | ||
String content = jsonObject.getString("content"); | ||
|
||
Map<String, String> summaryDataMap = new HashMap<>(); | ||
|
||
summaryDataMap.put("title", title); | ||
summaryDataMap.put("content", content); | ||
|
||
return summaryDataMap; | ||
|
||
} catch (JSONException e) { | ||
throw new CustomException(ErrorCode.INVALID_SUMMARY); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. convertString2Json → parseJsonFromText
stripJsonMarkdown → extractJsonContent
result → jsonMap
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2번은 좋은 것 같습니다. 1, 3번의 경우 개발하면서도 애매하다 생각했는데, 좋은 의견 감사합니다. 준섭님 의견 참고하여 명확하게 분리해보았으니 확인 부탁드립니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSONObject 좋네요! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SummaryAIManager → PostSummaryManager
getSummary → summarizePost
getPrompt → createSummaryPrompt
requestMessage → promptMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3, 4번은 좋은 것 같습니다~
1, 2번은 저희 게시물을 요약하는 느낌이 강해서 UrlSummaryManager, summarizeUrl이 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇다면 SummaryManager,
summarize로 변경하는 게 좋을 거 같네요
URL을 강조하거나 명시할 이유는 없는 거 같아요.
클래스 이름에서 URL만이 강조되는데, 요약 기능이 강조돼야 하기 때문에 요약에 더 직관적으로 바꾸는 게 좋다 생각합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다!