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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_invoke-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9de33b73eefc76a0d0b87b89e3e4a57cf216b0b8e6c739d1bf5a4838bd5ed97e
MD5 c15eb305d942bc695d20bb62fc99f160
BLAKE2b-256 da481a1ffe5b23b827f06472925cd2bfbac7bd370bbb98b4b95b676043f7a6dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_invoke-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d59b00085b4a9479123f1651fdd11a8eb964b1b6ce434117f19b11bf69c61644
MD5 c7aec7e74ff653cb1b71dac9ea9361e1
BLAKE2b-256 2f2ba97371b3b4b18194d202aa066d908d1e80a6b104d738b9b015ca7840a77d

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