ModalityTokenCount.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2025 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. /// Represents token counting info for a single modality.
  16. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  17. public struct ModalityTokenCount: Sendable {
  18. /// The modality associated with this token count.
  19. public let modality: ContentModality
  20. /// The number of tokens counted.
  21. public let tokenCount: Int
  22. }
  23. /// Content part modality.
  24. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  25. public struct ContentModality: DecodableProtoEnum, Hashable, Sendable {
  26. enum Kind: String {
  27. case text = "TEXT"
  28. case image = "IMAGE"
  29. case video = "VIDEO"
  30. case audio = "AUDIO"
  31. case document = "DOCUMENT"
  32. }
  33. /// Plain text.
  34. public static let text = ContentModality(kind: .text)
  35. /// Image.
  36. public static let image = ContentModality(kind: .image)
  37. /// Video.
  38. public static let video = ContentModality(kind: .video)
  39. /// Audio.
  40. public static let audio = ContentModality(kind: .audio)
  41. /// Document, e.g. PDF.
  42. public static let document = ContentModality(kind: .document)
  43. /// Returns the raw string representation of the `ContentModality` value.
  44. public let rawValue: String
  45. static let unrecognizedValueMessageCode =
  46. VertexLog.MessageCode.generateContentResponseUnrecognizedContentModality
  47. }
  48. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  49. extension ModalityTokenCount: Decodable {}