Skip to content

Commit bd4a309

Browse files
Add unit test for RawText and text content
1 parent cba75de commit bd4a309

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tensorzero-core/src/endpoints/openai_compatible.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,16 @@ impl TryFrom<Vec<OpenAICompatibleMessage>> for Input {
668668
#[serde(tag = "type", deny_unknown_fields, rename_all = "snake_case")]
669669
enum OpenAICompatibleContentBlock {
670670
Text(TextContent),
671-
ImageUrl { image_url: OpenAICompatibleImageUrl },
672-
File { file: OpenAICompatibleFile },
671+
ImageUrl {
672+
image_url: OpenAICompatibleImageUrl,
673+
},
674+
File {
675+
file: OpenAICompatibleFile,
676+
},
673677
#[serde(rename = "tensorzero::raw_text")]
674-
RawText { value: String },
678+
RawText {
679+
value: String,
680+
},
675681
}
676682

677683
#[derive(Deserialize, Debug)]
@@ -1432,6 +1438,26 @@ mod tests {
14321438

14331439
#[test]
14341440
fn test_convert_openai_message_content() {
1441+
// text content
1442+
let content = "Hello, world!".to_string();
1443+
let value = convert_openai_message_content(Value::String(content.clone())).unwrap();
1444+
assert_eq!(
1445+
value,
1446+
vec![InputMessageContent::Text(TextKind::Text { text: content })]
1447+
);
1448+
// tensorzero::raw_text
1449+
let content = json!([{
1450+
"type": "tensorzero::raw_text",
1451+
"value": "This is raw text"
1452+
}]);
1453+
let value = convert_openai_message_content(content.clone()).unwrap();
1454+
assert_eq!(
1455+
value,
1456+
vec![InputMessageContent::RawText {
1457+
value: "This is raw text".to_string()
1458+
}]
1459+
);
1460+
// tensorzero::arguments
14351461
let content = json!([{
14361462
"country": "Japan",
14371463
"city": "Tokyo",

0 commit comments

Comments
 (0)