Skip to content

[ICC-237] OCR로 변경 완료#106

Merged
GulSauce merged 2 commits intodevelopfrom
ICC-237-ocr
Jan 22, 2026
Merged

[ICC-237] OCR로 변경 완료#106
GulSauce merged 2 commits intodevelopfrom
ICC-237-ocr

Conversation

@GulSauce
Copy link
Member

@GulSauce GulSauce commented Jan 22, 2026

📢 설명

해당 Pull Request에 대해 간략하게 설명해주세요!

✅ 체크 리스트

  • 리뷰어가 체크할 내용을 작성해주세요!

Summary by CodeRabbit

Release Notes

  • New Features

    • Added PDF support with URL fetching and page selection capabilities
    • Enhanced quiz generation now embeds PDF content directly into prompts
  • Improvements

    • Optimized batch processing pipeline with improved error and timeout handling
    • More robust API response extraction and parsing logic

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This change refactors the request batching layer to use a new Responses API text extraction flow, restructures chunk generation to work with page counts instead of page lists with embedded text, and enhances the service layer with PDF fetching, page selection, and embedded PDF context in GPT prompts.

Changes

Cohort / File(s) Summary
Request batch adapter
app/adapter/request_batch.py
Replaced request_chat_completion_text with two new functions: request_responses_output_text (extracts text from Responses API output with fallback logic) and request_responses_batch (orchestrates batch requests with timeout handling and per-task exception recovery). Logic now traverses nested response structures to locate message dictionaries and extract text fields.
Service layer integration
app/service/generate_service.py
Added PDF fetching, page count validation, and page selection logic. Introduces per-chunk PDF extraction and base64 embedding into GPT prompts. Switches to request_responses_batch for API calls and alters JSON output from response_format to text-based schema. Includes chunk expansion to ensure max 2 quizzes per chunk. Adds per-chunk PDF cache to avoid redundant extraction.
Chunk utility restructuring
app/util/create_chunks.py
Renamed create_chunks to create_page_chunks with parameters changed from (pages: List[str], total_quiz_count, minimum_page_text_length_per_chunk, max_chunk_count) to (page_count: int, total_quiz_count, max_chunk_count). ChunkInfo model now contains only referenced_pages: List[int] and quiz_count: int (text field removed). Helper function signatures updated to accept page_count directly. Removed add_prefix_suffix function and text-based concatenation logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client/Service
    participant Adapter as Request Adapter
    participant OpenAI as OpenAI API
    participant Parser as Response Parser

    Client->>Adapter: request_responses_batch(requests, timeout)
    Adapter->>Adapter: Start async batch with wait_for
    loop For each request
        Adapter->>OpenAI: Submit GPT request
        OpenAI-->>Adapter: Return Responses object
        Adapter->>Parser: request_responses_output_text(response)
        Parser->>Parser: Try resp.output_text
        alt Found output_text
            Parser-->>Adapter: Return extracted text
        else Search resp.output list
            Parser->>Parser: Find dict with type="message"
            Parser->>Parser: Extract from text/output_text/value keys
            Parser-->>Adapter: Return first non-empty string or empty
        end
    end
    Adapter->>Adapter: Collect results (completed + cancelled tasks)
    Adapter-->>Client: Return List[Optional[str]]
