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.1.tar.gz (5.1 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.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_invoke-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 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.1.tar.gz
Algorithm Hash digest
SHA256 22f74b958ce7b5d655848d9891bac5f0797a75a34f94e2f4f10611dcde354d37
MD5 d3e85eb948995d6196ed2e6dd13a95f8
BLAKE2b-256 18c1c24942ebf59db5deaa2d2e37c87078d492882bcad24405ff127cbc7f1aeb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_invoke-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13fceb229a694c54eb973283d9d2457b215ec8ae85640cbdb1a637971369e304
MD5 933f449e93ee2314c998194a3c39a382
BLAKE2b-256 4b5c3f5ea823f4ba0e24940c68df676d521eb6e967a4030eb41e1786434bceb0

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