https://www.boundaryml.com logo
Sending PDFs to LLMs via BAML without base64 with ...
# help
v
Hi everyone , I’m new to BAML and had a question. Is there a way to send a PDF file directly to an LLM through BAML functions in Python scripts from a local file path, without having to convert it into base64 first? Thanks in advance!
v
Sadly not. We don’t have a file primitive 😦 you need to manually load and then send it
v
Would you suggest any way to deal with it ? I am building a prompt library and engine..
v
you just load the pdf via
open(...)
then just create the Pdf object via that!
Copy code
python
import base64
from baml_py import Image

with open('path/to/image.png', 'rb') as f:
    image_data = f.read()
    image_b64 = base64.b64encode(image_data).decode('utf-8')
    img = Image.from_base64('image/png', image_b64)
just use Pdf instead of Image