Loading
sequenceDiagram
    participant Service as Generate Service
    participant PDF as PDF Fetcher
    participant Chunks as Chunk Creator
    participant Cache as PDF Cache
    participant Adapter as Request Adapter
    participant GPT as OpenAI API

    Service->>PDF: Fetch PDF from URL
    PDF-->>Service: PDF content + page_count
    Service->>Chunks: create_page_chunks(page_count, quiz_count, max_chunks)
    Chunks-->>Service: List[ChunkInfo] with referenced_pages
    Service->>Service: Expand chunks (ensure ≤2 quizzes per chunk)
    loop For each chunk
        Service->>Cache: Check if pages cached
        alt Not cached
            Service->>PDF: Extract base64 for referenced_pages
            PDF-->>Cache: Store extracted PDF
        else Cached
            Cache-->>Service: Return cached PDF
        end
        Service->>Service: Build prompt with embedded PDF + page hints
        Service->>Adapter: Add to batch request with PDF context
    end
    Service->>Adapter: request_responses_batch(all_requests, timeout)
    Adapter->>GPT: Submit batch with PDF-embedded prompts
    GPT-->>Adapter: Return responses
    Adapter->>Service: Return extracted text results
    Service->>Service: Parse JSON and map to chunks
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 From batches old to responses new,
PDFs embedded in chunks of few,
Page counts dancing where text once stood,
The code hops faster—oh, so good!
hops twitch 📄✨

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@GulSauce GulSauce merged commit 672e7a8 into develop Jan 22, 2026
@coderabbitai coderabbitai bot mentioned this pull request Jan 25, 2026
1 task
@coderabbitai coderabbitai bot mentioned this pull request Feb 1, 2026
1 task
GulSauce added a commit that referenced this pull request Feb 1, 2026
* [ICC-25] 구성 완료

* [ICC-29] 구현 완료

* [ICC-29] 응답 구조 수정

* [ICC-30] 작성 완료

* [ICC-31] 레디스 구독 패턴 구현 완료

* [ICC-31] 레디스 클라이언트를 각 생성마다 생성되게함

* [ICC-31] 필요 없는 의존성 제거

* [ICC-31] requirements.txt 등록

* [ICC-31] 베드락에 요청하는 코드 분리

* [ICC-31] 타입아웃 설정

* [ICC-32] 첫번째 시도

* [ICC-32] 두번째 시도

* [ICC-32] 세번째 시도

* [ICC-32] 네번째 시도

* [ICC-32] 다섯번째 시도

* [ICC-32] 성공

* [ICC-32] 리모트환경에서는 바로 SQS를 보게함

* [ICC-32] 임시 수정

* [ICC-32] boto3 의존성 추가

* [ICC-32] 리전 추가

* [ICC-32] 반응 브랜치 변경

* [ICC-39] 구현 완료

