@@ -16,6 +16,10 @@ import FirebaseCore
1616import FirebaseVertexAI
1717import XCTest
1818
19+ #if canImport(UIKit)
20+ import UIKit
21+ #endif // canImport(UIKit)
22+
1923// These snippet tests are intentionally skipped in CI jobs; see the README file in this directory
2024// for instructions on running them manually.
2125
@@ -38,59 +42,61 @@ final class MultimodalSnippets: XCTestCase {
3842 await FirebaseApp . deleteDefaultAppForSnippets ( )
3943 }
4044
41- func testMultimodalOneImageNonStreaming( ) async throws {
42- guard let image = UIImage ( systemName: " bicycle " ) else { fatalError ( ) }
45+ #if canImport(UIKit)
46+ func testMultimodalOneImageNonStreaming( ) async throws {
47+ guard let image = UIImage ( systemName: " bicycle " ) else { fatalError ( ) }
4348
44- // Provide a text prompt to include with the image
45- let prompt = " What's in this picture? "
49+ // Provide a text prompt to include with the image
50+ let prompt = " What's in this picture? "
4651
47- // To generate text output, call generateContent and pass in the prompt
48- let response = try await model. generateContent ( image, prompt)
49- print ( response. text ?? " No text in response. " )
50- }
52+ // To generate text output, call generateContent and pass in the prompt
53+ let response = try await model. generateContent ( image, prompt)
54+ print ( response. text ?? " No text in response. " )
55+ }
5156
52- func testMultimodalOneImageStreaming( ) async throws {
53- guard let image = UIImage ( systemName: " bicycle " ) else { fatalError ( ) }
57+ func testMultimodalOneImageStreaming( ) async throws {
58+ guard let image = UIImage ( systemName: " bicycle " ) else { fatalError ( ) }
5459
55- // Provide a text prompt to include with the image
56- let prompt = " What's in this picture? "
60+ // Provide a text prompt to include with the image
61+ let prompt = " What's in this picture? "
5762
58- // To stream generated text output, call generateContentStream and pass in the prompt
59- let contentStream = try model. generateContentStream ( image, prompt)
60- for try await chunk in contentStream {
61- if let text = chunk. text {
62- print ( text)
63+ // To stream generated text output, call generateContentStream and pass in the prompt
64+ let contentStream = try model. generateContentStream ( image, prompt)
65+ for try await chunk in contentStream {
66+ if let text = chunk. text {
67+ print ( text)
68+ }
6369 }
6470 }
65- }
6671
67- func testMultimodalMultiImagesNonStreaming( ) async throws {
68- guard let image1 = UIImage ( systemName: " car " ) else { fatalError ( ) }
69- guard let image2 = UIImage ( systemName: " car.2 " ) else { fatalError ( ) }
72+ func testMultimodalMultiImagesNonStreaming( ) async throws {
73+ guard let image1 = UIImage ( systemName: " car " ) else { fatalError ( ) }
74+ guard let image2 = UIImage ( systemName: " car.2 " ) else { fatalError ( ) }
7075
71- // Provide a text prompt to include with the images
72- let prompt = " What's different between these pictures? "
76+ // Provide a text prompt to include with the images
77+ let prompt = " What's different between these pictures? "
7378
74- // To generate text output, call generateContent and pass in the prompt
75- let response = try await model. generateContent ( image1, image2, prompt)
76- print ( response. text ?? " No text in response. " )
77- }
79+ // To generate text output, call generateContent and pass in the prompt
80+ let response = try await model. generateContent ( image1, image2, prompt)
81+ print ( response. text ?? " No text in response. " )
82+ }
7883
79- func testMultimodalMultiImagesStreaming( ) async throws {
80- guard let image1 = UIImage ( systemName: " car " ) else { fatalError ( ) }
81- guard let image2 = UIImage ( systemName: " car.2 " ) else { fatalError ( ) }
84+ func testMultimodalMultiImagesStreaming( ) async throws {
85+ guard let image1 = UIImage ( systemName: " car " ) else { fatalError ( ) }
86+ guard let image2 = UIImage ( systemName: " car.2 " ) else { fatalError ( ) }
8287
83- // Provide a text prompt to include with the images
84- let prompt = " What's different between these pictures? "
88+ // Provide a text prompt to include with the images
89+ let prompt = " What's different between these pictures? "
8590
86- // To stream generated text output, call generateContentStream and pass in the prompt
87- let contentStream = try model. generateContentStream ( image1, image2, prompt)
88- for try await chunk in contentStream {
89- if let text = chunk. text {
90- print ( text)
91+ // To stream generated text output, call generateContentStream and pass in the prompt
92+ let contentStream = try model. generateContentStream ( image1, image2, prompt)
93+ for try await chunk in contentStream {
94+ if let text = chunk. text {
95+ print ( text)
96+ }
9197 }
9298 }
93- }
99+ #endif // canImport(UIKit)
94100
95101 func testMultimodalVideoNonStreaming( ) async throws {
96102 // Provide the video as `Data` with the appropriate MIME type
0 commit comments