Skip to content

Commit 5ed86cd

Browse files
authored
[Vertex AI] Set default request timeout to 180 seconds (#13722)
1 parent 801cbb3 commit 5ed86cd

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

FirebaseVertexAI/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
is now optional (`Int?`); it may be `null` in cases such as when a
2323
`GenerateContentRequest` contains only images or other non-text content.
2424
(#13721)
25+
- [changed] The default request timeout is now 180 seconds instead of the
26+
platform-default value of 60 seconds for a `URLRequest`; this timeout may
27+
still be customized in `RequestOptions`. (#13722)
2528

2629
# 11.3.0
2730
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)

FirebaseVertexAI/Sources/GenerativeAIRequest.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protocol GenerativeAIRequest: Encodable {
2828
public struct RequestOptions {
2929
/// The request’s timeout interval in seconds; if not specified uses the default value for a
3030
/// `URLRequest`.
31-
let timeout: TimeInterval?
31+
let timeout: TimeInterval
3232

3333
/// The API version to use in requests to the backend.
3434
///
@@ -38,9 +38,8 @@ public struct RequestOptions {
3838
/// Initializes a request options object.
3939
///
4040
/// - Parameters:
41-
/// - timeout The request’s timeout interval in seconds; if not specified uses the default value
42-
/// for a `URLRequest`.
43-
public init(timeout: TimeInterval? = nil) {
41+
/// - timeout The request’s timeout interval in seconds; defaults to 180 seconds.
42+
public init(timeout: TimeInterval = 180.0) {
4443
self.timeout = timeout
4544
}
4645
}

FirebaseVertexAI/Sources/GenerativeAIService.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,7 @@ struct GenerativeAIService {
205205
let encoder = JSONEncoder()
206206
encoder.keyEncodingStrategy = .convertToSnakeCase
207207
urlRequest.httpBody = try encoder.encode(request)
208-
209-
if let timeoutInterval = request.options.timeout {
210-
urlRequest.timeoutInterval = timeoutInterval
211-
}
208+
urlRequest.timeoutInterval = request.options.timeout
212209

213210
return urlRequest
214211
}

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ final class GenerativeModelTests: XCTestCase {
13191319
private func httpRequestHandler(forResource name: String,
13201320
withExtension ext: String,
13211321
statusCode: Int = 200,
1322-
timeout: TimeInterval = URLRequest.defaultTimeoutInterval(),
1322+
timeout: TimeInterval = RequestOptions().timeout,
13231323
appCheckToken: String? = nil,
13241324
authToken: String? = nil) throws -> ((URLRequest) throws -> (
13251325
URLResponse,
@@ -1368,14 +1368,6 @@ private extension String {
13681368
}
13691369
}
13701370

1371-
private extension URLRequest {
1372-
/// Returns the default `timeoutInterval` for a `URLRequest`.
1373-
static func defaultTimeoutInterval() -> TimeInterval {
1374-
let placeholderURL = URL(string: "https://example.com")!
1375-
return URLRequest(url: placeholderURL).timeoutInterval
1376-
}
1377-
}
1378-
13791371
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
13801372
class AppCheckInteropFake: NSObject, AppCheckInterop {
13811373
/// The placeholder token value returned when an error occurs

0 commit comments

Comments
 (0)