* [ICC-47] quiz parsing (#13)

* [ICC-35] Create 5 Quiz

* ICC-38 json 객체 테스트

* [ICC-47] Redis 주석 처리 해제

---------

Co-authored-by: Oh YoungJe <pine7420@naver.com>

* [ICC-49] Dependency 해결

* [ICC-50] API서버 연결 간 문제 해결 (#15)

* [ICC-50] generation으로 엔드포인트 변경

* [ICC-50] api와 연결간 오류 해결

* [ICC-53] 구현 완료

* [ICC-53] 로거, 전역 예외처리기 추가

* [ICC-53] 일부 수정

* [ICC-57] 구현 완료

* [ICC-67] 응답 구조 수정 완료

* [ICC-63] Webb's DOK

# Conflicts:
#	app/service/generate_service.py

* [ICC-63] 추가 코드 작성

* [ICC-70] api 수정

* [ICC-48] MCP 기능 구현  완료

* [ICC-48] MCP 리서치

* [ICC-48] 엔드포인트 분리

* [ICC-74] 요청 dto 변경

* [ICC-74] 페이지 일부만 가져오기 구현 완료

* [ICC-74] 파워포인트도 적용 완료

* [ICC-74] 불필요한 로그출력 제거

* [ICC-74] 페이지 선택 방식 변경

* [ICC-76] 발생한 문제 해결

* [ICC-76] 코드 수정

* [ICC-80] 프롬프트 추가

* [ICC-80] 프롬프트 추가

* [ICC-80] 롤백

* [ICC-80] 롤백

* [ICC-87] 최대 청크 개수 증가

* [ICC-87] 기본 구조 작성

* [ICC-87] 레디스 분산락 구현

* [ICC-87] 필요 없는  레디스 함수 제거:

* [ICC-87] 한번에 데이터를 넣게 함

* [ICC-99] generate dto 변경

* [ICC-99] 구현 완료

* [ICC-99] generate dto 변경

* [ICC-99] 구현 완료

* [ICC-94] specific explanation 서비스 추가

* [ICC-94] 구현완료

* ICC-112 OX 프롬프트 수정

* [ICC-112] 리팩터링 + BLANK 타입 추가

* [ICC-134] 필요한 프롬프트 추가

* [ICC-164] 작성 완료

* [ICC-167] 프롬프트 수정

* [ICC-167] 프롬프트 변경

* [ICC-167] 프롬프트 변경

* [ICC-167] 프롬프트 변경

* [ICC-167] 프롬프트 변경

* [ICC-167] 프롬프트 변경

* [ICC-167] 프롬프트 수정

* [ICC-167] 프롬프트 수정

* [ICC-167] 프롬프트 수정

* [ICC-167] 잘못된 프롬프트 반환 수정

* [ICC-167] 잘못된 프롬프트 반환 수정

* [ICC-167] 모델 변경

* [ICC-167] 리팩터링 완료

* [ICC-167] 코드 포맷팅

* [ICC-167] 제약사항 반영

* [ICC-167] 프롬프트 수정

* [ICC-167] 리팩터링

* [ICC-175] 도커 컴포즈 제거

* [ICC-175] 개발 깃허브 액션 스크립터 제거

* [ICC-180] 셔플 로직 추가

* [ICC-180] CD 브랜치명 올바르게 변경

* [ICC-189] 타임아웃시 전체 실패가 아닌 일부라도 반환하게함

* [ICC-192] 로직변경완료

* [ICC-194] 선지를 밝히지 말라는 문구 추가

* [ICC-196] 마이그레이션 완료

* [ICC-196] 프롬프트 롤백

* [ICC-196] min quiz size todo에 추가

* [ICC-196] 개행 문구 추가

* [ICC-200] 타입에 따라 셔플하도록 함

* Refactor quiz generation and explanation services; remove unused Bedrock adapter and integrate GPT for specific explanations. Update router to utilize new explanation service.

* [ICC-212] 커서를 통한 1차 리팩터링 완료

* [ICC-212] 어댑터 단순화

* [ICC-212] 블랙 포맷팅 적용

* [ICC-212] 기능 동작하게 수정 완료

* [ICC-212] 개행 프롬프트 추가

* [ICC-212] 구성 완료

* [ICC-215] 수정 완료

* [ICC-216] 구현 코드 작성 완료

* [ICC-216] 객관식 프롬프트 개선

* [ICC-220] 타임아웃 시 해당 문제만 실패하게 조정

* [ICC-221] env 중복참조 수정

* [ICC-220] 환경변수를 없애고 스레드 관점에서 타임아웃으로 조정

* [ICC-220] 불필요한 참조 제거

* [ICC-220] 불필요한 참조 제거

* v 1.5.5 (#97) (#98)

* [ICC-235] 비동기 클라이언트로 변경 완료 (#99)

* v 1.6.0 (#100) (#101)

* [ICC-229] 분리 완료 (#102)

* [ICC-233] 파일 텍스트 부족시 반환 (#103)

* [ICC-233] 구현 완료

* [ICC-230] 페이지 제한 환경변수화

* 계승: v1.6.1 (#105)

* v 1.6.0 (#100)

* v 1.6.1 (#104)

* [ICC-237] OCR로 변경 완료 (#106)

* [ICC-238]  수정 완료 (#108)

* [ICC-238] 수정 완료

* [ICC-241] 구현 완료

* [ICC-241] 최소 3개의 청크는 빨리 응답하도록 함

* [ICC-245] 응답구조 수정

* Hotfixgit add . import 누락 추가

---------

Co-authored-by: 이찬우 <105221020+ChanJinYeon@users.noreply.github.com>
Co-authored-by: Adansonia <lcw061145@gmail.com>
Co-authored-by: lhoju0158 <lhoju0158@gmail.com>
@coderabbitai coderabbitai bot mentioned this pull request Feb 1, 2026
1 task
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.

1 participant