forked from kakao-tech-campus-2nd-step3/Team29_BE
-
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.
Merge pull request kakao-tech-campus-2nd-step3#59 from kakao-tech-cam…
…pus-2nd-step3/Develop Feat: AI Client, PDF 처리 및 OCR 기능 구현
- Loading branch information
Showing
56 changed files
with
730 additions
and
85 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
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 notai.client.ai; | ||
|
||
import notai.client.ai.request.LlmTaskRequest; | ||
import notai.client.ai.response.TaskResponse; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import org.springframework.web.service.annotation.PostExchange; | ||
|
||
public interface AiClient { | ||
|
||
@PostExchange(url = "/api/ai/llm") | ||
TaskResponse submitLlmTask(@RequestBody LlmTaskRequest request); | ||
|
||
@PostExchange(url = "/api/ai/stt") | ||
TaskResponse submitSttTask(@RequestPart("audio") MultipartFile audioFile); | ||
} | ||
|
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,34 @@ | ||
package notai.client.ai; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import notai.common.exception.type.ExternalApiException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import static notai.client.HttpInterfaceUtil.createHttpInterface; | ||
import static notai.common.exception.ErrorMessages.AI_SERVER_ERROR; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class AiClientConfig { | ||
|
||
@Value("${ai-server-url}") | ||
private String aiServerUrl; | ||
|
||
@Bean | ||
public AiClient aiClient() { | ||
RestClient restClient = | ||
RestClient.builder().baseUrl(aiServerUrl).requestInterceptor((request, body, execution) -> { | ||
request.getHeaders().setContentLength(body.length); // Content-Length 설정 안하면 411 에러 발생 | ||
return execution.execute(request, body); | ||
}).defaultStatusHandler(HttpStatusCode::isError, (request, response) -> { | ||
String responseBody = new String(response.getBody().readAllBytes()); | ||
log.error("Response Status: {}", response.getStatusCode()); | ||
throw new ExternalApiException(AI_SERVER_ERROR, response.getStatusCode().value()); | ||
}).build(); | ||
return createHttpInterface(restClient, AiClient.class); | ||
} | ||
} |
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,11 @@ | ||
package notai.client.ai.request; | ||
|
||
public record LlmTaskRequest( | ||
String ocrText, | ||
String stt, | ||
String keyboardNote | ||
) { | ||
public static LlmTaskRequest of(String ocrText, String stt, String keyboardNote) { | ||
return new LlmTaskRequest(ocrText, stt, keyboardNote); | ||
} | ||
} |
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 notai.client.ai.request; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record SttTaskRequest( | ||
MultipartFile audioFile | ||
) { | ||
} |
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 notai.client.ai.response; | ||
|
||
import java.util.UUID; | ||
|
||
public record TaskResponse( | ||
UUID taskId, | ||
String taskType | ||
) { | ||
} |
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
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,62 @@ | ||
package notai.common.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum ErrorMessages { | ||
|
||
// annotation | ||
ANNOTATION_NOT_FOUND("주석을 찾을 수 없습니다."), | ||
|
||
// document | ||
DOCUMENT_NOT_FOUND("자료를 찾을 수 없습니다."), | ||
|
||
// ocr | ||
OCR_RESULT_NOT_FOUND("OCR 데이터를 찾을 수 없습니다."), | ||
OCR_TASK_ERROR("PDF 파일을 통해 OCR 작업을 수행하는데 실패했습니다."), | ||
|
||
// folder | ||
FOLDER_NOT_FOUND("폴더를 찾을 수 없습니다."), | ||
|
||
// llm task | ||
LLM_TASK_LOG_NOT_FOUND("AI 작업 기록을 찾을 수 없습니다."), | ||
LLM_TASK_RESULT_ERROR("AI 요약 및 문제 생성 중에 문제가 발생했습니다."), | ||
|
||
// problem | ||
PROBLEM_NOT_FOUND("문제 정보를 찾을 수 없습니다."), | ||
|
||
// summary | ||
SUMMARY_NOT_FOUND("요약 정보를 찾을 수 없습니다."), | ||
|
||
// member | ||
MEMBER_NOT_FOUND("회원 정보를 찾을 수 없습니다."), | ||
|
||
// recording | ||
RECORDING_NOT_FOUND("녹음 파일을 찾을 수 없습니다."), | ||
|
||
// external api call | ||
KAKAO_API_ERROR("카카오 API 호출에 예외가 발생했습니다."), | ||
AI_SERVER_ERROR("AI 서버 API 호출에 예외가 발생했습니다."), | ||
|
||
// auth | ||
INVALID_ACCESS_TOKEN("유효하지 않은 토큰입니다."), | ||
INVALID_REFRESH_TOKEN("유요하지 않은 Refresh Token입니다."), | ||
EXPIRED_REFRESH_TOKEN("만료된 Refresh Token입니다."), | ||
INVALID_LOGIN_TYPE("지원하지 않는 소셜 로그인 타입입니다."), | ||
|
||
// json conversion | ||
JSON_CONVERSION_ERROR("JSON-객체 변환 중에 오류가 발생했습니다."), | ||
|
||
// etc | ||
INVALID_FILE_TYPE("지원하지 않는 파일 형식입니다."), | ||
FILE_NOT_FOUND("존재하지 않는 파일입니다."), | ||
FILE_SAVE_ERROR("파일을 저장하는 과정에서 오류가 발생했습니다."), | ||
INVALID_AUDIO_ENCODING("오디오 파일이 잘못되었습니다.") | ||
; | ||
|
||
private final String message; | ||
|
||
ErrorMessages(String message) { | ||
this.message = message; | ||
} | ||
} |
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
Oops, something went wrong.