BAML with Python/TS/Ruby

Multimodal

Multi-modal input

Images

Calling a BAML function with an image input argument type (see image types).

The from_url and from_base64 methods create an Image object based on input type.

1from baml_py import Image
2from baml_client import b
3
4async def test_image_input():
5 # from URL
6 res = await b.TestImageInput(
7 img=Image.from_url(
8 "https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png"
9 )
10 )
11
12 # Base64 image
13 image_b64 = "iVBORw0K...."
14 res = await b.TestImageInput(
15 img=Image.from_base64("image/png", image_b64)
16 )

Audio

Calling functions that have audio types. See audio types

1from baml_py import Audio
2from baml_client import b
3
4async def run():
5 # from URL
6 res = await b.TestAudioInput(
7 img=Audio.from_url(
8 "https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png"
9 )
10 )
11
12 # Base64
13 b64 = "iVBORw0K...."
14 res = await b.TestAudioInput(
15 img=Audio.from_base64("image/png", b64)
16 )