GenerativeAIRequest.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  16. protocol GenerativeAIRequest: Sendable, Encodable {
  17. associatedtype Response: Decodable
  18. var url: URL { get }
  19. var options: RequestOptions { get }
  20. }
  21. /// Configuration parameters for sending requests to the backend.
  22. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  23. public struct RequestOptions: Sendable {
  24. /// The request’s timeout interval in seconds; if not specified uses the default value for a
  25. /// `URLRequest`.
  26. let timeout: TimeInterval
  27. /// Initializes a request options object.
  28. ///
  29. /// - Parameters:
  30. /// - timeout: The request’s timeout interval in seconds; defaults to 180 seconds.
  31. public init(timeout: TimeInterval = 180.0) {
  32. self.timeout = timeout
  33. }
  34. }
  35. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  36. extension RequestOptions: Equatable {}