@@ -34,8 +34,6 @@ public class UnifiedChatCompletionRequestEntityTests extends ESTestCase {
3434
3535 private static final String ROLE = "user" ;
3636
37- // 1. Basic Serialization
38- // Test with minimal required fields to ensure basic serialization works.
3937 public void testBasicSerialization () throws IOException {
4038 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
4139 new UnifiedCompletionRequest .ContentString ("Hello, world!" ),
@@ -76,10 +74,8 @@ public void testBasicSerialization() throws IOException {
7674 assertJsonEquals (jsonString , expectedJson );
7775 }
7876
79- // 2. Serialization with All Fields
80- // Test with all possible fields populated to ensure complete serialization.
77+
8178 public void testSerializationWithAllFields () throws IOException {
82- // Create a message with all fields populated
8379 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
8480 new UnifiedCompletionRequest .ContentString ("Hello, world!" ),
8581 ROLE ,
@@ -94,7 +90,6 @@ public void testSerializationWithAllFields() throws IOException {
9490 )
9591 );
9692
97- // Create a tool with all fields populated
9893 UnifiedCompletionRequest .Tool tool = new UnifiedCompletionRequest .Tool (
9994 "type" ,
10095 new UnifiedCompletionRequest .Tool .FunctionField (
@@ -106,7 +101,6 @@ public void testSerializationWithAllFields() throws IOException {
106101 );
107102 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
108103 messageList .add (message );
109- // Create the unified request with all fields populated
110104 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
111105 messageList ,
112106 "model" ,
@@ -118,19 +112,15 @@ public void testSerializationWithAllFields() throws IOException {
118112 0.8f // topP
119113 );
120114
121- // Create the unified chat input
122115 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
123116
124117 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
125118
126- // Create the entity
127119 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
128120
129- // Serialize to XContent
130121 XContentBuilder builder = JsonXContent .contentBuilder ();
131122 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
132123
133- // Convert to string and verify
134124 String jsonString = Strings .toString (builder );
135125 String expectedJson = """
136126 {
@@ -195,10 +185,7 @@ public void testSerializationWithAllFields() throws IOException {
195185
196186 }
197187
198- // 3. Serialization with Null Optional Fields
199- // Test with optional fields set to null to ensure they are correctly omitted from the output.
200188 public void testSerializationWithNullOptionalFields () throws IOException {
201- // Create a message with minimal required fields
202189 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
203190 new UnifiedCompletionRequest .ContentString ("Hello, world!" ),
204191 ROLE ,
@@ -209,7 +196,6 @@ public void testSerializationWithNullOptionalFields() throws IOException {
209196 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
210197 messageList .add (message );
211198
212- // Create the unified request with optional fields set to null
213199 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
214200 messageList ,
215201 null , // model
@@ -221,19 +207,15 @@ public void testSerializationWithNullOptionalFields() throws IOException {
221207 null // topP
222208 );
223209
224- // Create the unified chat input
225210 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
226211
227212 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
228213
229- // Create the entity
230214 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
231215
232- // Serialize to XContent
233216 XContentBuilder builder = JsonXContent .contentBuilder ();
234217 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
235218
236- // Convert to string and verify
237219 String jsonString = Strings .toString (builder );
238220 String expectedJson = """
239221 {
@@ -254,10 +236,7 @@ public void testSerializationWithNullOptionalFields() throws IOException {
254236 assertJsonEquals (jsonString , expectedJson );
255237 }
256238
257- // 4. Serialization with Empty Lists
258- // Test with fields that are lists set to empty lists to ensure they are correctly serialized.
259239 public void testSerializationWithEmptyLists () throws IOException {
260- // Create a message with minimal required fields
261240 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
262241 new UnifiedCompletionRequest .ContentString ("Hello, world!" ),
263242 ROLE ,
@@ -267,7 +246,6 @@ public void testSerializationWithEmptyLists() throws IOException {
267246 );
268247 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
269248 messageList .add (message );
270- // Create the unified request with empty lists
271249 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
272250 messageList ,
273251 null , // model
@@ -279,19 +257,15 @@ public void testSerializationWithEmptyLists() throws IOException {
279257 null // topP
280258 );
281259
282- // Create the unified chat input
283260 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
284261
285262 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
286263
287- // Create the entity
288264 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
289265
290- // Serialize to XContent
291266 XContentBuilder builder = JsonXContent .contentBuilder ();
292267 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
293268
294- // Convert to string and verify
295269 String jsonString = Strings .toString (builder );
296270 String expectedJson = """
297271 {
@@ -313,12 +287,10 @@ public void testSerializationWithEmptyLists() throws IOException {
313287 assertJsonEquals (jsonString , expectedJson );
314288 }
315289
316- // 5. Serialization with Nested Objects
317- // Test with nested objects (e.g., toolCalls, toolChoice, tool) to ensure they are correctly serialized.
290+
318291 public void testSerializationWithNestedObjects () throws IOException {
319292 Random random = Randomness .get ();
320293
321- // Generate random values
322294 String randomContent = "Hello, world! " + random .nextInt (1000 );
323295 String randomName = "name" + random .nextInt (1000 );
324296 String randomToolCallId = "tool_call_id" + random .nextInt (1000 );
@@ -330,7 +302,6 @@ public void testSerializationWithNestedObjects() throws IOException {
330302 float randomTemperature = (float ) ((float ) Math .round (0.5d + (double ) random .nextFloat () * 0.5d * 100000d ) / 100000d );
331303 float randomTopP = (float ) ((float ) Math .round (0.5d + (double ) random .nextFloat () * 0.5d * 100000d ) / 100000d );
332304
333- // Create a message with nested toolCalls
334305 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
335306 new UnifiedCompletionRequest .ContentString (randomContent ),
336307 ROLE ,
@@ -345,7 +316,6 @@ public void testSerializationWithNestedObjects() throws IOException {
345316 )
346317 );
347318
348- // Create a tool with nested function fields
349319 UnifiedCompletionRequest .Tool tool = new UnifiedCompletionRequest .Tool (
350320 randomType ,
351321 new UnifiedCompletionRequest .Tool .FunctionField (
@@ -357,7 +327,6 @@ public void testSerializationWithNestedObjects() throws IOException {
357327 );
358328 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
359329 messageList .add (message );
360- // Create the unified request with nested objects
361330 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
362331 messageList ,
363332 randomModel ,
@@ -372,21 +341,16 @@ public void testSerializationWithNestedObjects() throws IOException {
372341 randomTopP // topP
373342 );
374343
375- // Create the unified chat input
376344 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
377345
378346 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , randomModel , null );
379347
380- // Create the entity
381348 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
382349
383- // Serialize to XContent
384350 XContentBuilder builder = JsonXContent .contentBuilder ();
385351 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
386352
387- // Convert to string and verify
388353 String jsonString = Strings .toString (builder );
389- // Expected JSON should be dynamically generated based on random values
390354 String expectedJson = String .format (
391355 Locale .US ,
392356 """
@@ -470,15 +434,12 @@ public void testSerializationWithNestedObjects() throws IOException {
470434 assertJsonEquals (jsonString , expectedJson );
471435 }
472436
473- // 6. Serialization with Different Content Types
474- // Test with different content types in messages (e.g., ContentString, ContentObjects) to ensure they are correctly serialized.
437+
475438 public void testSerializationWithDifferentContentTypes () throws IOException {
476439 Random random = Randomness .get ();
477440
478- // Generate random values for ContentString
479441 String randomContentString = "Hello, world! " + random .nextInt (1000 );
480442
481- // Generate random values for ContentObjects
482443 String randomText = "Random text " + random .nextInt (1000 );
483444 String randomType = "type" + random .nextInt (1000 );
484445 UnifiedCompletionRequest .ContentObject contentObject = new UnifiedCompletionRequest .ContentObject (randomText , randomType );
@@ -487,7 +448,6 @@ public void testSerializationWithDifferentContentTypes() throws IOException {
487448 contentObjectsList .add (contentObject );
488449 UnifiedCompletionRequest .ContentObjects contentObjects = new UnifiedCompletionRequest .ContentObjects (contentObjectsList );
489450
490- // Create messages with different content types
491451 UnifiedCompletionRequest .Message messageWithString = new UnifiedCompletionRequest .Message (
492452 new UnifiedCompletionRequest .ContentString (randomContentString ),
493453 ROLE ,
@@ -501,22 +461,17 @@ public void testSerializationWithDifferentContentTypes() throws IOException {
501461 messageList .add (messageWithString );
502462 messageList .add (messageWithObjects );
503463
504- // Create the unified request with both types of messages
505464 UnifiedCompletionRequest unifiedRequest = UnifiedCompletionRequest .of (messageList );
506465
507- // Create the unified chat input
508466 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
509467
510468 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
511469
512- // Create the entity
513470 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
514471
515- // Serialize to XContent
516472 XContentBuilder builder = JsonXContent .contentBuilder ();
517473 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
518474
519- // Convert to string and verify
520475 String jsonString = Strings .toString (builder );
521476 String expectedJson = String .format (Locale .US , """
522477 {
@@ -546,10 +501,8 @@ public void testSerializationWithDifferentContentTypes() throws IOException {
546501 assertJsonEquals (jsonString , expectedJson );
547502 }
548503
549- // 7. Serialization with Special Characters
550- // Test with special characters in string fields to ensure they are correctly escaped and serialized.
504+
551505 public void testSerializationWithSpecialCharacters () throws IOException {
552- // Create a message with special characters
553506 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
554507 new UnifiedCompletionRequest .ContentString ("Hello, world! \n \" Special\" characters: \t \\ /" ),
555508 ROLE ,
@@ -565,7 +518,6 @@ public void testSerializationWithSpecialCharacters() throws IOException {
565518 );
566519 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
567520 messageList .add (message );
568- // Create the unified request
569521 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
570522 messageList ,
571523 null , // model
@@ -577,19 +529,15 @@ public void testSerializationWithSpecialCharacters() throws IOException {
577529 null // topP
578530 );
579531
580- // Create the unified chat input
581532 UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
582533
583534 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
584535
585- // Create the entity
586536 OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
587537
588- // Serialize to XContent
589538 XContentBuilder builder = JsonXContent .contentBuilder ();
590539 entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
591540
592- // Convert to string and verify
593541 String jsonString = Strings .toString (builder );
594542 String expectedJson = """
595543 {
@@ -622,10 +570,7 @@ public void testSerializationWithSpecialCharacters() throws IOException {
622570 assertJsonEquals (jsonString , expectedJson );
623571 }
624572
625- // 8. Serialization with Boolean Fields
626- // Test with boolean fields (stream) set to both true and false to ensure they are correctly serialized.
627573 public void testSerializationWithBooleanFields () throws IOException {
628- // Create a message with minimal required fields
629574 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
630575 new UnifiedCompletionRequest .ContentString ("Hello, world!" ),
631576 ROLE ,
@@ -635,7 +580,6 @@ public void testSerializationWithBooleanFields() throws IOException {
635580 );
636581 var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
637582 messageList .add (message );
638- // Create the unified request
639583 UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
640584 messageList ,
641585 null , // model
@@ -649,7 +593,6 @@ public void testSerializationWithBooleanFields() throws IOException {
649593
650594 OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
651595
652- // Test with stream set to true
653596 UnifiedChatInput unifiedChatInputTrue = new UnifiedChatInput (unifiedRequest , true );
654597 OpenAiUnifiedChatCompletionRequestEntity entityTrue = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInputTrue , model );
655598
@@ -675,7 +618,6 @@ public void testSerializationWithBooleanFields() throws IOException {
675618 """ ;
676619 assertJsonEquals (expectedJsonTrue , jsonStringTrue );
677620
678- // Test with stream set to false
679621 UnifiedChatInput unifiedChatInputFalse = new UnifiedChatInput (unifiedRequest , false );
680622 OpenAiUnifiedChatCompletionRequestEntity entityFalse = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInputFalse , model );
681623
@@ -699,7 +641,6 @@ public void testSerializationWithBooleanFields() throws IOException {
699641 assertJsonEquals (expectedJsonFalse , jsonStringFalse );
700642 }
701643
702- // 9. a test without the content field to show that the content field is optional
703644 public void testSerializationWithoutContentField () throws IOException {
704645 UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
705646 null ,
0 commit comments