Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dig into how scoring works re maps vs classes #950

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions engine/baml-lib/jsonish/src/tests/test_unions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,176 @@ test_deserializer!(
"data": null
}
);

const MAP_VS_CLASS: &str = r###"
class Page {
object string @description("Always page")
// children (Bookmark | Breadcrumb | BulletedListItem | Callout | Code | ColumnList | Divider | Embed | Equation | File | Heading1 | Heading2 | Heading3 | ImageFile | NumberedListItem | Paragraph | PDF | Quote | Table | TableOfContents | ToDo | Toggle | Video)[] @description("Some blocks of the page")
children (Breadcrumb | ColumnList)[] @description("Some blocks of the page")
}

// ------------ Breadcrumb ----------------
class Breadcrumb {
type string @description("Always breadcrumb")
breadcrumb map<string, string> @description("Always empty map")
}

/// ------------ Column List ----------------
class ColumnList {
type string @description("Always column_list")
column_list ColumnListBody @description("Column list block with columns")
}

class ColumnListBody {
children Column[] @description("The columns in the column list. Max length is 5")
}

class Column {
type string @description("Always column")
column ColumnBody @description("Always empty map for columns")
}

class ColumnBody {
// children (Bookmark | Breadcrumb | BulletedListItem | Callout | Code | Divider | Embed | Equation | File | Heading1 | Heading2 | Heading3 | ImageFile | NumberedListItem | Paragraph | PDF | Quote | Table | TableOfContents | ToDo | Toggle | Video)[] @description("Content of the column. Can contain any block type. Min length is 1")
children (Breadcrumb | Paragraph)[]
}

/// ------------ Other blocks ----------------
///
class Paragraph {
type string @description("Always paragraph")
paragraph string
}
"###;

test_deserializer!(
prefer_class_to_map,
MAP_VS_CLASS,
r#"```json
{
"object": "page",
"children": [
{
"type": "column_list",
"column_list": {
"children": [
{
"type": "column",
"column": {
"children": [
{
"untyped": "lorem ipsum",
},
{
"untyped": "lorem ipsum",
},
{
"untyped": "lorem ipsum",
},
{
"type": "paragraph",
"paragraph": "J.R.R. Tolkien",
},
{
"type": "to_do",
"to_do": {
"untyped": "dolor sit amet",
"rich_text": [
{
"type": "text",
"text": {
"content": "Read again"
}
}
],
"checked": false
}
}
]
}
}
]
}
}
]
}
```"#,
FieldType::class("Page"),
{
"children": [
{
"type": "column_list",
"column_list": {
"children": [
{
"type": "column",
"column": {
"children": [
{
"type": "paragraph",
"paragraph": "J.R.R. Tolkien",
},
]
}
}
]
}
}
]
}
);

test_deserializer!(
array_of_union_should_drop_unknown,
MAP_VS_CLASS,
r#"```json
{
"children": [
{
"untyped": "lorem ipsum",
},
{
"untyped": "lorem ipsum",
},
{
"untyped": "lorem ipsum",
},
{
"untyped": "lorem ipsum",
},
{
"type": "paragraph",
"paragraph": "J.R.R. Tolkien",
},
{
"type": "to_do",
"to_do": {
"untyped": "dolor sit amet",
"rich_text": [
{
"type": "text",
"text": {
"content": "Read again"
}
}
],
"checked": false
}
}
]
}
```"#,
FieldType::class("ColumnBody"),
{
"children": [
{
"type": "paragraph",
"paragraph": "J.R.R. Tolkien",
},
{
"type": "to_do",
"breadcrumb": {},
}
]
}
);
Loading