The parse_pdf function parses a PDF file into a Markdown file and returns the Markdown content along with a list of all extracted image paths.
Signature:
def parse_pdf(
pdf_path: str,
output_dir: str = './',
prompt: Optional[Dict] = None,
api_key: Optional[str] = None,
base_url: Optional[str] = None,
model: str = 'gpt-4o',
verbose: bool = False,
gpt_worker: int = 1
) -> Tuple[str, List[str]]:
Parameters:
pdf_path (str): Path to the PDF file.output_dir (str, default: './'): Output directory to store all images and the Markdown file.api_key (Optional[str], optional): OpenAI API key. If not provided, the OPENAI_API_KEY environment variable will be used.base_url (Optional[str], optional): OpenAI base URL. If not provided, the OPENAI_BASE_URL environment variable will be used. This allows using other services with OpenAI-compatible interfaces (e.g., GLM-4V).model (str, default: 'gpt-4o'): OpenAI API formatted multimodal large model. Supports models like qwen-vl-max, GLM-4V, Yi-Vision, or Azure OpenAI (by setting base_url to the Azure endpoint and using the deployed model name).verbose (bool, default: False): When enabled, the content parsed by the large model is displayed in the command line.gpt_worker (int, default: 1): Number of GPT parsing worker threads. Increase this to speed up parsing on high-performance machines.prompt (dict, optional): A dictionary to provide custom prompts. The dictionary can contain:prompt: Guides the model on processing/converting text content in images.rect_prompt: Handles specific marked areas like tables or images.role_prompt: Defines the model's role for the parsing task.
Returns:
Tuple[str, List[str]]: A tuple containing the Markdown string and a list of image file paths.
content, image_paths = parse_pdf(
pdf_path=pdf_path,
output_dir='./output',
model="gpt-4o",
prompt=prompt,
verbose=False,
)