강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

nathan님의 프로필 이미지
nathan

작성한 질문수

LangGraph를 활용한 AI Agent 개발 (feat. MCP)

2.2 강의 질문(markdown 생성관련)

작성

·

15

0

선생님 안녕하세요

좋은 강의 감사합니다.

 

바로 아래 질문 올린 수강생입니다. 강의에 나온대로 openai api를 사용해서 pdf 파일을 markdown으로 변환하는데, 아래와 같은 오류(?) 메시지가 뜨다가, 맨 마지막에는 결과물이 나오긴 합니다.

import nest_asyncio
nest_asyncio.apply()

from pyzerox import zerox
import os
import json
import asyncio


kwargs = {}

## Vision 모델에 사용할 시스템 프롬프트
custom_system_prompt = None

model = "gpt-4o-mini"
# os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")


# 메인 비동기 진입점을 정의합니다
async def main():
    file_path = "./documents/income_tax.pdf" ## 로컬 파일 경로 및 파일 URL 지원

    ## 일부 페이지 또는 전체 페이지를 처리
    select_pages = None ## 전체는 None, 특정 페이지는 int 또는 list(int) 페이지 번호 (1부터 시작)

    output_dir = "./documents" ## 통합된 마크다운 파일을 저장할 디렉토리
    result = await zerox(file_path=file_path, model=model, output_dir=output_dir,
                        custom_system_prompt=custom_system_prompt, select_pages=select_pages, **kwargs)
    return result


# 메인 함수를 실행합니다:
result = asyncio.run(main())

# 마크다운 결과를 출력합니다
print(result)

에러 메시지(실제는 이런게 여러번 반복이 됨)


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/newLiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.

ERROR:root:Failed to process image Error: Error in Completion Response. Error: litellm.RateLimitError: RateLimitError: OpenAIException - Rate limit reached for gpt-4o-mini in organization org-ZlBA2iz8ZXx6PbxDnPFaTYOK on tokens per min (TPM): Limit 200000, Used 200000, Requested 807. Please try again in 242ms. Visit https://platform.openai.com/account/rate-limits to learn more. Please check the status of your model provider API status. ERROR:root:Failed to process image Error: Error in Completion Response. Error: litellm.RateLimitError: RateLimitError: OpenAIException - Rate limit reached for gpt-4o-mini in organization org-ZlBA2iz8ZXx6PbxDnPFaTYOK on tokens per min (TPM): Limit 200000, Used 200000, Requested 807. Please try again in 242ms. Visit https://platform.openai.com/account/rate-limits to learn more. Please check the status of your model provider API status. ERROR:root:Failed to process image Error: Error in Completion Response. Error: litellm.RateLimitError: RateLimitError: OpenAIException - Rate limit reached for gpt-4o-mini in organization org-ZlBA2iz8ZXx6PbxDnPFaTYOK on tokens per min (TPM): Limit 200000, Used 200000, Requested 807. Please try again in 242ms. Visit https://platform.openai.com/account/rate-limits to learn more. Please check the status of your model provider API status.

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/newLiteLLM.Info: If you need to debug this error, use litellm._turn_on_debug()'. Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new LiteLLM.Info: If you need to debug this error, use litellm._turn_on_debug()'. Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/newLiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.

ERROR:root:Failed to process image Error: Error in Completion Response. Error: litellm.RateLimitError: RateLimitError: OpenAIException - Rate limit reached for gpt-4o-mini in organization org-ZlBA2iz8ZXx6PbxDnPFaTYOK on tokens per min (TPM): Limit 200000, Used 200000, Requested 807. Please try again in 242ms. Visit https://platform.openai.com/account/rate-limits to learn more. Please check the status of your model provider API status.

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/newLiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.

ERROR:root:Failed to process image Error: Error in Completion Response. Error: litellm.RateLimitError: RateLimitError: OpenAIException - Rate limit reached for gpt-4o-mini in organization org-ZlBA2iz8ZXx6PbxDnPFaTYOK on tokens per min (TPM): Limit 200000, Used 200000, Requested 807. Please try again in 242ms. Visit https://platform.openai.com/account/rate-limits to learn more. Please check the status of your model provider API status.

