diff --git a/FirebaseVertexAI/Sources/APIVersion.swift b/FirebaseVertexAI/Sources/APIVersion.swift index 44619e0efbd..640f2b947d9 100644 --- a/FirebaseVertexAI/Sources/APIVersion.swift +++ b/FirebaseVertexAI/Sources/APIVersion.swift @@ -13,16 +13,13 @@ // limitations under the License. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) -public struct APIVersion: ExpressibleByStringLiteral { - public static let v1 = APIVersion("v1") - public static let v1beta = APIVersion("v1beta") +public struct APIVersion { + public static let v1 = APIVersion(versionIdentifier: "v1") + public static let v1beta = APIVersion(versionIdentifier: "v1beta") let versionIdentifier: String - public init(stringLiteral versionIdentifier: String) { - guard !versionIdentifier.isEmpty else { - fatalError("The API version identifier must not be empty.") - } + init(versionIdentifier: String) { self.versionIdentifier = versionIdentifier } } diff --git a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift index 25f87c09a7d..e00d6c2974d 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift @@ -36,7 +36,8 @@ public struct RequestOptions { /// Initializes a request options object. /// /// - Parameters: - /// - timeout The request’s timeout interval in seconds; defaults to 180 seconds. + /// - timeout: The request’s timeout interval in seconds; defaults to 180 seconds. + /// - apiVersion: The API version to use in requests to the backend; defaults to v1beta. public init(timeout: TimeInterval = 180.0, apiVersion: APIVersion = .v1beta) { self.timeout = timeout self.apiVersion = apiVersion.versionIdentifier diff --git a/FirebaseVertexAI/Tests/Unit/APIVersionTests.swift b/FirebaseVertexAI/Tests/Unit/APIVersionTests.swift index d713009f405..0f9743b21a2 100644 --- a/FirebaseVertexAI/Tests/Unit/APIVersionTests.swift +++ b/FirebaseVertexAI/Tests/Unit/APIVersionTests.swift @@ -18,20 +18,6 @@ import XCTest @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) final class APIVersionTests: XCTestCase { - func testInitialize_stringLiteral() { - let apiVersion = APIVersion("test-version") - - XCTAssertEqual(apiVersion.versionIdentifier, "test-version") - } - - func testInitialize_stringConstant() { - let expectedVersion = "test-version" - - let apiVersion = APIVersion(stringLiteral: expectedVersion) - - XCTAssertEqual(apiVersion.versionIdentifier, expectedVersion) - } - func testInitialize_v1() { let apiVersion: APIVersion = .v1 diff --git a/FirebaseVertexAI/Tests/Unit/RequestOptionsTest.swift b/FirebaseVertexAI/Tests/Unit/RequestOptionsTest.swift index b8f6f82c7c8..adf9441d716 100644 --- a/FirebaseVertexAI/Tests/Unit/RequestOptionsTest.swift +++ b/FirebaseVertexAI/Tests/Unit/RequestOptionsTest.swift @@ -37,22 +37,6 @@ final class RequestOptionsTests: XCTestCase { XCTAssertEqual(requestOptions.apiVersion, defaultAPIVersion) } - func testInitialize_apiVersion_stringLiteral() { - let requestOptions = RequestOptions(apiVersion: "test-version") - - XCTAssertEqual(requestOptions.timeout, defaultTimeout) - XCTAssertEqual(requestOptions.apiVersion, "test-version") - } - - func testInitialize_apiVersion_stringConstant() { - let expectedVersion = "test-version" - - let requestOptions = RequestOptions(apiVersion: APIVersion(stringLiteral: expectedVersion)) - - XCTAssertEqual(requestOptions.timeout, defaultTimeout) - XCTAssertEqual(requestOptions.apiVersion, expectedVersion) - } - func testInitialize_apiVersion_v1() { let requestOptions = RequestOptions(apiVersion: .v1) diff --git a/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift b/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift index 82e9a73aa3b..30f16851260 100644 --- a/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift +++ b/FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift @@ -38,14 +38,10 @@ final class VertexAIAPITests: XCTestCase { parts: TextPart("Talk like a pirate.") ) - let apiVersionID = "v1" - let apiVersion = APIVersion.v1 - let _ = RequestOptions() + let requestOptions = RequestOptions() + let _ = RequestOptions(timeout: 30.0) let _ = RequestOptions(apiVersion: .v1) - let _ = RequestOptions(apiVersion: "v1") - let _ = RequestOptions(apiVersion: APIVersion(stringLiteral: "v1")) - let _ = RequestOptions(apiVersion: APIVersion(stringLiteral: apiVersionID)) - let _ = RequestOptions(apiVersion: apiVersion) + let _ = RequestOptions(timeout: 60.0, apiVersion: .v1) // Instantiate Vertex AI SDK - Default App let vertexAI = VertexAI.vertexAI() @@ -79,7 +75,8 @@ final class VertexAIAPITests: XCTestCase { modelName: "gemini-1.0-pro", generationConfig: config, // Optional safetySettings: filters, // Optional - systemInstruction: systemInstruction // Optional + systemInstruction: systemInstruction, // Optional + requestOptions: requestOptions // Optional ) // Full Typed Usage