GenerativeAIRequest.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 11.0, macCatalyst 15.0, tvOS 15.0, *)
  16. protocol GenerativeAIRequest: 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 11.0, macCatalyst 15.0, tvOS 15.0, *)
  23. public struct RequestOptions {
  24. /// The request’s timeout interval in seconds; if not specified uses the default value for a
  25. /// `URLRequest`.
  26. let timeout: TimeInterval?
  27. /// The API version to use in requests to the backend.
  28. let apiVersion = "v2beta"
  29. /// Initializes a request options object.
  30. ///
  31. /// - Parameters:
  32. /// - timeout The request’s timeout interval in seconds; if not specified uses the default value
  33. /// for a `URLRequest`.
  34. public init(timeout: TimeInterval? = nil) {
  35. self.timeout = timeout
  36. }
  37. }