https://www.boundaryml.com logo
๐ŸŸก Question about passing various file types to Op...
# questions
e
Is there a way to pass
input_file
for https://developers.openai.com/api/docs/guides/file-inputs (not just PDFs, but other files like
.docx
,
.pptx
) from BAML?
Copy code
python
response = client.responses.create(
    model="gpt-5",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "filename": "draconomicon.pdf",
                    "file_data": f"data:application/pdf;base64,{base64_string}",
                },
                {
                    "type": "input_text",
                    "text": "What is the first dragon in the book?",
                },
            ],
        },
    ]
)
Basically like this
input_file
but via BAML without being constrained to BAML's PDF type.
j
Yes but not without some fun hacking.. no native way that I could find But you can pretty easily get there with the modular API - https://docs.boundaryml.com/guide/baml-advanced/modular-api I put together this example using requests for HTTP or you can load the client SDK directly that has built in support (helpful if you need to adjust these types of requests for example sending to AWS Bedrock vs OpenAI .. differnt API or client but similar funcitonality.. this is the way) Technique works to extend the request for any thing in the body or headers if BAML doesn't natively support it https://cdn.discordapp.com/attachments/1483934407667486720/1483958437758111805/image.png?ex=69bc7b7e&is=69bb29fe&hm=9fea620d56ce52e64ec3c2bec0b85318ac16329b7883fc04a5997928f023e868&
e
Thanks very much, this was the approach I went with as well to create the Streaming response via OpenAI SDK via
responses.create
and then via
b.parse_stream.MyClass
It's not ideal but suffices.
j
Yeah if you only are planning on a single provider itโ€™s a good solution.. this gets kinda brittle if you wanted to support multiple providers and their own flavors of input_file style endpoints The other alternative is process within your app and add it as a string in your prompt (added benefit is testing becomes easier) - can just replicate the same parsing logic the OpenAI supports but do it before you call any baml_client code
I think it would be cool to see BAML try and get some coverage on all the MIME types commonly used .. just not every provider supports this interface so itโ€™s kinda a one off situation (at least this workaround still gets the DSL and parsing power the BAML brings)
e
Agree, would be great if we can get first class support in BAML for various MIME types for providers who support this.
cc @Vaibhav (BAML ๐Ÿ‘)
a
agreed. CC @avery (BAML) something to think about as you're doing the new compiler providers