-
Notifications
You must be signed in to change notification settings - Fork 5
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
LLM을 활용하여 돌봄대상자별 차트 요약하기 #59
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
487d0f2
[관리자 페이지] 요양원 도메인 CRUD (#39)
hyyyh0x faa1dae
Merge remote-tracking branch 'origin/Week5' into Week5_hy_swagger
hyyyh0x a97030d
Merge remote-tracking branch 'origin/Week5' into Week5_hy_swagger
hyyyh0x 705578c
Merge remote-tracking branch 'origin/Week6' into openai
hyyyh0x 591f9a2
Merge remote-tracking branch 'origin/Week7' into openai
hyyyh0x 7bb1829
Merge remote-tracking branch 'origin/Week7' into openai
hyyyh0x 027661a
Merge remote-tracking branch 'origin/Week7' into openai
hyyyh0x 1e2df1e
feat: openai summarization(7일치)
hyyyh0x 93fc7e7
Merge branch 'Week7' into openai
hyyyh0x 203e33d
Merge branch 'Week9' into openai
hyyyh0x 2506a18
[관리자 페이지] 요양원 도메인 CRUD (#39)
hyyyh0x bfd6f1e
feat: openai summarization(7일치)
hyyyh0x 4f9e8bb
feat: swagger, openAi
hyyyh0x a7e8625
Merge remote-tracking branch 'origin/openai' into openai
hyyyh0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions
7
src/main/java/dbdr/domain/chart/repository/ChartRepository.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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package dbdr.domain.chart.repository; | ||
|
||
import dbdr.domain.chart.entity.Chart; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ChartRepository extends JpaRepository<Chart, Long> { | ||
Page<Chart> findAllByRecipientId(Long recipientId, Pageable pageable); | ||
|
||
@Query("SELECT c FROM Chart c WHERE c.recipient.id = :recipientId AND c.createdAt >= :startDate AND c.createdAt <= :endDate") | ||
List<Chart> findByLocalDateTimeAndRecipient(@Param("recipientId") Long recipientId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dbdr.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum ApplicationError { | ||
|
||
//Auth | ||
ROLE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 유저가 ROLE을 가지고 있지 않습니다."), | ||
ACCESS_NOT_ALLOWED(HttpStatus.FORBIDDEN, "접근 권한이 없습니다."), | ||
|
||
// Guardian (보호자) | ||
GUARDIAN_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 보호자를 찾을 수가 없습니다."), | ||
|
||
// Careworker (요양보호사) | ||
CAREWORKER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 요양보호사를 찾을 수가 없습니다."), | ||
|
||
// Recipient (돌봄대상자) | ||
RECIPIENT_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 돌봄대상자를 찾을 수가 없습니다."), | ||
|
||
// Institution (요양원) | ||
INSTITUTION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 요양원을 찾을 수가 없습니다."), | ||
|
||
// 공통 | ||
DUPLICATE_EMAIL(HttpStatus.CONFLICT, "이미 존재하는 이메일입니다."), | ||
DUPLICATE_PHONE(HttpStatus.CONFLICT, "이미 존재하는 전화번호입니다."), | ||
DUPLICATE_CARE_NUMBER(HttpStatus.CONFLICT, "이미 존재하는 장기요양번호입니다."), | ||
DUPLICATE_INSTITUTION_NUMBER(HttpStatus.CONFLICT, "이미 존재하는 요양기관번호입니다."), | ||
INVALID_INPUT(HttpStatus.BAD_REQUEST, "잘못된 입력값입니다."), | ||
|
||
// 시스템 | ||
DATABASE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스 처리 중 오류가 발생했습니다."); | ||
|
||
private final HttpStatus status; | ||
private final String message; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dbdr/global/configuration/OpenAiSummarizationConfig.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,28 @@ | ||
package dbdr.global.configuration; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class OpenAiSummarizationConfig { | ||
|
||
@Value("${openai.api-key}") | ||
private String secretKey; | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Bean | ||
public HttpHeaders httpHeaders() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setBearerAuth(secretKey); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
return headers; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/dbdr/openai/controller/SummaryController.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,35 @@ | ||
package dbdr.openai.controller; | ||
|
||
import dbdr.openai.dto.response.SummaryResponse; | ||
import dbdr.openai.service.SummarizationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "요약 API", description = "차트 하루 요약") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/${spring.app.version}/summary") | ||
public class SummaryController { | ||
|
||
private final SummarizationService summarizationService; | ||
|
||
@Operation(summary = "해당 날짜와 돌봄대상자 id로 요약을 해준다.", description = "시작 날짜만 필수이고, 끝 날짜는 필수가 아니다. 끝나는 날짜를 넣지 않으면 자동으로 하루치만 요약한다.") | ||
@PostMapping | ||
public ResponseEntity<SummaryResponse> getSummary(@RequestParam("recipientId") Long recipientId, | ||
@RequestParam("startDate") | ||
LocalDateTime startDate, | ||
@RequestParam(name = "endDate", required = false) LocalDateTime endDate) { | ||
if(endDate == null){ | ||
endDate = startDate; | ||
} | ||
return ResponseEntity.ok( | ||
summarizationService.getTextAndGetSummary(recipientId, startDate, endDate)); | ||
} | ||
} |
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,12 @@ | ||
package dbdr.openai.dto.etc; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record Choice( | ||
int index, | ||
Message message, | ||
Object logprobs, | ||
String finishReason | ||
) {} |
9 changes: 9 additions & 0 deletions
9
src/main/java/dbdr/openai/dto/etc/CompletionTokensDetails.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,9 @@ | ||
package dbdr.openai.dto.etc; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record CompletionTokensDetails( | ||
int reasoningTokens | ||
) {} |
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,6 @@ | ||
package dbdr.openai.dto.etc; | ||
|
||
public record Message( | ||
String role, | ||
String content | ||
) {} |
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,12 @@ | ||
package dbdr.openai.dto.etc; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record Usage( | ||
int promptTokens, | ||
int completionTokens, | ||
int totalTokens, | ||
CompletionTokensDetails completionTokensDetails | ||
) {} |
14 changes: 14 additions & 0 deletions
14
src/main/java/dbdr/openai/dto/request/ChartDataRequest.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,14 @@ | ||
package dbdr.openai.dto.request; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record ChartDataRequest( | ||
String cognitiveManagement, | ||
String bodyManagement, | ||
String recoveryTraining, | ||
String conditionDisease, | ||
String nursingManagement) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/dbdr/openai/dto/request/OpenAiSummaryRequest.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,7 @@ | ||
package dbdr.openai.dto.request; | ||
|
||
import dbdr.openai.dto.etc.Message; | ||
import java.util.List; | ||
|
||
public record OpenAiSummaryRequest(String model, List<Message> messages) { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/dbdr/openai/dto/response/OpenAiSummaryResponse.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,18 @@ | ||
package dbdr.openai.dto.response; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import dbdr.openai.dto.etc.Choice; | ||
import dbdr.openai.dto.etc.Usage; | ||
import java.util.List; | ||
|
||
@JsonNaming(SnakeCaseStrategy.class) | ||
public record OpenAiSummaryResponse( | ||
String id, | ||
String object, | ||
long created, | ||
String model, | ||
String systemFingerprint, | ||
List<Choice> choices, | ||
Usage usage | ||
) {} |
Oops, something went wrong.
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.
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.
날짜인식이 안되면 바로 예외를 던지는 방식으로 가는건 어떤지용...?
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.
저도 그럴려고 했는데, 인식이 안되는게 7일을 가져올 때, 해당 날짜의 차트가 없으면 인식이 안되는 것 같더라고요.
7일치를 가져오라고 했을때, 3일치만 있으면 인식을 못하더라고요. 그래서 이런식으로 처리했습니다. 아니면 그렇다해도 에러를 던지는게 나을까요?
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.
넹 그게 좋을 것 같아요! -> 사용자가 몇일 치를 가져오는 것을 입력하는 것이고, 입력값이 옳지 못해서 생기는 비즈니스 에러? ( 로그인에서 비밀번호가 틀리면 로그인 실패와 같은) 그런 종류로 생각해서 처리하는 것이 좋을 것 같아요!