Преглед изворни кода

Add endpoint version to RequestOptions.

This change introduces a new  property in the  struct
that allows users to specify whether they want to use the v1 or v1beta endpoint. The default
value is set to .

A new test file  was added to verify the behavior of the new property.
labs-code-app[bot] пре 1 година
родитељ
комит
e56d6840ee

+ 11 - 1
FirebaseVertexAI/Sources/GenerativeAIRequest.swift

@@ -32,12 +32,22 @@ public struct RequestOptions {
 
   /// The API version to use in requests to the backend.
   let apiVersion = "v1beta"
+    
+  public enum EndpointVersion: String {
+      case v1 = "v1"
+      case v1beta = "v1beta"
+  }
+
+  /// The endpoint version to use in requests to the backend.
+  let endpointVersion: EndpointVersion
 
   /// Initializes a request options object.
   ///
   /// - Parameters:
   ///   - timeout The request’s timeout interval in seconds; defaults to 180 seconds.
-  public init(timeout: TimeInterval = 180.0) {
+  ///   - endpointVersion The endpoint version to use in request to the backend; defaults to `v1beta`.
+  public init(timeout: TimeInterval = 180.0, endpointVersion: EndpointVersion = .v1beta) {
     self.timeout = timeout
+    self.endpointVersion = endpointVersion
   }
 }

+ 40 - 0
FirebaseVertexAI/Tests/Unit/EndpointVersionTests.swift

@@ -0,0 +1,40 @@
+// 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 XCTest
+@testable import FirebaseVertexAI
+
+@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
+final class EndpointVersionTests: XCTestCase {
+    func test_default_is_v1beta() {
+        // Given
+        let requestOptions = RequestOptions()
+        // When
+        XCTAssertEqual(requestOptions.endpointVersion, .v1beta)
+    }
+
+    func test_can_set_v1() {
+        // Given
+        let requestOptions = RequestOptions(endpointVersion: .v1)
+        // When
+        XCTAssertEqual(requestOptions.endpointVersion, .v1)
+    }
+    
+    func test_can_set_v1beta() {
+        // Given
+        let requestOptions = RequestOptions(endpointVersion: .v1beta)
+        // When
+        XCTAssertEqual(requestOptions.endpointVersion, .v1beta)
+    }
+}