Skip to content

Commit 9e2775b

Browse files
committed
chore: add test with multimodal content
1 parent 6bfeee8 commit 9e2775b

File tree

1 file changed

+44
-0
lines changed
  • lib/llm/src/preprocessor/prompt/template

1 file changed

+44
-0
lines changed

lib/llm/src/preprocessor/prompt/template/oai.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,48 @@ NORMAL MODE
841841
serde_json::Value::String("not valid json at all".to_string())
842842
);
843843
}
844+
845+
#[test]
846+
fn test_normalize_tool_arguments_with_multimodal_content() {
847+
let json_str = r#"{
848+
"model": "gpt-4o",
849+
"messages": [
850+
{
851+
"role": "user",
852+
"content": [
853+
{"type": "text", "text": "Check this:"},
854+
{"type": "video_url", "video_url": {"url": "https://example.com/vid.mp4"}},
855+
{"type": "text", "text": "Interesting?"}
856+
]
857+
},
858+
{
859+
"role": "assistant",
860+
"tool_calls": [{
861+
"id": "call_123",
862+
"type": "function",
863+
"function": {
864+
"name": "analyze_video",
865+
"arguments": "{\"url\":\"https://example.com/vid.mp4\",\"format\":\"mp4\"}"
866+
}
867+
}]
868+
}
869+
]
870+
}"#;
871+
872+
let request: NvCreateChatCompletionRequest = serde_json::from_str(json_str).unwrap();
873+
let mut messages = serde_json::to_value(request.messages()).unwrap();
874+
875+
normalize_tool_arguments_in_messages(&mut messages);
876+
877+
// Multimodal content preserved as array
878+
assert!(messages[0]["content"].is_array());
879+
assert_eq!(messages[0]["content"].as_array().unwrap().len(), 3);
880+
881+
// Tool arguments deserialized to object
882+
assert!(messages[1]["tool_calls"][0]["function"]["arguments"].is_object());
883+
assert_eq!(
884+
messages[1]["tool_calls"][0]["function"]["arguments"]["url"],
885+
"https://example.com/vid.mp4"
886+
);
887+
}
844888
}

0 commit comments

Comments
 (0)