From b5d593240e50546b785d1b5dec84a1e5b55f5f99 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 25 Sep 2024 16:29:53 -0400 Subject: [PATCH 1/4] [Vertex AI] Set default request timeout to 180 seconds --- FirebaseVertexAI/CHANGELOG.md | 3 +++ FirebaseVertexAI/Sources/GenerativeAIRequest.swift | 7 +++---- FirebaseVertexAI/Sources/GenerativeAIService.swift | 5 +---- FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift | 10 +--------- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index f3d471969c3..e0a0d74b586 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -22,6 +22,9 @@ is now optional (`Int?`); it may be `null` in cases such as when a `GenerateContentRequest` contains only images or other non-text content. (#13721) +- [changed] The default request timeout is now 180 seconds instead of the + platform-default value for a `URLRequest`; this timeout may still be + customized in `RequestOptions`. # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606) diff --git a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift index 08b178d5808..55f7af7d1be 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIRequest.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIRequest.swift @@ -28,7 +28,7 @@ protocol GenerativeAIRequest: Encodable { public struct RequestOptions { /// The request’s timeout interval in seconds; if not specified uses the default value for a /// `URLRequest`. - let timeout: TimeInterval? + let timeout: TimeInterval /// The API version to use in requests to the backend. let apiVersion = "v2beta" @@ -36,9 +36,8 @@ public struct RequestOptions { /// Initializes a request options object. /// /// - Parameters: - /// - timeout The request’s timeout interval in seconds; if not specified uses the default value - /// for a `URLRequest`. - public init(timeout: TimeInterval? = nil) { + /// - timeout The request’s timeout interval in seconds; defaults to 180 seconds. + public init(timeout: TimeInterval = 180.0) { self.timeout = timeout } } diff --git a/FirebaseVertexAI/Sources/GenerativeAIService.swift b/FirebaseVertexAI/Sources/GenerativeAIService.swift index 3ebbf69f102..36a208440fb 100644 --- a/FirebaseVertexAI/Sources/GenerativeAIService.swift +++ b/FirebaseVertexAI/Sources/GenerativeAIService.swift @@ -191,10 +191,7 @@ struct GenerativeAIService { let encoder = JSONEncoder() encoder.keyEncodingStrategy = .convertToSnakeCase urlRequest.httpBody = try encoder.encode(request) - - if let timeoutInterval = request.options.timeout { - urlRequest.timeoutInterval = timeoutInterval - } + urlRequest.timeoutInterval = request.options.timeout return urlRequest } diff --git a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift index c7cfe36df70..0dc352291b2 100644 --- a/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift +++ b/FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift @@ -1267,7 +1267,7 @@ final class GenerativeModelTests: XCTestCase { private func httpRequestHandler(forResource name: String, withExtension ext: String, statusCode: Int = 200, - timeout: TimeInterval = URLRequest.defaultTimeoutInterval(), + timeout: TimeInterval = RequestOptions().timeout, appCheckToken: String? = nil, authToken: String? = nil) throws -> ((URLRequest) throws -> ( URLResponse, @@ -1316,14 +1316,6 @@ private extension String { } } -private extension URLRequest { - /// Returns the default `timeoutInterval` for a `URLRequest`. - static func defaultTimeoutInterval() -> TimeInterval { - let placeholderURL = URL(string: "https://example.com")! - return URLRequest(url: placeholderURL).timeoutInterval - } -} - @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) class AppCheckInteropFake: NSObject, AppCheckInterop { /// The placeholder token value returned when an error occurs From 5b8b614ab26153b8703ed11b6fbbac1ace369955 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 25 Sep 2024 16:33:21 -0400 Subject: [PATCH 2/4] Add PR# to CHANGELOG entry --- FirebaseVertexAI/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index e0a0d74b586..00500c4f94b 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -24,7 +24,7 @@ (#13721) - [changed] The default request timeout is now 180 seconds instead of the platform-default value for a `URLRequest`; this timeout may still be - customized in `RequestOptions`. + customized in `RequestOptions`. (#13722) # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606) From e70e30617409846878b971a65c59c5ba54ca16d5 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 26 Sep 2024 10:59:49 -0400 Subject: [PATCH 3/4] Re-word changelog entry --- FirebaseVertexAI/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index 00500c4f94b..af12c6485ef 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -23,8 +23,8 @@ `GenerateContentRequest` contains only images or other non-text content. (#13721) - [changed] The default request timeout is now 180 seconds instead of the - platform-default value for a `URLRequest`; this timeout may still be - customized in `RequestOptions`. (#13722) + platform-default value for a `URLRequest` (typically 60 seconds); this timeout + may still be customized in `RequestOptions`. (#13722) # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606) From fa029854fad40870d8041112140ee462d75d4399 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 26 Sep 2024 11:02:22 -0400 Subject: [PATCH 4/4] Another re-word of changelog --- FirebaseVertexAI/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index af12c6485ef..21271329704 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -23,8 +23,8 @@ `GenerateContentRequest` contains only images or other non-text content. (#13721) - [changed] The default request timeout is now 180 seconds instead of the - platform-default value for a `URLRequest` (typically 60 seconds); this timeout - may still be customized in `RequestOptions`. (#13722) + platform-default value of 60 seconds for a `URLRequest`; this timeout may + still be customized in `RequestOptions`. (#13722) # 11.3.0 - [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)