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.1.3.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.1.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_invoke-0.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 f32833f25117ea5c162e2cbe5e3c98080bb93bce28ffd8218da803773487ce11
MD5 203dd268f2a2b09375be85c79fe795f3
BLAKE2b-256 7dd5fafa9b19a02a2582680345041a257f271ecd94608ad23dab0c74278d8e58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_invoke-0.1.3-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.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 154cfcd7c535e29395292e02ac2dc75db0b784b419abd150cdebe68208370356
MD5 8ad2c950dbdfc0c2813c13a36673fd6e
BLAKE2b-256 838ab813d8355f1eeb39b44cd989091d8c73ccc9e4f95db381ead06f4db0e629

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