@@ -146,10 +146,11 @@ void testWrapOpenAi() {
146146 "chatcmpl-test123" ,
147147 span .getAttributes ().get (AttributeKey .stringKey ("gen_ai.response.id" )));
148148 assertEquals (
149- "[{\" content\" :\" You are a helpful"
150- + " assistant\" ,\" role\" :\" system\" ,\" valid\" :true},{\" content\" :\" What is the"
151- + " capital of France?\" ,\" role\" :\" user\" ,\" valid\" :true}]" ,
152- span .getAttributes ().get (AttributeKey .stringKey ("braintrust.input_json" )));
149+ "[{\" role\" :\" system\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" You are a"
150+ + " helpful"
151+ + " assistant\" }]},{\" role\" :\" user\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" What"
152+ + " is the capital of France?\" }]}]" ,
153+ span .getAttributes ().get (AttributeKey .stringKey ("gen_ai.input.messages" )));
153154 assertEquals (
154155 "project_name:unit-test-project" ,
155156 span .getAttributes ().get (AttributeKey .stringKey ("braintrust.parent" )));
@@ -162,12 +163,11 @@ void testWrapOpenAi() {
162163 span .getAttributes ().get (AttributeKey .doubleKey ("gen_ai.request.temperature" )));
163164
164165 String outputJson =
165- span .getAttributes ().get (AttributeKey .stringKey ("braintrust.output_json" ));
166- assertNotNull (outputJson );
167- var outputMessages = JSON_MAPPER .readTree (outputJson );
168- assertEquals (1 , outputMessages .size ());
169- var messageZero = outputMessages .get (0 );
170- assertEquals ("The capital of France is Paris." , messageZero .get ("content" ).asText ());
166+ span .getAttributes ().get (AttributeKey .stringKey ("gen_ai.output.messages" ));
167+ assertEquals (
168+ "[{\" role\" :\" assistant\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" The capital"
169+ + " of France is Paris.\" }],\" finish_reason\" :\" stop\" }]" ,
170+ outputJson );
171171
172172 assertEquals (
173173 "chatcmpl-test123" ,
@@ -432,41 +432,15 @@ void testWrapOpenAiWithImageAttachment() {
432432
433433 // Verify input JSON captures both text and image content
434434 String inputJson =
435- span .getAttributes ().get (AttributeKey .stringKey ("braintrust.input_json" ));
435+ span .getAttributes ().get (AttributeKey .stringKey ("gen_ai.input.messages" ));
436+ assertEquals (
437+ "[{\" role\" :\" system\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" You are a helpful assistant that can analyze images\" }]},{\" role\" :\" user\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" What's in this image?\" },{\" type\" :\" base64_attachment\" ,\" content\" :\" %s\" }]}]"
438+ .formatted (imageDataUrl ),
439+ inputJson );
436440 assertNotNull (inputJson );
437441 var inputMessages = JSON_MAPPER .readTree (inputJson );
438442 assertEquals (2 , inputMessages .size ()); // system message + user message
439443
440- // Verify system message
441- var systemMessage = inputMessages .get (0 );
442- assertEquals ("system" , systemMessage .get ("role" ).asText ());
443- assertEquals (
444- "You are a helpful assistant that can analyze images" ,
445- systemMessage .get ("content" ).asText ());
446-
447- // Verify user message with image
448- var userMsg = inputMessages .get (1 );
449- assertEquals ("user" , userMsg .get ("role" ).asText ());
450- assertTrue (userMsg .has ("content" ));
451- var content = userMsg .get ("content" );
452- assertTrue (content .isArray ());
453- assertEquals (2 , content .size ()); // text + image
454-
455- // Verify text content part
456- var textContent = content .get (0 );
457- assertEquals ("text" , textContent .get ("type" ).asText ());
458- assertEquals ("What's in this image?" , textContent .get ("text" ).asText ());
459-
460- // Verify image content part (now serialized as base64_attachment)
461- var imageContent = content .get (1 );
462- assertEquals ("base64_attachment" , imageContent .get ("type" ).asText ());
463- assertTrue (imageContent .has ("content" ));
464- assertTrue (imageContent .get ("content" ).asText ().startsWith ("data:image/jpeg;base64," ));
465- assertEquals (
466- imageDataUrl ,
467- imageContent .get ("content" ).asText (),
468- "base64 data not correctly serialized" );
469-
470444 // Verify usage metrics
471445 assertEquals (
472446 150L , span .getAttributes ().get (AttributeKey .longKey ("gen_ai.usage.input_tokens" )));
@@ -475,13 +449,10 @@ void testWrapOpenAiWithImageAttachment() {
475449
476450 // Verify output JSON
477451 String outputJson =
478- span .getAttributes ().get (AttributeKey .stringKey ("braintrust.output_json" ));
479- assertNotNull (outputJson );
480- var outputMessages = JSON_MAPPER .readTree (outputJson );
481- assertEquals (1 , outputMessages .size ());
482- var messageZero = outputMessages .get (0 );
452+ span .getAttributes ().get (AttributeKey .stringKey ("gen_ai.output.messages" ));
483453 assertEquals (
484- "This image shows the Eiffel Tower in Paris, France." ,
485- messageZero .get ("content" ).asText ());
454+ "[{\" role\" :\" assistant\" ,\" parts\" :[{\" type\" :\" text\" ,\" content\" :\" This image"
455+ + " shows the Eiffel Tower in Paris, France.\" }],\" finish_reason\" :\" stop\" }]" ,
456+ outputJson );
486457 }
487458}
0 commit comments