Skip to content

Commit

Permalink
Remove ExpressibleByStringLiteral conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Jan 17, 2025
1 parent 054b6e1 commit bcb1e5c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 46 deletions.
11 changes: 4 additions & 7 deletions FirebaseVertexAI/Sources/APIVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 2 additions & 1 deletion FirebaseVertexAI/Sources/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions FirebaseVertexAI/Tests/Unit/APIVersionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 0 additions & 16 deletions FirebaseVertexAI/Tests/Unit/RequestOptionsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 5 additions & 8 deletions FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bcb1e5c

Please sign in to comment.