Skip to content

Commit b5d5932

Browse files
committed
[Vertex AI] Set default request timeout to 180 seconds
1 parent b1a19b4 commit b5d5932

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 for a `URLRequest`; this timeout may still be
27+
customized in `RequestOptions`.
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,17 +28,16 @@ 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
let apiVersion = "v2beta"
3535

3636
/// Initializes a request options object.
3737
///
3838
/// - Parameters:
39-
/// - timeout The request’s timeout interval in seconds; if not specified uses the default value
40-
/// for a `URLRequest`.
41-
public init(timeout: TimeInterval? = nil) {
39+
/// - timeout The request’s timeout interval in seconds; defaults to 180 seconds.
40+
public init(timeout: TimeInterval = 180.0) {
4241
self.timeout = timeout
4342
}
4443
}

FirebaseVertexAI/Sources/GenerativeAIService.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ struct GenerativeAIService {
191191
let encoder = JSONEncoder()
192192
encoder.keyEncodingStrategy = .convertToSnakeCase
193193
urlRequest.httpBody = try encoder.encode(request)
194-
195-
if let timeoutInterval = request.options.timeout {
196-
urlRequest.timeoutInterval = timeoutInterval
197-
}
194+
urlRequest.timeoutInterval = request.options.timeout
198195

199196
return urlRequest
200197
}

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ final class GenerativeModelTests: XCTestCase {
12671267
private func httpRequestHandler(forResource name: String,
12681268
withExtension ext: String,
12691269
statusCode: Int = 200,
1270-
timeout: TimeInterval = URLRequest.defaultTimeoutInterval(),
1270+
timeout: TimeInterval = RequestOptions().timeout,
12711271
appCheckToken: String? = nil,
12721272
authToken: String? = nil) throws -> ((URLRequest) throws -> (
12731273
URLResponse,
@@ -1316,14 +1316,6 @@ private extension String {
13161316
}
13171317
}
13181318

1319-
private extension URLRequest {
1320-
/// Returns the default `timeoutInterval` for a `URLRequest`.
1321-
static func defaultTimeoutInterval() -> TimeInterval {
1322-
let placeholderURL = URL(string: "https://example.com")!
1323-
return URLRequest(url: placeholderURL).timeoutInterval
1324-
}
1325-
}
1326-
13271319
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
13281320
class AppCheckInteropFake: NSObject, AppCheckInterop {
13291321
/// The placeholder token value returned when an error occurs

0 commit comments

Comments
 (0)