Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vertex AI] Add support for compiling on tvOS #13090

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/vertexai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
spm-unit:
strategy:
matrix:
target: [iOS, macOS, catalyst]
target: [iOS, macOS, catalyst, tvOS]
os: [macos-14]
include:
- os: macos-14
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation

/// An object that represents a back-and-forth chat with a model, capturing the history and saving
/// the context in memory between each message sent.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public class Chat {
private let model: GenerativeModel

Expand Down
1 change: 0 additions & 1 deletion FirebaseVertexAI/Sources/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Foundation
#endif

/// Constants associated with the Vertex AI for Firebase SDK.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
enum Constants {
/// The Vertex AI backend endpoint URL.
static let baseURL = "https://firebaseml.googleapis.com"
Expand Down
10 changes: 5 additions & 5 deletions FirebaseVertexAI/Sources/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
struct CountTokensRequest {
let model: String
let contents: [ModelContent]
let options: RequestOptions
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CountTokensRequest: GenerativeAIRequest {
typealias Response = CountTokensResponse

Expand All @@ -31,7 +31,7 @@ extension CountTokensRequest: GenerativeAIRequest {
}

/// The model's response to a count tokens request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct CountTokensResponse {
/// The total number of tokens in the input given to the model as a prompt.
public let totalTokens: Int
Expand All @@ -45,14 +45,14 @@ public struct CountTokensResponse {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CountTokensRequest: Encodable {
enum CodingKeys: CodingKey {
case contents
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CountTokensResponse: Decodable {
enum CodingKeys: CodingKey {
case totalTokens
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerateContentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

/// Errors that occur when generating content from a model.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public enum GenerateContentError: Error {
/// An error occurred when constructing the prompt. Examine the related error for details.
case promptImageContentError(underlying: ImageConversionError)
Expand Down
6 changes: 3 additions & 3 deletions FirebaseVertexAI/Sources/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
struct GenerateContentRequest {
/// Model name.
let model: String
Expand All @@ -28,7 +28,7 @@ struct GenerateContentRequest {
let options: RequestOptions
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension GenerateContentRequest: Encodable {
enum CodingKeys: String, CodingKey {
case contents
Expand All @@ -40,7 +40,7 @@ extension GenerateContentRequest: Encodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension GenerateContentRequest: GenerativeAIRequest {
typealias Response = GenerateContentResponse

Expand Down
28 changes: 14 additions & 14 deletions FirebaseVertexAI/Sources/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

/// The model's response to a generate content request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct GenerateContentResponse {
/// Token usage metadata for processing the generate content request.
public struct UsageMetadata {
Expand Down Expand Up @@ -84,7 +84,7 @@ public struct GenerateContentResponse {

/// A struct representing a possible reply to a content generation prompt. Each content generation
/// prompt may produce multiple candidate responses.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct CandidateResponse {
/// The response's content.
public let content: ModelContent
Expand All @@ -110,14 +110,14 @@ public struct CandidateResponse {
}

/// A collection of source attributions for a piece of content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct CitationMetadata {
/// A list of individual cited sources and the parts of the content to which they apply.
public let citationSources: [Citation]
}

/// A struct describing a source attribution.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct Citation {
/// The inclusive beginning of a sequence in a model response that derives from a cited source.
public let startIndex: Int
Expand All @@ -133,7 +133,7 @@ public struct Citation {
}

/// A value enumerating possible reasons for a model to terminate a content generation request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public enum FinishReason: String {
case unknown = "FINISH_REASON_UNKNOWN"

Expand All @@ -158,7 +158,7 @@ public enum FinishReason: String {
}

/// A metadata struct containing any feedback the model had on the prompt it was provided.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct PromptFeedback {
/// A type describing possible reasons to block a prompt.
public enum BlockReason: String {
Expand Down Expand Up @@ -190,7 +190,7 @@ public struct PromptFeedback {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension GenerateContentResponse: Decodable {
enum CodingKeys: CodingKey {
case candidates
Expand Down Expand Up @@ -224,7 +224,7 @@ extension GenerateContentResponse: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension GenerateContentResponse.UsageMetadata: Decodable {
enum CodingKeys: CodingKey {
case promptTokenCount
Expand All @@ -241,7 +241,7 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CandidateResponse: Decodable {
enum CodingKeys: CodingKey {
case content
Expand Down Expand Up @@ -290,14 +290,14 @@ extension CandidateResponse: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CitationMetadata: Decodable {
enum CodingKeys: String, CodingKey {
case citationSources = "citations"
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension Citation: Decodable {
enum CodingKeys: CodingKey {
case startIndex
Expand All @@ -315,7 +315,7 @@ extension Citation: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension FinishReason: Decodable {
public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer().decode(String.self)
Expand All @@ -330,7 +330,7 @@ extension FinishReason: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension PromptFeedback.BlockReason: Decodable {
public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer().decode(String.self)
Expand All @@ -345,7 +345,7 @@ extension PromptFeedback.BlockReason: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension PromptFeedback: Decodable {
enum CodingKeys: CodingKey {
case blockReason
Expand Down
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation

/// A struct defining model parameters to be used when sending generative AI
/// requests to the backend model.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct GenerationConfig {
/// A parameter controlling the degree of randomness in token selection. A
/// temperature of zero is deterministic, always choosing the
Expand Down Expand Up @@ -95,5 +95,5 @@ public struct GenerationConfig {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension GenerationConfig: Encodable {}
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
protocol GenerativeAIRequest: Encodable {
associatedtype Response: Decodable

Expand All @@ -24,7 +24,7 @@ protocol GenerativeAIRequest: Encodable {
}

/// Configuration parameters for sending requests to the backend.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct RequestOptions {
/// The request’s timeout interval in seconds; if not specified uses the default value for a
/// `URLRequest`.
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import FirebaseAuthInterop
import FirebaseCore
import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
struct GenerativeAIService {
/// The language of the SDK in the format `gl-<language>/<version>`.
static let languageTag = "gl-swift/5"
Expand Down
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

/// A type that represents a remote multimodal model (like Gemini), with the ability to generate
/// content based on various input types.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public final class GenerativeModel {
// The prefix for a model resource in the Gemini API.
private static let modelResourcePrefix = "models/"
Expand Down Expand Up @@ -318,7 +318,7 @@ public final class GenerativeModel {
}

/// An error thrown in `GenerativeModel.countTokens(_:)`.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public enum CountTokensError: Error {
case internalError(underlying: Error)
}
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation
import OSLog

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
struct Logging {
/// Subsystem that should be used for all Loggers.
static let subsystem = "com.google.firebase.vertex-ai"
Expand Down
6 changes: 3 additions & 3 deletions FirebaseVertexAI/Sources/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
/// A type describing data in media formats interpretable by an AI model. Each generative AI
/// request or response contains an `Array` of ``ModelContent``s, and each ``ModelContent`` value
/// may comprise multiple heterogeneous ``ModelContent/Part``s.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
public struct ModelContent: Equatable {
/// A discrete piece of data in a media format interpretable by an AI model. Within a single value
/// of ``Part``, different data types may not mix.
Expand Down Expand Up @@ -116,10 +116,10 @@ public struct ModelContent: Equatable {

// MARK: Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension ModelContent: Codable {}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension ModelContent.Part: Codable {
enum CodingKeys: String, CodingKey {
case text
Expand Down
8 changes: 4 additions & 4 deletions FirebaseVertexAI/Sources/PartsRepresentable+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum ImageConversionError: Error {

#if canImport(UIKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension UIImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let data = jpegData(compressionQuality: imageCompressionQuality) else {
Expand All @@ -50,7 +50,7 @@ public enum ImageConversionError: Error {

#elseif canImport(AppKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension NSImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else {
Expand All @@ -67,7 +67,7 @@ public enum ImageConversionError: Error {
#endif

/// Enables `CGImages` to be representable as model content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CGImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
let output = NSMutableData()
Expand All @@ -88,7 +88,7 @@ extension CGImage: ThrowingPartsRepresentable {
}

/// Enables `CIImages` to be representable as model content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
extension CIImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
let context = CIContext()
Expand Down
Loading
Loading