Skip to content

Commit

Permalink
Merge pull request #39 from SWM-SMART/feat/#38
Browse files Browse the repository at this point in the history
AI 요청 수정
  • Loading branch information
noparamin authored Nov 7, 2023
2 parents 8135b09 + 4047dca commit d1eaf6c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public ResponseEntity<?> getAudioFile(@PathVariable(value = "documentID") long d
}

@PostMapping("/testffff")
public ResponseEntity<?> test(@RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
public ResponseEntity<?> test(@RequestParam("audioFile") MultipartFile audioFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
String body = """
{
"segments":[
Expand Down Expand Up @@ -144,14 +144,20 @@ public ResponseEntity<?> test(@RequestHeader("Authorization") String accessToken
]
}
""";
ResponseEntity<String> response1 = new ResponseEntity<>(body, HttpStatus.OK);
List<SttData> data = sttService.getSTTData(response1);
System.out.println(data.get(0).getText());
lectureNoteService.createLectureNote(100L, data, "aa");
String path = "naver.com";
SttDto body2 = fileService.createResponseBody(path, data);
ResponseEntity<?> ss = new ResponseEntity<>(body2, HttpStatus.OK);
return ss;
// ResponseEntity<String> response1 = new ResponseEntity<>(body, HttpStatus.OK);
// List<SttData> data = sttService.getSTTData(response1);
// System.out.println(data.get(0).getText());
// lectureNoteService.createLectureNote(100L, data, "aa");
// String path = "naver.com";
// SttDto body2 = fileService.createResponseBody(path, data);
// ResponseEntity<?> ss = new ResponseEntity<>(body2, HttpStatus.OK);
// return ss;
S3Dto s3Dto = new S3Dto(audioFile, 26L);
String path = awsS3Uploader.uploadFile(s3Dto);
int startIndex = path.indexOf("application/pdf/") + "application/pdf/".length();
String extractedString = path.substring(startIndex);
System.out.println(extractedString);
return new ResponseEntity<>(HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ResponseEntity<?> updateKeywords(@PathVariable(value = "documentID") long
@GetMapping("/documents/{documentID}/mindmap/keyword/{keywordLabel}")
@Operation(summary = "키워드 질문", description = "키워드 AI에 질문")
public ResponseEntity<?> getAnswer(@PathVariable(value = "documentID") long documentId, @PathVariable String keywordLabel, @RequestHeader("Authorization") String accessToken) throws JsonProcessingException {
ResponseEntity<String> responseEntity = mindmapService.getKeywordAnswer(documentId, keywordLabel);
ResponseEntity<String> responseEntity = requestService.requestAnswer(documentId, keywordLabel);

return new ResponseEntity<>(responseEntity, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.smart.watchboard.dto.FileDto;
import com.smart.watchboard.dto.KeywordsDto;
import com.smart.watchboard.dto.S3Dto;
import com.smart.watchboard.service.FileService;
import com.smart.watchboard.service.MindmapService;
import com.smart.watchboard.service.RequestService;
import com.smart.watchboard.service.WhiteboardService;
import com.smart.watchboard.service.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,12 +30,15 @@ public class LearningFileController {
private final FileService fileService;
private final RequestService requestService;
private final WhiteboardService whiteboardService;
private final SummaryService summaryService;

@PostMapping("/{documentID}/pdf")
public ResponseEntity<?> uploadLearningFile(@PathVariable(value = "documentID") long documentId, @RequestParam("pdf") MultipartFile pdfFile, @RequestHeader("Authorization") String accessToken) throws UnsupportedAudioFileException, IOException {
S3Dto s3Dto = new S3Dto(pdfFile, documentId);
String path = awsS3Uploader.uploadFile(s3Dto);
ResponseEntity<String> responseEntity = requestService.requestPdfKeywords(path);
String summary = requestService.requestPdfSummary(path);
summaryService.createSummary(documentId, summary);
whiteboardService.setDataType(documentId, "pdf");

return new ResponseEntity<>(responseEntity.getBody(), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MindmapService {

private final MindmapRepository mindmapRepository;
private final WhiteboardService whiteboardService;
private final RequestService requestService;
//private final RequestService requestService;

public void createMindmap(ResponseEntity<String> responseEntity, Long documentId) throws JsonProcessingException {
Document document = whiteboardService.findDoc(documentId);
Expand Down Expand Up @@ -80,7 +80,7 @@ public void updateKeywords(KeywordsDto keywordsDto, Long documentId) {
mindmapRepository.save(updatedMindmap);
}

public ResponseEntity<String> getKeywordAnswer(Long documentId, String keywordLabel) throws JsonProcessingException {
return requestService.requestAnswer(documentId, keywordLabel);
}
// public ResponseEntity<String> getKeywordAnswer(Long documentId, String keywordLabel) throws JsonProcessingException {
// return requestService.requestAnswer(documentId, keywordLabel);
// }
}
18 changes: 14 additions & 4 deletions src/main/java/com/smart/watchboard/service/RequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class RequestService {
private final SummaryService summaryService;

public ResponseEntity<String> requestPdfKeywords(String filePath) {
int startIndex = filePath.indexOf("application/pdf/") + "application/pdf/".length();
String fileName = filePath.substring(startIndex);

RestTemplate restTemplate = new RestTemplate();
String url = aiUrl + "/keywords";
// 요청 헤더 추가
Expand All @@ -42,7 +45,7 @@ public ResponseEntity<String> requestPdfKeywords(String filePath) {
"db": "s3"
}
}
""".formatted(filePath);
""".formatted(fileName);
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);

// 요청 보내기
Expand Down Expand Up @@ -77,7 +80,10 @@ public ResponseEntity<String> requestSTTKeywords(String text) {
return responseEntity;
}

public ResponseEntity<String> requestPdfSummary(String filePath) {
public String requestPdfSummary(String filePath) throws JsonProcessingException {
int startIndex = filePath.indexOf("application/pdf/") + "application/pdf/".length();
String fileName = filePath.substring(startIndex);

RestTemplate restTemplate = new RestTemplate();
String url = aiUrl + "/summary";
//String url = "http://echo.jsontest.com/key/value/one/two";
Expand All @@ -93,13 +99,17 @@ public ResponseEntity<String> requestPdfSummary(String filePath) {
"db": "s3"
}
}
""".formatted(filePath);
""".formatted(fileName);
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);

// 요청 보내기
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
//ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
return responseEntity;
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseEntity.getBody());
String text = jsonNode.get("summary").asText();

return text;
}

public String requestSTTSummary(String sttResult) throws JsonProcessingException {
Expand Down

0 comments on commit d1eaf6c

Please sign in to comment.