@@ -702,124 +702,6 @@ public void testSerializationWithBooleanFields() throws IOException {
702702 assertJsonEquals (expectedJsonFalse , jsonStringFalse );
703703 }
704704
705- // 9. Serialization with Missing Required Fields
706- // Test with missing required fields to ensure appropriate exceptions are thrown.
707- public void testSerializationWithMissingRequiredFields () {
708- // Create a message with missing content (required field)
709- UnifiedCompletionRequest .Message message = new UnifiedCompletionRequest .Message (
710- null , // missing content
711- OpenAiUnifiedChatCompletionRequestEntity .USER_FIELD ,
712- null ,
713- null ,
714- null
715- );
716- var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
717- messageList .add (message );
718- // Create the unified request
719- UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
720- messageList ,
721- null , // model
722- null , // maxCompletionTokens
723- null , // stop
724- null , // temperature
725- null , // toolChoice
726- null , // tools
727- null // topP
728- );
729-
730- // Create the unified chat input
731- UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
732-
733- OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
734-
735- // Create the entity
736- OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
737-
738- // Attempt to serialize to XContent and expect an exception
739- try {
740- XContentBuilder builder = JsonXContent .contentBuilder ();
741- entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
742- fail ("Expected an exception due to missing required fields" );
743- } catch (NullPointerException | IOException e ) {
744- // Expected exception
745- }
746- }
747-
748- // 10. Serialization with Mixed Valid and Invalid Data
749- // Test with a mix of valid and invalid data to ensure the serializer handles it gracefully.
750- public void testSerializationWithMixedValidAndInvalidData () throws IOException {
751- // Create a valid message
752- UnifiedCompletionRequest .Message validMessage = new UnifiedCompletionRequest .Message (
753- new UnifiedCompletionRequest .ContentString ("Valid content" ),
754- OpenAiUnifiedChatCompletionRequestEntity .USER_FIELD ,
755- "validName" ,
756- "validToolCallId" ,
757- Collections .singletonList (
758- new UnifiedCompletionRequest .ToolCall (
759- "validId" ,
760- new UnifiedCompletionRequest .ToolCall .FunctionField ("validArguments" , "validFunctionName" ),
761- "validType"
762- )
763- )
764- );
765-
766- // Create an invalid message with null content
767- UnifiedCompletionRequest .Message invalidMessage = new UnifiedCompletionRequest .Message (
768- null , // invalid content
769- OpenAiUnifiedChatCompletionRequestEntity .USER_FIELD ,
770- "invalidName" ,
771- "invalidToolCallId" ,
772- Collections .singletonList (
773- new UnifiedCompletionRequest .ToolCall (
774- "invalidId" ,
775- new UnifiedCompletionRequest .ToolCall .FunctionField ("invalidArguments" , "invalidFunctionName" ),
776- "invalidType"
777- )
778- )
779- );
780- var messageList = new ArrayList <UnifiedCompletionRequest .Message >();
781- messageList .add (validMessage );
782- messageList .add (invalidMessage );
783- // Create the unified request with both valid and invalid messages
784- UnifiedCompletionRequest unifiedRequest = new UnifiedCompletionRequest (
785- messageList ,
786- "model-name" ,
787- 100L , // maxCompletionTokens
788- Collections .singletonList ("stop" ),
789- 0.9f , // temperature
790- new UnifiedCompletionRequest .ToolChoiceString ("tool_choice" ),
791- Collections .singletonList (
792- new UnifiedCompletionRequest .Tool (
793- "type" ,
794- new UnifiedCompletionRequest .Tool .FunctionField (
795- "Fetches the weather in the given location" ,
796- "get_weather" ,
797- createParameters (),
798- true
799- )
800- )
801- ),
802- 0.8f // topP
803- );
804-
805- // Create the unified chat input
806- UnifiedChatInput unifiedChatInput = new UnifiedChatInput (unifiedRequest , true );
807-
808- OpenAiChatCompletionModel model = createChatCompletionModel ("test-endpoint" , "organizationId" , "api-key" , "model-name" , null );
809-
810- // Create the entity
811- OpenAiUnifiedChatCompletionRequestEntity entity = new OpenAiUnifiedChatCompletionRequestEntity (unifiedChatInput , model );
812-
813- // Serialize to XContent and verify
814- try {
815- XContentBuilder builder = JsonXContent .contentBuilder ();
816- entity .toXContent (builder , ToXContent .EMPTY_PARAMS );
817- fail ("Expected an exception due to invalid data" );
818- } catch (NullPointerException | IOException e ) {
819- // Expected exception
820- }
821- }
822-
823705 public static Map <String , Object > createParameters () {
824706 Map <String , Object > parameters = new LinkedHashMap <>();
825707 parameters .put ("type" , "object" );
0 commit comments