@@ -16,62 +16,59 @@ import FirebaseCore
16
16
import FirebaseVertexAI
17
17
import XCTest
18
18
19
- // These tests are functional on other platforms but are compiled-out of non-macOS platforms to
20
- // avoid re-running them as part of `swift-build-run` job (iOS-only) in the `spm` workflow on CI:
21
- // https://github.com/firebase/firebase-ios-sdk/blob/0492e83cb22833ec548e61d854bb7b830e83b826/.github/workflows/spm.yml#L57
22
- // Since these requests are billed, we are running them more sparsely than the unit tests.
23
- #if os(macOS)
24
-
25
- @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , * )
26
- final class IntegrationTests : XCTestCase {
27
- // Set temperature, topP and topK to lowest allowed values to make responses more deterministic.
28
- let generationConfig = GenerationConfig ( temperature: 0.0 , topP: 0.0 , topK: 1 )
29
-
30
- var vertex : VertexAI !
31
- var model : GenerativeModel !
32
-
33
- override func setUp( ) async throws {
34
- let plistPath = try XCTUnwrap ( Bundle . module. path (
35
- forResource: " GoogleService-Info " ,
36
- ofType: " plist "
37
- ) )
38
- let options = try XCTUnwrap ( FirebaseOptions ( contentsOfFile: plistPath) )
39
- FirebaseApp . configure ( options: options)
40
-
41
- vertex = VertexAI . vertexAI ( )
42
- model = vertex. generativeModel (
43
- modelName: " gemini-1.5-flash " ,
44
- generationConfig: generationConfig
45
- )
46
- }
19
+ @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , * )
20
+ final class IntegrationTests : XCTestCase {
21
+ // Set temperature, topP and topK to lowest allowed values to make responses more deterministic.
22
+ let generationConfig = GenerationConfig ( temperature: 0.0 , topP: 0.0 , topK: 1 )
23
+
24
+ var vertex : VertexAI !
25
+ var model : GenerativeModel !
26
+
27
+ override func setUp( ) async throws {
28
+ try XCTSkipIf ( ProcessInfo . processInfo. environment [ " VertexAIRunIntegrationTests " ] == nil , """
29
+ Vertex AI integration tests skipped; to enable them, set the VertexAIRunIntegrationTests \
30
+ environment variable in Xcode or CI jobs.
31
+ """ )
32
+
33
+ let plistPath = try XCTUnwrap ( Bundle . module. path (
34
+ forResource: " GoogleService-Info " ,
35
+ ofType: " plist "
36
+ ) )
37
+ let options = try XCTUnwrap ( FirebaseOptions ( contentsOfFile: plistPath) )
38
+ FirebaseApp . configure ( options: options)
39
+
40
+ vertex = VertexAI . vertexAI ( )
41
+ model = vertex. generativeModel (
42
+ modelName: " gemini-1.5-flash " ,
43
+ generationConfig: generationConfig
44
+ )
45
+ }
47
46
48
- override func tearDown( ) async throws {
49
- if let app = FirebaseApp . app ( ) {
50
- await app. delete ( )
51
- }
47
+ override func tearDown( ) async throws {
48
+ if let app = FirebaseApp . app ( ) {
49
+ await app. delete ( )
52
50
}
51
+ }
53
52
54
- // MARK: - Generate Content
53
+ // MARK: - Generate Content
55
54
56
- func testGenerateContent( ) async throws {
57
- let prompt = " Where is Google headquarters located? Answer with the city name only. "
55
+ func testGenerateContent( ) async throws {
56
+ let prompt = " Where is Google headquarters located? Answer with the city name only. "
58
57
59
- let response = try await model. generateContent ( prompt)
58
+ let response = try await model. generateContent ( prompt)
60
59
61
- let text = try XCTUnwrap ( response. text) . trimmingCharacters ( in: . whitespacesAndNewlines)
62
- XCTAssertEqual ( text, " Mountain View " )
63
- }
60
+ let text = try XCTUnwrap ( response. text) . trimmingCharacters ( in: . whitespacesAndNewlines)
61
+ XCTAssertEqual ( text, " Mountain View " )
62
+ }
64
63
65
- // MARK: - Count Tokens
64
+ // MARK: - Count Tokens
66
65
67
- func testCountTokens( ) async throws {
68
- let prompt = " Why is the sky blue? "
66
+ func testCountTokens( ) async throws {
67
+ let prompt = " Why is the sky blue? "
69
68
70
- let response = try await model. countTokens ( prompt)
69
+ let response = try await model. countTokens ( prompt)
71
70
72
- XCTAssertEqual ( response. totalTokens, 6 )
73
- XCTAssertEqual ( response. totalBillableCharacters, 16 )
74
- }
71
+ XCTAssertEqual ( response. totalTokens, 6 )
72
+ XCTAssertEqual ( response. totalBillableCharacters, 16 )
75
73
}
76
-
77
- #endif // os(macOS)
74
+ }
0 commit comments