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