-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from dongyeon1031/main
Feat: 학교공지 요약기능 추가
- Loading branch information
Showing
12 changed files
with
94 additions
and
93 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
Empty file.
26 changes: 18 additions & 8 deletions
26
src/main/java/com/example/bigbrotherbe/global/llm/controller/SummarizationController.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,17 +1,27 @@ | ||
package com.example.bigbrotherbe.global.llm.controller; | ||
import com.example.bigbrotherbe.global.llm.service.SageMakerService; | ||
import com.example.bigbrotherbe.domain.campusNotice.dto.CampusNoticeResponse; | ||
import com.example.bigbrotherbe.domain.campusNotice.service.CampusNoticeService; | ||
import com.example.bigbrotherbe.global.common.exception.response.ApiResponse; | ||
import com.example.bigbrotherbe.global.llm.dto.SummarizeRequest; | ||
import com.example.bigbrotherbe.global.llm.service.BedrockService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static com.example.bigbrotherbe.global.common.exception.enums.SuccessCode.SUCCESS; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/admin/llm") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/summarize") | ||
public class SummarizationController { | ||
|
||
@Autowired | ||
private SageMakerService sageMakerService; | ||
private final BedrockService bedrockService; | ||
private final CampusNoticeService campusNoticeService; | ||
|
||
@GetMapping() | ||
public String summarize(@RequestPart(value = "text") String inputText) { | ||
return sageMakerService.getSummary(inputText); | ||
public ResponseEntity<ApiResponse<String>> getSummarizeById(@RequestBody SummarizeRequest summarizeRequest) { | ||
CampusNoticeResponse campusNoticeResponse = campusNoticeService.getCampusNoticeById(summarizeRequest.getCampusNoticeId()); | ||
String content = campusNoticeResponse.getContent(); | ||
String response = bedrockService.getSummary(content); | ||
return ResponseEntity.ok(ApiResponse.success(SUCCESS, response)); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/bigbrotherbe/global/llm/dto/SummarizeRequest.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,8 @@ | ||
package com.example.bigbrotherbe.global.llm.dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SummarizeRequest { | ||
Long campusNoticeId; | ||
} |
31 changes: 0 additions & 31 deletions
31
src/main/java/com/example/bigbrotherbe/global/llm/sagemakerConfig/SagemakerConfig.java
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/bigbrotherbe/global/llm/service/BedrockService.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,5 @@ | ||
package com.example.bigbrotherbe.global.llm.service; | ||
|
||
public interface BedrockService { | ||
public String getSummary(String content); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/example/bigbrotherbe/global/llm/service/BedrockServiceImpl.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,49 @@ | ||
package com.example.bigbrotherbe.global.llm.service; | ||
import com.amazonaws.services.lambda.AWSLambda; | ||
import com.amazonaws.services.lambda.model.InvokeRequest; | ||
import com.amazonaws.services.lambda.model.InvokeResult; | ||
import com.example.bigbrotherbe.global.common.constant.Constant; | ||
import com.example.bigbrotherbe.global.common.exception.BusinessException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.FAIL_TO_JSON_PARSING; | ||
import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.LAMBDA_FUNCTION_ERROR; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BedrockServiceImpl implements BedrockService{ | ||
|
||
private final AWSLambda awsLambda; | ||
private final ObjectMapper objectMapper; | ||
|
||
public String getSummary(String content) { | ||
String payload = this.createPayload(content); | ||
InvokeRequest invokeRequest = new InvokeRequest() | ||
.withFunctionName(Constant.LLM.FUNCTION_NAME) | ||
.withPayload(payload); | ||
|
||
InvokeResult invokeResult = awsLambda.invoke(invokeRequest); | ||
String jsonResponse = new String(invokeResult.getPayload().array()); | ||
|
||
try{ | ||
JsonNode root = objectMapper.readTree(jsonResponse); | ||
return root.get("body").asText(); | ||
} catch ( | ||
JsonProcessingException e) { | ||
throw new BusinessException(FAIL_TO_JSON_PARSING); | ||
} catch (NullPointerException e) { | ||
throw new BusinessException(LAMBDA_FUNCTION_ERROR); | ||
} | ||
} | ||
|
||
private String createPayload(String content) { | ||
return "{" + | ||
"\"content\": \"" + content + "\"" + | ||
"}"; | ||
} | ||
|
||
} |
38 changes: 0 additions & 38 deletions
38
src/main/java/com/example/bigbrotherbe/global/llm/service/SageMakerService.java
This file was deleted.
Oops, something went wrong.