[ICC-53] 로깅 + 전역예외처리기 + 한 프롬프트당 생성 개수 조정#16
Conversation
| try: | ||
| chunks = [] | ||
| chunk_count = quiz_count // 5 | ||
| chunk_count = math.ceil(quiz_count / quiz_count_per_chunk) |
There was a problem hiding this comment.
나누어 떨어지지 않을 때는 청크가 하나 덜 만들어지므로
chunk_count = math.ceil(quiz_count / quiz_count_per_chunk)로 수정합니다
There was a problem hiding this comment.
Pull Request Overview
This PR enhances quiz chunking flexibility and adds timing logs for Bedrock requests.
- Introduces a
quiz_count_per_chunkparameter to control quizzes per chunk withmath.ceillogic. - Updates the generate service to compute per-chunk counts dynamically and inject into the system prompt.
- Adds timing measurement around the
request_to_bedrockcall.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/util/create_chunks.py | Added quiz_count_per_chunk parameter and updated chunk_count logic. |
| app/service/generate_service.py | Implemented dynamic per-chunk quiz counts, f-string prompt update, and timing log. |
Comments suppressed due to low confidence (2)
app/service/generate_service.py:64
- The
contentfield no longer includes the{chunk}placeholder, so the lecture note chunk isn't passed into the prompt. Reintroduce the multi-line string with the{chunk}variable inside.
"",",
app/util/create_chunks.py:4
- The new
quiz_count_per_chunkparameter and updated chunk logic need corresponding unit tests to verify behavior for edge cases (e.g., remainders, exact divides).
async def create_chunks(text: str, quiz_count: int, quiz_count_per_chunk: int) -> list:
| chunks = await create_chunks(full_text, quiz_count) | ||
|
|
||
| for chunk in chunks: | ||
| quiz_count_per_chunk = 5 |
There was a problem hiding this comment.
[nitpick] Hardcoding quiz_count_per_chunk may reduce flexibility; consider sourcing this value from configuration or function parameters.
|
|
||
| for chunk in chunks: | ||
| quiz_count_per_chunk = 5 | ||
| if quiz_count % quiz_count_per_chunk == 0: |
There was a problem hiding this comment.
나누어 떨어질 때는 quiz_count % quiz_count_per_chunk가 0이므로
대신 quiz_count_last_chunk = quiz_count_per_chunk로 둡니다
| if len(chunks) != i: | ||
| cur_quiz_count_per_chunk = quiz_count_per_chunk | ||
| else: | ||
| cur_quiz_count_per_chunk = quiz_count_last_chunk |
There was a problem hiding this comment.
마지막 청크에 대해서만 quiz_count_last_chunk로 퀴즈 개수를 만들어달라고합니다
|
|
||
| start = time.time() | ||
| responses = await request_to_bedrock(bedrock_contents) | ||
| end = time.time() |
There was a problem hiding this comment.
await request_to_bedrock(bedrock_contents)의 수행시간을 로깅합니다
예시: 청크 당 퀴즈 카운트 5개 일 때 소요 시간: 27.2863초
| app.include_router(generate_router) | ||
|
|
||
|
|
||
| @app.exception_handler(Exception) |
There was a problem hiding this comment.
추가) 전역 예외처리기
여러 파일에서 일어나는 raise를 한 곳에서 관리할 수 있는 장점이 있습니다
📢 설명
청크 나누는 로직
코드에 코멘트 달아놓았으니 참조해주세요
타이머
await request_to_bedrock(bedrock_contents)의 수행시간을 로깅합니다예시:
청크 당 퀴즈 카운트 5개 일 때 소요 시간: 27.2863초추가) 로깅
심각도를 구분할 수 있습니다 INFO, WARNING, ERROR
원한다면 파일로 저장, 버퍼링을 통한 시스템콜 횟수 절감 등의 기능도 있습니다
추가) 전역 예외처리기
여러 파일에서 일어나는 raise를 한 곳에서 관리할 수 있는 장점이 있습니다
✅ 체크 리스트