Skip to main content

A LLM utility for working with pdfs

Project description

📄 pdf-invoke

pdf-invoke is a lightweight utility for invoking multimodal LLMs using PDF files or image inputs.

It converts PDFs to images, prepares base64-encoded payloads, and sends them to a LangChain-compatible chat model with optional structured output support.


Features

  • Convert PDFs to images automatically
  • Accept raw image bytes or file paths
  • Prepare multimodal LLM payloads
  • Support structured output via Pydantic models
  • Sync and async invocation
  • MIME type validation for image safety

Installation

pip install pdf-invoke

Quick Example

from langchain_openai import ChatOpenAI
from pdf_invoke import MultiModalLLM

llm = ChatOpenAI(model="gpt-4o")

mm = MultiModalLLM(
    prompt="Extract the key information from this document.",
    model=llm,
)

response = mm.invoke(pdf="example.pdf")

print(response)

Structured Output Example

from pydantic import BaseModel

class ExtractedData(BaseModel):
    title: str
    summary: str

response = mm.invoke(
    pdf="example.pdf",
    output_model=ExtractedData,
)

print(response.title)

Async Usage

response = await mm.ainvoke(pdf="example.pdf")

Accepted Inputs

You may provide:

  • pdf → file path, Path, or raw PDF bytes
  • images → list of image paths or image bytes

Only one of pdf or images may be provided per invocation.


How It Works

  1. PDF inputs are converted to images.
  2. Images are validated and base64 encoded.
  3. A multimodal payload is created.
  4. The payload is sent to a LangChain chat model.
  5. Optional structured output is enforced via Pydantic.

Requirements

  • Python 3.10+
  • LangChain-compatible chat model
  • Pydantic

License

MIT License


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_invoke-0.2.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf_invoke-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pdf_invoke-0.2.0.tar.gz.

File metadata

  • Download URL: pdf_invoke-0.2.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdf_invoke-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e1b47bebe40085dcb99275897b9622e4e36b3e920af240f6730b2cf2ed0f680a
MD5 c71467048e13e846ca0b73a9e0d5ea8a
BLAKE2b-256 95c38d286d019544da5dc173721cc54810141ca7e0b9fe186a23a30cf48c15c6

See more details on using hashes here.

File details

Details for the file pdf_invoke-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pdf_invoke-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdf_invoke-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b386a31f51f2643db2029401acae62a8187fef20e6da6abe58ea318c80761288
MD5 09b418e59f14d8c49c3b5f458b027397
BLAKE2b-256 826da1b0d95d4c416a84f1db6f7ec9c6738edab54ff4b3c3df2ff9ad3bdabcab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page