Skip to content

Commit 3e515cb

Browse files
authored
[AI] Annotate Imagen integration tests as deprecated (#16054)
1 parent dabe9f0 commit 3e515cb

6 files changed

Lines changed: 9 additions & 342 deletions

File tree

FirebaseAI/Sources/Types/Internal/Imagen/ImagenGCSImage.swift

Lines changed: 0 additions & 101 deletions
This file was deleted.

FirebaseAI/Sources/Types/Public/Imagen/ImagenModel.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,6 @@ public final class ImagenModel {
9393
)
9494
}
9595

96-
/// Generates images using the Imagen model and stores them in Cloud Storage (GCS) for Firebase.
97-
///
98-
/// The generated images are stored in a subdirectory of the requested `gcsURI`, named as a random
99-
/// numeric hash. For example, for the `gcsURI` `"gs://bucket-name/path/"`, the generated images
100-
/// are stored in `"gs://bucket-name/path/1234567890123/"` with the names `sample_0.png`,
101-
/// `sample_1.png`, `sample_2.png`, ..., `sample_N.png`. In this example, `1234567890123` is the
102-
/// hash value and `N` is the number of images that were generated, up to the number requested in
103-
/// ``ImagenGenerationConfig/numberOfImages``. The individual ``ImagenGCSImage/gcsURI`` is
104-
/// provided for each of the generated ``ImagenGenerationResponse/images``.
105-
///
106-
/// > Note: By default, 1 image sample is generated; see ``ImagenGenerationConfig/numberOfImages``
107-
/// to configure the number of images that are generated.
108-
///
109-
/// - Parameters:
110-
/// - prompt: A text prompt describing the image(s) to generate.
111-
/// - gcsURI: The Cloud Storage (GCS) for Firebase URI where the generated images are stored.
112-
/// This is a `"gs://"`-prefixed URI , for example, `"gs://bucket-name/path/"`.
113-
///
114-
func generateImages(prompt: String, gcsURI: String) async throws
115-
-> ImagenGenerationResponse<ImagenGCSImage> {
116-
return try await generateImages(
117-
prompt: prompt,
118-
parameters: ImagenModel.imageGenerationParameters(
119-
storageURI: gcsURI,
120-
generationConfig: generationConfig,
121-
safetySettings: safetySettings
122-
)
123-
)
124-
}
125-
12696
func generateImages<T>(prompt: String,
12797
parameters: ImageGenerationParameters) async throws
12898
-> ImagenGenerationResponse<T> where T: Decodable, T: ImagenImageRepresentable {

FirebaseAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import Testing
2323
import UIKit
2424
#endif // canImport(UIKit)
2525

26-
// TODO(#14452): Remove `@testable import` when `generateImages(prompt:gcsURI:)` is public.
27-
@testable import class FirebaseAILogic.ImagenModel
28-
2926
@Suite(
3027
.enabled(
3128
if: ProcessInfo.processInfo.environment["VTXIntegrationImagen"] != nil,
@@ -44,7 +41,9 @@ struct ImagenIntegrationTests {
4441
storage = Storage.storage()
4542
}
4643

47-
@Test func generateImage_inlineImage() async throws {
44+
@Test
45+
@available(*, deprecated)
46+
func generateImage_inlineImage() async throws {
4847
let generationConfig = ImagenGenerationConfig(
4948
negativePrompt: "snow, frost",
5049
aspectRatio: .portrait3x4,
@@ -75,45 +74,9 @@ struct ImagenIntegrationTests {
7574
#endif // canImport(UIKit)
7675
}
7776

78-
@Test func generateImages_gcsImages() async throws {
79-
let generationConfig = ImagenGenerationConfig(
80-
numberOfImages: 3,
81-
aspectRatio: .landscape16x9,
82-
imageFormat: .jpeg(compressionQuality: 60),
83-
addWatermark: true
84-
)
85-
let model = vertex.imagenModel(
86-
modelName: "imagen-3.0-fast-generate-001",
87-
generationConfig: generationConfig,
88-
safetySettings: ImagenSafetySettings(
89-
safetyFilterLevel: .blockMediumAndAbove,
90-
personFilterLevel: .blockAll
91-
)
92-
)
93-
let prompt = "A dense jungle with light streaming through the treetops"
94-
let storageRef = storage.reference(
95-
withPath: "/vertexai/imagen/authenticated/user/\(userID1)"
96-
)
97-
98-
let response = try await model.generateImages(prompt: prompt, gcsURI: storageRef.gsURI)
99-
100-
#expect(response.filteredReason == nil)
101-
#expect(response.images.count == generationConfig.numberOfImages)
102-
for image in response.images {
103-
#expect(image.mimeType == "image/jpeg")
104-
let imageRef = storage.reference(forURL: image.gcsURI)
105-
let imageData = try await imageRef.data(maxSize: 1_000_000) // ~1MB
106-
#expect(imageData.isEmpty == false)
107-
#if canImport(UIKit)
108-
let uiImage = try #require(UIImage(data: imageData))
109-
#expect(uiImage.size.width == 1408.0)
110-
#expect(uiImage.size.height == 768.0)
111-
#endif // canImport(UIKit)
112-
try await imageRef.delete()
113-
}
114-
}
115-
116-
@Test func generateImage_allImagesFilteredOut() async throws {
77+
@Test
78+
@available(*, deprecated)
79+
func generateImage_allImagesFilteredOut() async throws {
11780
let generationConfig = ImagenGenerationConfig(numberOfImages: 2, imageFormat: .jpeg())
11881
let model = vertex.imagenModel(
11982
modelName: "imagen-3.0-fast-generate-001",
@@ -134,8 +97,4 @@ struct ImagenIntegrationTests {
13497
return error.localizedDescription.contains("39322892")
13598
}
13699
}
137-
138-
// TODO(#14221): Add an integration test for the prompt being blocked.
139-
140-
// TODO(#14452): Add integration tests for validating that Storage Rules are enforced.
141100
}

FirebaseAI/Tests/Unit/Types/Imagen/ImagenGCSImageTests.swift

Lines changed: 0 additions & 80 deletions
This file was deleted.

FirebaseAI/Tests/Unit/Types/Imagen/ImagenGenerationRequestTests.swift

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,6 @@ final class ImagenGenerationRequestTests: XCTestCase {
6666
)
6767
}
6868

69-
func testInitializeRequest_fileDataImage() throws {
70-
let request = ImagenGenerationRequest<ImagenGCSImage>(
71-
model: modelName,
72-
apiConfig: apiConfig,
73-
options: requestOptions,
74-
instances: [instance],
75-
parameters: parameters
76-
)
77-
78-
XCTAssertEqual(request.model, modelName)
79-
XCTAssertEqual(request.options, requestOptions)
80-
XCTAssertEqual(request.instances, [instance])
81-
XCTAssertEqual(request.parameters, parameters)
82-
XCTAssertEqual(
83-
try request.getURL(),
84-
URL(string:
85-
"\(apiConfig.service.endpoint.rawValue)/\(apiConfig.version.rawValue)/\(modelName):predict")
86-
)
87-
}
88-
8969
// MARK: - Encoding Tests
9070

9171
func testEncodeRequest_inlineDataImage() throws {
@@ -117,34 +97,4 @@ final class ImagenGenerationRequestTests: XCTestCase {
11797
}
11898
""")
11999
}
120-
121-
func testEncodeRequest_fileDataImage() throws {
122-
let request = ImagenGenerationRequest<ImagenGCSImage>(
123-
model: modelName,
124-
apiConfig: apiConfig,
125-
options: RequestOptions(),
126-
instances: [instance],
127-
parameters: parameters
128-
)
129-
130-
let jsonData = try encoder.encode(request)
131-
132-
let json = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
133-
XCTAssertEqual(json, """
134-
{
135-
"instances" : [
136-
{
137-
"prompt" : "\(instance.prompt)"
138-
}
139-
],
140-
"parameters" : {
141-
"aspectRatio" : "\(aspectRatio)",
142-
"includeRaiReason" : \(includeResponsibleAIFilterReason),
143-
"includeSafetyAttributes" : \(includeSafetyAttributes),
144-
"safetySetting" : "\(safetyFilterLevel)",
145-
"sampleCount" : \(sampleCount)
146-
}
147-
}
148-
""")
149-
}
150100
}

0 commit comments

Comments
 (0)