@@ -48,35 +48,35 @@ class Request < SimpleDelegator
4848 # @option params [Integer] :max_output_tokens
4949 # @raise [ArgumentError] when parameters are invalid
5050 def initialize ( **params )
51- # Extract custom fields
51+ # Step 1: Extract custom fields
5252 @stream = params [ :stream ]
5353 @response_format = params . delete ( :response_format )
5454
55- # Map common format 'messages' to OpenAI Responses 'input'
55+ # Step 2: Map common format 'messages' to OpenAI Responses 'input'
5656 if params . key? ( :messages )
5757 params [ :input ] = params . delete ( :messages )
5858 end
5959
60- # Join instructions array into string (like Chat API)
60+ # Step 3: Join instructions array into string (like Chat API)
6161 if params [ :instructions ] . is_a? ( Array )
6262 params [ :instructions ] = params [ :instructions ] . join ( "\n " )
6363 end
6464
65- # Map response_format to text parameter for Responses API
65+ # Step 4: Map response_format to text parameter for Responses API
6666 if @response_format
6767 params [ :text ] = Responses ::Transforms . normalize_response_format ( @response_format )
6868 end
6969
70- # Apply defaults
70+ # Step 5: Apply defaults
7171 params = apply_defaults ( params )
7272
73- # Normalize input content for gem compatibility
73+ # Step 6: Normalize input content for gem compatibility
7474 params [ :input ] = Responses ::Transforms . normalize_input ( params [ :input ] ) if params [ :input ]
7575
76- # Create gem model - delegates to OpenAI gem
76+ # Step 7: Create gem model - delegates to OpenAI gem
7777 gem_model = ::OpenAI ::Models ::Responses ::ResponseCreateParams . new ( **params )
7878
79- # Delegate all method calls to gem model
79+ # Step 8: Delegate all method calls to gem model
8080 super ( gem_model )
8181 rescue ArgumentError => e
8282 # Re-raise with more context
@@ -85,22 +85,12 @@ def initialize(**params)
8585
8686 # Serializes request for API call
8787 #
88- # Removes default values for minimal request body and simplifies
89- # single-element input arrays to strings where possible.
88+ # Uses gem's JSON serialization and delegates cleanup to Transforms module.
9089 #
9190 # @return [Hash] cleaned request hash
9291 def serialize
9392 hash = Responses ::Transforms . gem_to_hash ( __getobj__ )
94-
95- # Remove default values that shouldn't be in the request body
96- DEFAULTS . each do |key , value |
97- hash . delete ( key ) if hash [ key ] == value
98- end
99-
100- # Simplify input when possible for cleaner API requests
101- hash [ :input ] = Responses ::Transforms . simplify_input ( hash [ :input ] ) if hash [ :input ]
102-
103- hash
93+ Responses ::Transforms . cleanup_serialized_request ( hash , DEFAULTS , __getobj__ )
10494 end
10595
10696 # @return [Array, String, Hash, nil]
0 commit comments