From 1de7f6f0814631b71b19335a5aee231478d18faf Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 12 Dec 2024 17:27:15 -0500 Subject: [PATCH] [Vertex AI] Replace `ImagenImage` protocol with `_ImagenImage` struct (#14249) --- .../Internal/Imagen/InternalImagenImage.swift | 29 ------------------- .../Public/Imagen/ImagenFileDataImage.swift | 4 +-- .../Types/Public/Imagen/ImagenImage.swift | 8 ++--- .../Imagen/ImagenImageRepresentable.swift | 9 +----- .../Public/Imagen/ImagenInlineDataImage.swift | 4 +-- .../Tests/Integration/IntegrationTests.swift | 4 --- .../Imagen/ImagenFileDataImageTests.swift | 6 ++-- .../Imagen/ImagenInlineDataImageTests.swift | 6 ++-- 8 files changed, 15 insertions(+), 55 deletions(-) delete mode 100644 FirebaseVertexAI/Sources/Types/Internal/Imagen/InternalImagenImage.swift diff --git a/FirebaseVertexAI/Sources/Types/Internal/Imagen/InternalImagenImage.swift b/FirebaseVertexAI/Sources/Types/Internal/Imagen/InternalImagenImage.swift deleted file mode 100644 index 16296245f95..00000000000 --- a/FirebaseVertexAI/Sources/Types/Internal/Imagen/InternalImagenImage.swift +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -struct InternalImagenImage { - let mimeType: String - let bytesBase64Encoded: String? - let gcsURI: String? - - init(mimeType: String, bytesBase64Encoded: String?, gcsURI: String?) { - self.mimeType = mimeType - self.bytesBase64Encoded = bytesBase64Encoded - self.gcsURI = gcsURI - } -} - -@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -extension InternalImagenImage: ImagenImage {} diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenFileDataImage.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenFileDataImage.swift index 48b94504293..5f04f3c1aa9 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenFileDataImage.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenFileDataImage.swift @@ -27,8 +27,8 @@ public struct ImagenFileDataImage { @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) extension ImagenFileDataImage: ImagenImageRepresentable { - public var imagenImage: any ImagenImage { - InternalImagenImage(mimeType: mimeType, bytesBase64Encoded: nil, gcsURI: gcsURI) + public var _imagenImage: _ImagenImage { + _ImagenImage(mimeType: mimeType, bytesBase64Encoded: nil, gcsURI: gcsURI) } } diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImage.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImage.swift index 4a5e90fc785..fb19243b4b3 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImage.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImage.swift @@ -15,8 +15,8 @@ import Foundation @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -public protocol ImagenImage: ImagenImageRepresentable { - var mimeType: String { get } - var bytesBase64Encoded: String? { get } - var gcsURI: String? { get } +public struct _ImagenImage { + let mimeType: String + let bytesBase64Encoded: String? + let gcsURI: String? } diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImageRepresentable.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImageRepresentable.swift index 816bbed5d28..8c5adb7133c 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImageRepresentable.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenImageRepresentable.swift @@ -16,12 +16,5 @@ import Foundation @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) public protocol ImagenImageRepresentable { - var imagenImage: any ImagenImage { get } -} - -@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -public extension ImagenImage { - var imagenImage: any ImagenImage { - return self - } + var _imagenImage: _ImagenImage { get } } diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineDataImage.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineDataImage.swift index f3c1343721b..4c77bd86150 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineDataImage.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenInlineDataImage.swift @@ -31,8 +31,8 @@ public struct ImagenInlineDataImage { @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) extension ImagenInlineDataImage: ImagenImageRepresentable { - public var imagenImage: any ImagenImage { - InternalImagenImage( + public var _imagenImage: _ImagenImage { + _ImagenImage( mimeType: mimeType, bytesBase64Encoded: data.base64EncodedString(), gcsURI: nil diff --git a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift index 11ffd3de600..4e233ffee38 100644 --- a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift +++ b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift @@ -267,10 +267,6 @@ final class IntegrationTests: XCTestCase { let image = try XCTUnwrap(response.images.first) XCTAssertEqual(image.mimeType, "image/jpeg") XCTAssertGreaterThan(image.data.count, 0) - let imagenImage = image.imagenImage - XCTAssertEqual(imagenImage.mimeType, image.mimeType) - XCTAssertEqual(imagenImage.bytesBase64Encoded, image.data.base64EncodedString()) - XCTAssertNil(imagenImage.gcsURI) #if canImport(UIKit) let uiImage = try XCTUnwrap(UIImage(data: image.data)) XCTAssertEqual(uiImage.size.width, 1408.0) diff --git a/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenFileDataImageTests.swift b/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenFileDataImageTests.swift index 21327d0dd7f..892228f8d25 100644 --- a/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenFileDataImageTests.swift +++ b/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenFileDataImageTests.swift @@ -35,9 +35,9 @@ final class ImagenFileDataImageTests: XCTestCase { XCTAssertEqual(image.mimeType, mimeType) XCTAssertEqual(image.gcsURI, gcsURI) - XCTAssertEqual(image.imagenImage.mimeType, mimeType) - XCTAssertEqual(image.imagenImage.gcsURI, gcsURI) - XCTAssertNil(image.imagenImage.bytesBase64Encoded) + XCTAssertEqual(image._imagenImage.mimeType, mimeType) + XCTAssertEqual(image._imagenImage.gcsURI, gcsURI) + XCTAssertNil(image._imagenImage.bytesBase64Encoded) } func testDecodeImage_missingGCSURI_throws() throws { diff --git a/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenInlineDataImageTests.swift b/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenInlineDataImageTests.swift index 8479f3e0079..3253716e221 100644 --- a/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenInlineDataImageTests.swift +++ b/FirebaseVertexAI/Tests/Unit/Types/Imagen/ImagenInlineDataImageTests.swift @@ -35,9 +35,9 @@ final class ImagenInlineDataImageTests: XCTestCase { XCTAssertEqual(image.mimeType, mimeType) XCTAssertEqual(image.data.base64EncodedString(), bytesBase64Encoded) - XCTAssertEqual(image.imagenImage.mimeType, mimeType) - XCTAssertEqual(image.imagenImage.bytesBase64Encoded, bytesBase64Encoded) - XCTAssertNil(image.imagenImage.gcsURI) + XCTAssertEqual(image._imagenImage.mimeType, mimeType) + XCTAssertEqual(image._imagenImage.bytesBase64Encoded, bytesBase64Encoded) + XCTAssertNil(image._imagenImage.gcsURI) } func testDecodeImage_missingBytesBase64Encoded_throws() throws {