Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. (#13722)

# 11.3.0
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)
Expand Down
7 changes: 3 additions & 4 deletions FirebaseVertexAI/Sources/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ 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"

/// 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
}
}
5 changes: 1 addition & 4 deletions FirebaseVertexAI/Sources/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 1 addition & 9 deletions FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading