Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vertex AI] Add environment variable to control integration tests #13095

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/vertexai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ jobs:
spm-integration:
strategy:
matrix:
target: [macOS]
target: [iOS]
os: [macos-14]
include:
- os: macos-14
xcode: Xcode_15.2
runs-on: ${{ matrix.os }}
env:
TEST_RUNNER_VertexAIRunIntegrationTests: 1
andrewheard marked this conversation as resolved.
Show resolved Hide resolved
FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
steps:
Expand Down
93 changes: 45 additions & 48 deletions FirebaseVertexAI/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,59 @@ import FirebaseCore
import FirebaseVertexAI
import XCTest

// These tests are functional on other platforms but are compiled-out of non-macOS platforms to
// avoid re-running them as part of `swift-build-run` job (iOS-only) in the `spm` workflow on CI:
// https://github.com/firebase/firebase-ios-sdk/blob/0492e83cb22833ec548e61d854bb7b830e83b826/.github/workflows/spm.yml#L57
// Since these requests are billed, we are running them more sparsely than the unit tests.
#if os(macOS)

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)
final class IntegrationTests: XCTestCase {
// Set temperature, topP and topK to lowest allowed values to make responses more deterministic.
let generationConfig = GenerationConfig(temperature: 0.0, topP: 0.0, topK: 1)

var vertex: VertexAI!
var model: GenerativeModel!

override func setUp() async throws {
let plistPath = try XCTUnwrap(Bundle.module.path(
forResource: "GoogleService-Info",
ofType: "plist"
))
let options = try XCTUnwrap(FirebaseOptions(contentsOfFile: plistPath))
FirebaseApp.configure(options: options)

vertex = VertexAI.vertexAI()
model = vertex.generativeModel(
modelName: "gemini-1.5-flash",
generationConfig: generationConfig
)
}
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)
final class IntegrationTests: XCTestCase {
// Set temperature, topP and topK to lowest allowed values to make responses more deterministic.
let generationConfig = GenerationConfig(temperature: 0.0, topP: 0.0, topK: 1)

var vertex: VertexAI!
var model: GenerativeModel!

override func setUp() async throws {
try XCTSkipIf(ProcessInfo.processInfo.environment["VertexAIRunIntegrationTests"] == nil, """
Vertex AI integration tests skipped; to enable them, set the VertexAIRunIntegrationTests \
environment variable in Xcode or CI jobs.
""")

let plistPath = try XCTUnwrap(Bundle.module.path(
forResource: "GoogleService-Info",
ofType: "plist"
))
let options = try XCTUnwrap(FirebaseOptions(contentsOfFile: plistPath))
FirebaseApp.configure(options: options)

vertex = VertexAI.vertexAI()
model = vertex.generativeModel(
modelName: "gemini-1.5-flash",
generationConfig: generationConfig
)
}

override func tearDown() async throws {
if let app = FirebaseApp.app() {
await app.delete()
}
override func tearDown() async throws {
if let app = FirebaseApp.app() {
await app.delete()
}
}

// MARK: - Generate Content
// MARK: - Generate Content

func testGenerateContent() async throws {
let prompt = "Where is Google headquarters located? Answer with the city name only."
func testGenerateContent() async throws {
let prompt = "Where is Google headquarters located? Answer with the city name only."

let response = try await model.generateContent(prompt)
let response = try await model.generateContent(prompt)

let text = try XCTUnwrap(response.text).trimmingCharacters(in: .whitespacesAndNewlines)
XCTAssertEqual(text, "Mountain View")
}
let text = try XCTUnwrap(response.text).trimmingCharacters(in: .whitespacesAndNewlines)
XCTAssertEqual(text, "Mountain View")
}

// MARK: - Count Tokens
// MARK: - Count Tokens

func testCountTokens() async throws {
let prompt = "Why is the sky blue?"
func testCountTokens() async throws {
let prompt = "Why is the sky blue?"

let response = try await model.countTokens(prompt)
let response = try await model.countTokens(prompt)

XCTAssertEqual(response.totalTokens, 6)
XCTAssertEqual(response.totalBillableCharacters, 16)
}
XCTAssertEqual(response.totalTokens, 6)
XCTAssertEqual(response.totalBillableCharacters, 16)
}

#endif // os(macOS)
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ let package = Package(
),
.testTarget(
name: "FirebaseVertexAIIntegration",
dependencies: ["FirebaseVertexAI", "SharedTestUtilities"],
dependencies: ["FirebaseVertexAI"],
path: "FirebaseVertexAI/Tests/Integration",
resources: [
.process("Resources"),
Expand Down
Loading