Skip to content

Commit 1e7137e

Browse files
authored
[Vertex AI] Add environment variable to control integration tests (#13095)
1 parent 1c02a95 commit 1e7137e

File tree

3 files changed

+48
-50
lines changed

3 files changed

+48
-50
lines changed

.github/workflows/vertexai.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ jobs:
4343
spm-integration:
4444
strategy:
4545
matrix:
46-
target: [macOS]
46+
target: [iOS]
4747
os: [macos-14]
4848
include:
4949
- os: macos-14
5050
xcode: Xcode_15.2
5151
runs-on: ${{ matrix.os }}
5252
env:
53+
TEST_RUNNER_VertexAIRunIntegrationTests: 1
5354
FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
5455
plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
5556
steps:

FirebaseVertexAI/Tests/Integration/IntegrationTests.swift

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,59 @@ import FirebaseCore
1616
import FirebaseVertexAI
1717
import XCTest
1818

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+
}
4746

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()
5250
}
51+
}
5352

54-
// MARK: - Generate Content
53+
// MARK: - Generate Content
5554

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."
5857

59-
let response = try await model.generateContent(prompt)
58+
let response = try await model.generateContent(prompt)
6059

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+
}
6463

65-
// MARK: - Count Tokens
64+
// MARK: - Count Tokens
6665

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?"
6968

70-
let response = try await model.countTokens(prompt)
69+
let response = try await model.countTokens(prompt)
7170

72-
XCTAssertEqual(response.totalTokens, 6)
73-
XCTAssertEqual(response.totalBillableCharacters, 16)
74-
}
71+
XCTAssertEqual(response.totalTokens, 6)
72+
XCTAssertEqual(response.totalBillableCharacters, 16)
7573
}
76-
77-
#endif // os(macOS)
74+
}

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ let package = Package(
13871387
),
13881388
.testTarget(
13891389
name: "FirebaseVertexAIIntegration",
1390-
dependencies: ["FirebaseVertexAI", "SharedTestUtilities"],
1390+
dependencies: ["FirebaseVertexAI"],
13911391
path: "FirebaseVertexAI/Tests/Integration",
13921392
resources: [
13931393
.process("Resources"),

0 commit comments

Comments
 (0)