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 bytesimages→ list of image paths or image bytes
Only one of pdf or images may be provided per invocation.
How It Works
- PDF inputs are converted to images.
- Images are validated and base64 encoded.
- A multimodal payload is created.
- The payload is sent to a LangChain chat model.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf_invoke-0.1.2.tar.gz.
File metadata
- Download URL: pdf_invoke-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20f9bf24504468ca194205c1835cfbfb72a3faff77c138622162a917c92be7c3
|
|
| MD5 |
df8ac309c388966d9986184e05f0498d
|
|
| BLAKE2b-256 |
ba7f452d77847e2cf6e906de84ff752b6287301ff9604c679e29dd1c069f2b3f
|
File details
Details for the file pdf_invoke-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pdf_invoke-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56ea225671a78a017f713ff46562dcf001c27dab43df881d9e3163eb6e178cef
|
|
| MD5 |
8309fde2c42b0e350880f7fd777e77e0
|
|
| BLAKE2b-256 |
dbc84ba4b47b6ef0c0cebb522aadd3af229fc22b6c733122cab3c062994ea390
|