Skip to content
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

feat: OCR 영수증 텍스트를 파싱한다 #16

Open
wants to merge 4 commits into
base: inpink/#5
Choose a base branch
from

Conversation

inpink
Copy link
Member

@inpink inpink commented Jan 28, 2025

요약

  • OCR 영수증 텍스트를 받아와서, 영수증 내용을 파싱하여 응답한다
  • OCR이 인식한 영수증의 텍스트의 길이가 길고 특수문자도 포함되고, LLM 호출해서 파싱데이터 생성해내기 때문에 GET에서 POST로 변경한다

어떻게 구현했는지

  • 리뷰 생성과 다르게 스트리밍을 지원할 필요가 없기 때문에 동기 블럭킹 방식의 RestClient 사용
  • AI에게 정해진 JSON 형태로만 응답달라고 요청함. 응답값은 String으로 오기때문에 Kotlin용 Jackson 의존성 추가하여 응답 객체에 매핑함

다음 계획

  • 생성 실패 시 재시도
    • OCR 텍스트가 엉망인건지, AI가 잘못 생성해낸건지 판단 후 후자만 재생성해야 함

이슈번호

close #15

@inpink inpink requested a review from devxb as a code owner January 28, 2025 19:19
@inpink inpink self-assigned this Jan 28, 2025
Copy link
Collaborator

@devxb devxb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! 🥳🥳

gradle.properties Outdated Show resolved Hide resolved
gradle/core.gradle Outdated Show resolved Hide resolved
src/main/kotlin/me/misik/api/api/response/KeyValuePair.kt Outdated Show resolved Hide resolved
src/main/kotlin/me/misik/api/api/response/KeyValuePair.kt Outdated Show resolved Hide resolved
src/main/kotlin/me/misik/api/app/CreateReviewFacade.kt Outdated Show resolved Hide resolved
)

if (parsedOcr.parsed.isEmpty()) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException을 던지고, ExceptionHandler에서 http status code를 정의하는건 어떨까요?
app layer에서 어떻게 통신했는지 (ex. 컨슈머인지, HTTP인지) 알 필요가 없다고 생각합니다.

return parsedOcr
} catch (e: Exception) {
logger.error("Failed to parse ocr text.", e)
throw ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500 코드같은 경우는 IllegalStateException을 던지고 ExceptionHandler에서 잡을 수 있을것 같아요.

src/main/kotlin/me/misik/api/app/CreateReviewFacade.kt Outdated Show resolved Hide resolved
.baseUrl(chatbotUrl)
.defaultHeaders { headers ->
headers.add(HttpHeaders.AUTHORIZATION, "Bearer $authorization")
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACCEPT를 명시하지않으면 기본으로 application/json으로 오나요??

@@ -63,6 +73,27 @@ class CreateReviewFacade(
}
}

fun parseOcrText(deviceId: String, ocrText: OcrTextRequest): ParsedOcrResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseOcrText 메소드는 CreateReviewFacade 객체보다 다른 객체에 있는게 자연스러울 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants