-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: post - archive join (#41) * feat: 게시물 조회 - 아카이브 id 필터링 추가 (#41) * refactor: 게시물 목록 response 생성 방법 변경 (#41) * refactor: 게시물 생성 로직 수정 (#41) * feat: AI 요약 로직 수정 (#41) * refactor: post detail 조회 response 로직 수정 (#41) * feat: 게시물 수정 API 아카이브 추가 (# 41) * feat: 게시물 재요약 API 수정 (#41) * feat: 메모 API 수정 (#41) * feat: url 수정 (#41) * feat: Swagger server 세팅 (#41) * feat: 게시물 전체 개수 조회 API (#41) * refactor: json parsing 관련 메소드 수정 (#41) * refactor: 네이밍 수정 (#41) * refactor: 단순 로직 수정 (#41) * refactor: summary 클래스, 메소드 명 수정 (#41) * deploy: local로 전환 (#41)
- Loading branch information
Showing
27 changed files
with
383 additions
and
160 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
47 changes: 0 additions & 47 deletions
47
src/main/java/project/backend/business/post/implement/SummaryAIManager.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
src/main/java/project/backend/business/post/implement/SummaryManager.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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; | ||
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions; | ||
import org.springframework.stereotype.Component; | ||
import project.backend.business.post.request.CreatePostServiceRequest; | ||
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 | ||
@RequiredArgsConstructor | ||
public class SummaryManager { | ||
|
||
private final VertexAiGeminiChatModel chatModel; | ||
|
||
public SummaryResultDto summarize(CreatePostServiceRequest createPostServiceRequest) { | ||
Prompt prompt = createPrompt(createPostServiceRequest); | ||
ChatResponse response = chatModel.call(prompt); | ||
String responseContent = response.getResult() | ||
.getOutput() | ||
.getContent(); | ||
|
||
JSONObject jsonObject = JsonParser.parseJsonFromText(responseContent); | ||
Map<String, String> summaryResult = extractSummaryDataFromJson(jsonObject); | ||
|
||
return SummaryResultDto.builder() | ||
.title(summaryResult.get("title")) | ||
.content(summaryResult.get("content")) | ||
.build(); | ||
} | ||
|
||
private Prompt createPrompt(CreatePostServiceRequest createPostServiceRequest) { | ||
SummaryOption options = createPostServiceRequest.getOption(); | ||
|
||
String promptMessage = "URL: " + createPostServiceRequest.getUrl() + "\n" + | ||
"Summarize the website corresponding to the URL below in a blog style according to the following summary conditions.\n" | ||
+ "Please also recommend the title\n" | ||
+ "The answer is given in json format string with title and content as keys.\n" | ||
+ "Translate the content into the summary language!\n" | ||
+ "Summary conditions: \n" | ||
+ "Summary length: " + options.getLevel().getLines() + "\n" | ||
+ "Summary tone:" + options.getTone().getValue() + "\n" | ||
+ "Summary language: " + options.getLanguage().getValue() + "\n" | ||
+ "Summary keywords: " + options.getKeywords(); | ||
|
||
return new Prompt(promptMessage, | ||
VertexAiGeminiChatOptions.builder() | ||
.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); | ||
} | ||
} | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
src/main/java/project/backend/business/post/request/UpdatePostServiceRequest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package project.backend.business.post.request; | ||
|
||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class UpdatePostServiceRequest { | ||
|
||
private final String title; | ||
private final String content; | ||
private final String url; | ||
private final List<String> tagList; | ||
private final Long archiveId; | ||
private final String memo; | ||
} |
Oops, something went wrong.