Skip to content

Commit

Permalink
[Vertex AI] Add simple integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Jun 5, 2024
1 parent 17165d1 commit d9d5fa7
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
68 changes: 68 additions & 0 deletions FirebaseVertexAI/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import FirebaseCore
import FirebaseVertexAI
import XCTest

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)
final class IntegrationTests: XCTestCase {
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
)
}

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

// MARK: - Generate Content

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 text = try XCTUnwrap(response.text).trimmingCharacters(in: .whitespacesAndNewlines)
XCTAssertEqual(text, "Mountain View")
}

// MARK: - Count Tokens

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

let response = try await model.countTokens(prompt)

XCTAssertEqual(response.totalTokens, 6)
XCTAssertEqual(response.totalBillableCharacters, 16)
}
}
Empty file.
8 changes: 8 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,14 @@ let package = Package(
.headerSearchPath("../../../"),
]
),
.testTarget(
name: "FirebaseVertexAIIntegration",
dependencies: ["FirebaseVertexAI", "SharedTestUtilities"],
path: "FirebaseVertexAI/Tests/Integration",
resources: [
.process("Resources"),
]
),
] + firestoreTargets(),
cLanguageStandard: .c99,
cxxLanguageStandard: CXXLanguageStandard.gnucxx14
Expand Down
Binary file added scripts/gha-encrypted/vertexai-integration.plist.gpg
Binary file not shown.
77 changes: 77 additions & 0 deletions scripts/spm_test_schemes/FirebaseVertexAIIntegration.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FirebaseVertexAIIntegration"
BuildableName = "FirebaseVertexAIIntegration"
BlueprintName = "FirebaseVertexAIIntegration"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FirebaseVertexAIIntegration"
BuildableName = "FirebaseVertexAIIntegration"
BlueprintName = "FirebaseVertexAIIntegration"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FirebaseVertexAIIntegration"
BuildableName = "FirebaseVertexAIIntegration"
BlueprintName = "FirebaseVertexAIIntegration"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

0 comments on commit d9d5fa7

Please sign in to comment.