- 결과물 : ZeroxOutput(completion_time=69952.953, file_name='income_tax', input_tokens=626909, output_tokens=17668, pages=[Page(content='# 소득세법\n[시행 2025. 1. 1.] [법률 제20615호, 2024. 12. 31., 일부개정]\ (이후 생략)

--> 근데 생성된 markdown 파일을 보니 18조 정도밖에 생성이 안되어있고, 그 이후 내용은 모두 없더라고요.

 

  1. 이건 그냥 token의 문제 때문에 openai api가 너무 큰 pdf파일을 처리하지 못하면서 발생하는 문제인가요?

  2. 강의에서는 아무런 문제 없이 변환이 되는데, 갑자기 안되는 이유가 있을까요?

  3. 강의 소스코드에 제공된 파일의 markdown 파일에는 소득세법의 전 내용이 들어가있던데, 그걸 사용하면 강의 따라가는데는 문제가 없어보입니다. 맞나요?

 

 

 

답변 2

0

강병진님의 프로필 이미지
강병진
지식공유자

안녕하세요! 좋은 질문 감사합니다. 답변을 드려보자면

  1. 올려주신 에러메시지로 볼 때 rate limit 이라면, OpenAI에 충분한 금액을 충전하지 않아서 분당 토큰양 제한에 걸린 것 같아요.

    1. Limit 200000, Used 200000, Requested 807. Please try again in 242ms

    2. 분당 20만 토큰을 사용할 수 있는데, 이미 다 썼으니 242ms뒤에 다시 시도하라는 내용입니다. 그래서 일부 처리된 후에 멈춘 것 같아요

    3. 자세한 내용은Rate Limit - Usage Tiers를 참고해주세요

  2. 강의에서 문제 없이 진행되는 이유는 제가 nathan 님보다 OpenAI tier가 높아서라고 봐주시면 되겠습니다.

  3. 소스코드에 있는 파일을 활용하셔도 강의를 수강하시는데는 문제 없습니다

0

안녕하세요, 인프런 AI 인턴입니다. nathan님께서 제기한 질문은 PDF 파일의 마크다운 변환 과정에서의 오류 메시지와 부분적으로 생성된 결과물에 대한 내용입니다. 해당 문제에 대한 해결 방법과 추가적인 정보를 제공해 드리겠습니다.

1. 토큰 처리 문제에 대해

초과된 토큰 사용량으로 인해 발생하는 Rate Limit 오류는 OpenAI API의 사용 빈도를 초과할 때 나타납니다. 주어진 한도 내에서 처리 가능한 데이터가 제한되기 때문에 대규모 파일 처리 시 주의가 필요합니다.

  • 원인: OpenAI API의 요청 수와 토큰 처리량 제한 때문입니다. 특정 시간 내에 한 번에 너무 많은 데이터를 요청하고, 사용 허용량을 초과할 때 발생합니다.
  • 해결 방법:
    • 데이터 크기를 줄이거나, 처리 단위를 더 작게 나누어 작업해야 합니다. 현재 코드는 전체 페이지를 한꺼번에 처리하여 과도한 토큰 소비가 이루어질 수 있습니다.
    • 페이지를 특정 부분씩 분할 처리하고 중간 결과를 저장하여 병합하는 전략을 고려하세요.

2. 강의와의 차이점

강의 촬영 당시와 현재 사용 가능한 API의 제한 및 성능이 다를 수 있습니다. OpenAI API의 토큰 제한은 사용자의 설정이나 요금제에 따라 차이가 있을 수 있습니다.

3. 제공된 Markdown 파일 사용 여부

제공된 Markdown 파일을 이용하여 강의를 따라가면 큰 문제가 없을 것입니다. 강의에서는 전체 내용을 다루는 대신, 핵심적인 부분에 초점을 맞추기 때문에 제공된 자료를 통해 학습을 진행하실 수 있습니다.

참고 자료

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해 드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

nathan님의 프로필 이미지
nathan

작성한 질문수

질문하기