BAML Snippets

Test Cases

You can test your BAML functions in the VSCode Playground by adding a test snippet into a BAML file:

1enum Category {
2 Refund
3 CancelOrder
4 TechnicalSupport
5 AccountIssue
6 Question
7}
8
9function ClassifyMessage(input: string) -> Category {
10 client GPT4Turbo
11 prompt #"
12 ... truncated ...
13 "#
14}
15
16test Test1 {
17 functions [ClassifyMessage]
18 args {
19 input "Can't access my account using my usual login credentials, and each attempt results in an error message stating 'Invalid username or password.' I have tried resetting my password using the 'Forgot Password' link, but I haven't received the promised password reset email."
20 }
21}

See the interactive examples

The BAML playground will give you a starting snippet to copy that will match your function signature.

BAML doesn’t use between key-value pairs : except in function parameters

Complex object inputs

Objects are injected as dictionaries

1class Message {
2 user string
3 content string
4}
5
6function ClassifyMessage(messages: Messages[]) -> Category {
7...
8}
9
10test Test1 {
11 functions [ClassifyMessage]
12 args {
13 messages [
14 {
15 user "hey there"
16 content #"
17 You can also add a multi-line
18 string with the hashtags
19 Instead of ugly json with \n
20 "#
21 }
22 ]
23 }
24}

Images

An image input type is translated into this object (assuming the function signature is function MyFunction(myImage: image) -> ...):

URL input

1test Test1 {
2 args {
3 myImage {
4 url "https...."
5 }
6 }
7}

base64 input

1test Test1 {
2 args {
3 myImage {
4 base64 "base64string"
5 media_type "image/png"
6 }
7 }
8}

file input (coming soon)

Audio

Audio inputs are similar to images:

URL input

1...
2 {
3 url "https//domain.com/somefile.mp3"
4 }
5...

Base64 input

1{
2 media_type "audio/mp3"
3 base64 "base64string"
4}

file input (coming soon)