-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Add optional `media_type` parameter to `from_url()` for `Audio` and `Image` classes in Python, Ruby, and TypeScript, and update documentation accordingly. > > - **Behavior**: > - Add optional `media_type` parameter to `from_url()` in `BamlAudioPy` and `BamlImagePy` in `audio.rs` and `image.rs`. > - Update `from_url()` in `media.rs` for Ruby to accept `media_type`. > - Modify `fromUrl()` in `native.d.ts` and `audio.rs` and `image.rs` for TypeScript to include `mediaType`. > - **Documentation**: > - Add `media.mdx` and `media.mdx` to document `Image` and `Audio` usage. > - Update `multi-modal.mdx` to reflect changes in `from_url()` method. > - Update `typebuilder.mdx` to include new TypeBuilder methods. > - Update `docs.yml` to include new documentation paths. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for e7a3d2a. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
Showing
11 changed files
with
269 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: Image / Audio | ||
--- | ||
|
||
Media values as denoted more specifically in BAML. | ||
|
||
| Baml Type | | ||
| --- | | ||
| `image` | | ||
| `audio` | | ||
|
||
Both `image` and `audio` values values can be: | ||
|
||
- A URL | ||
- A base64 encoded string | ||
- A file path | ||
|
||
For usage in Python / Typescript / etc, see [baml_client > media](/ref/baml-client/media). | ||
|
||
## Usage as a URL | ||
|
||
```baml {2,13-15,22-25,32-34} | ||
// Pass in an image type | ||
function DescribeImage(image: image) -> string { | ||
client "openai/gpt-4o-mini" | ||
prompt #" | ||
Describe the image. | ||
{{ image }} | ||
"# | ||
} | ||
test ImageDescriptionFromURL { | ||
functions [DescribeImage] | ||
args { | ||
image { | ||
url "https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png" | ||
} | ||
} | ||
} | ||
test ImageDescriptionFromBase64 { | ||
functions [DescribeImage] | ||
args { | ||
image { | ||
media_type "image/png" | ||
base64 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x/AAzmH+UlvRkwAAAAASUVORK5CYII=" | ||
} | ||
} | ||
} | ||
test ImageDescriptionFromFile { | ||
functions [DescribeImage] | ||
args { | ||
image { | ||
file "./shrek.png" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
title: Image / Audio | ||
--- | ||
|
||
Image / Audio values to BAML functions can by created in client libraries. This document explains how to use these functions both at compile time and runtime to handle multimedia data. For more details, refer to [image types](/ref/baml/types#image) and [audio types](/ref/baml/types#audio). | ||
|
||
## Images | ||
|
||
BAML functions that accept an image input utilize the Image helper, which supports creating Image objects from URLs or Base64 encoded data. | ||
|
||
### Image Creation Methods | ||
|
||
|
||
• `Image.from_url(url: string, media_type: string | null)`: Creates an Image object from the specified URL. (optionally specify the media type, otherwise it will be inferred from the URL) | ||
|
||
• `Image.from_base64(mime_type: string, data: string)`: Creates an Image object using Base64 encoded data along with the given MIME type. | ||
|
||
### Usage | ||
|
||
|
||
<CodeBlocks> | ||
```python {6,11} | ||
from baml_py import Image | ||
from baml_client import b | ||
|
||
async def test_image_input(): | ||
# Create an Image from a URL | ||
img = Image.from_url("https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png") | ||
res = await b.TestImageInput(img=img) | ||
|
||
# Create an Image from Base64 data | ||
image_b64 = "iVB0xyz..." | ||
img = Image.from_base64("image/png", image_b64) | ||
res = await b.TestImageInput(img=img) | ||
``` | ||
|
||
```typescript | ||
import { b } from '../baml_client' | ||
import { Image } from "@boundaryml/baml" | ||
|
||
// Create an Image from a URL | ||
let res = await b.TestImageInput( | ||
Image.fromUrl('https://upload.wikimedia.org/wikipedia/en/4/4d/Shrek_%28character%29.png') | ||
) | ||
|
||
// Create an Image from Base64 data | ||
const image_b64 = "iVB0xyz..." | ||
res = await b.TestImageInput( | ||
Image.fromBase64('image/png', image_b64) | ||
) | ||
``` | ||
|
||
```ruby | ||
# Ruby implementation is in development. | ||
``` | ||
</CodeBlocks> | ||
## Audio | ||
|
||
BAML functions that accept audio inputs utilize the Audio helper. Similar to images, you can create Audio objects from URLs or Base64 encoded data. | ||
|
||
### Audio Creation Methods | ||
|
||
• Audio.from_url(url: string): Creates an Audio object from the specified URL. | ||
|
||
• Audio.from_base64(mime_type: string, data: string): Creates an Audio object using Base64 encoded audio data with the provided MIME type. | ||
|
||
### Usage | ||
|
||
**Python** | ||
```python | ||
from baml_py import Audio | ||
from baml_client import b | ||
|
||
async def run(): | ||
# Create an Audio object from a URL | ||
res = await b.TestAudioInput( | ||
audio=Audio.from_url("https://actions.google.com/sounds/v1/emergency/beeper_emergency_call.ogg") | ||
) | ||
|
||
# Create an Audio object from Base64 data | ||
b64 = "iVB0xyz..." | ||
res = await b.TestAudioInput( | ||
audio=Audio.from_base64("audio/ogg", b64) | ||
) | ||
``` | ||
|
||
**TypeScript** | ||
```typescript | ||
import { b } from '../baml_client' | ||
import { Audio } from "@boundaryml/baml" | ||
|
||
// Create an Audio object from a URL | ||
let res = await b.TestAudioInput( | ||
Audio.fromUrl('https://actions.google.com/sounds/v1/emergency/beeper_emergency_call.ogg') | ||
) | ||
|
||
// Create an Audio object from Base64 data | ||
const audio_base64 = "iVB0xyz..." | ||
res = await b.TestAudioInput( | ||
Audio.fromBase64('audio/ogg', audio_base64) | ||
) | ||
``` | ||
|
||
**Ruby (beta)** | ||
```ruby | ||
# Ruby implementation is in development. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.