encode_content

in lib/openai/internal/util.rb [560:581]


        def encode_content(headers, body)
          content_type = headers["content-type"]
          body = body.inner if body.is_a?(OpenAI::Internal::Util::SerializationAdapter)

          case [content_type, body]
          in [%r{^application/(?:vnd\.api\+)?json}, Hash | Array | -> { primitive?(_1) }]
            [headers, JSON.fast_generate(body)]
          in [%r{^application/(?:x-)?jsonl}, Enumerable] unless body.is_a?(StringIO) || body.is_a?(IO)
            [headers, body.lazy.map { JSON.fast_generate(_1) }]
          in [%r{^multipart/form-data}, Hash | Pathname | StringIO | IO]
            boundary, strio = encode_multipart_streaming(body)
            headers = {**headers, "content-type" => "#{content_type}; boundary=#{boundary}"}
            [headers, strio]
          in [_, Symbol | Numeric]
            [headers, body.to_s]
          in [_, StringIO]
            [headers, body.string]
          else
            [headers, body]
          end
        end