GenerativeAIRequest.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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, watchOS 8.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, watchOS 8.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. ///
  29. /// TODO(andrewheard): Update to "v1beta" after the Vertex AI in Firebase API launch.
  30. let apiVersion = "v2beta"
  31. /// Initializes a request options object.
  32. ///
  33. /// - Parameters:
  34. /// - timeout The request’s timeout interval in seconds; defaults to 180 seconds.
  35. public init(timeout: TimeInterval = 180.0) {
  36. self.timeout = timeout
  37. }
  38. }