Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
- [changed] **Breaking Change**: The `BlockThreshold` enum in `SafetySetting`
has been renamed to `HarmBlockThreshold`. (#13696)
- [changed] **Breaking Change**: The `unspecified` case has been removed from
the `FinishReason`, `PromptFeedback` and `HarmProbability` enums; this
scenario is now handled by the existing `unknown` case. (#13699)
the `FinishReason`, `BlockReason` and `HarmProbability` enums; this scenario
is now handled by the existing `unknown` case. (#13699)
- [changed] **Breaking Change**: The `data` case in the `Part` enum has been
renamed to `inlineData`; no functionality changes. (#13700)

# 11.3.0
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class FunctionCallingViewModel: ObservableObject {
case let .functionCall(functionCall):
messages.insert(functionCall.chatMessage(), at: messages.count - 1)
functionCalls.append(functionCall)
case .data, .fileData, .functionResponse:
case .inlineData, .fileData, .functionResponse:
fatalError("Unsupported response content.")
}
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public actor Chat {
case let .text(str):
combinedText += str

case .data, .fileData, .functionCall, .functionResponse:
case .inlineData, .fileData, .functionCall, .functionResponse:
// Don't combine it, just add to the content. If there's any text pending, add that as
// a part.
if !combinedText.isEmpty {
Expand Down
10 changes: 5 additions & 5 deletions FirebaseVertexAI/Sources/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ModelContent: Equatable, Sendable {
case text(String)

/// Data with a specified media type. Not all media types may be supported by the AI model.
case data(mimetype: String, Data)
case inlineData(mimetype: String, Data)

/// File data stored in Cloud Storage for Firebase, referenced by URI.
///
Expand All @@ -53,12 +53,12 @@ public struct ModelContent: Equatable, Sendable {

/// Convenience function for populating a Part with JPEG data.
public static func jpeg(_ data: Data) -> Self {
return .data(mimetype: "image/jpeg", data)
return .inlineData(mimetype: "image/jpeg", data)
}

/// Convenience function for populating a Part with PNG data.
public static func png(_ data: Data) -> Self {
return .data(mimetype: "image/png", data)
return .inlineData(mimetype: "image/png", data)
}

/// Returns the text contents of this ``Part``, if it contains text.
Expand Down Expand Up @@ -144,7 +144,7 @@ extension ModelContent.Part: Codable {
switch self {
case let .text(a0):
try container.encode(a0, forKey: .text)
case let .data(mimetype, bytes):
case let .inlineData(mimetype, bytes):
var inlineDataContainer = container.nestedContainer(
keyedBy: InlineDataKeys.self,
forKey: .inlineData
Expand Down Expand Up @@ -176,7 +176,7 @@ extension ModelContent.Part: Codable {
)
let mimetype = try dataContainer.decode(String.self, forKey: .mimeType)
let bytes = try dataContainer.decode(Data.self, forKey: .bytes)
self = .data(mimetype: mimetype, bytes)
self = .inlineData(mimetype: mimetype, bytes)
} else if values.contains(.functionCall) {
self = try .functionCall(values.decode(FunctionCall.self, forKey: .functionCall))
} else if values.contains(.functionResponse) {
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 @@ -57,7 +57,7 @@ public enum ImageConversionError: Error {
guard let data = jpegData(compressionQuality: imageCompressionQuality) else {
throw ImageConversionError.couldNotConvertToJPEG(.uiImage(self))
}
return [ModelContent.Part.data(mimetype: "image/jpeg", data)]
return [ModelContent.Part.inlineData(mimetype: "image/jpeg", data)]
}
}

Expand All @@ -74,7 +74,7 @@ public enum ImageConversionError: Error {
else {
throw ImageConversionError.couldNotConvertToJPEG(.nsImage(self))
}
return [ModelContent.Part.data(mimetype: "image/jpeg", data)]
return [ModelContent.Part.inlineData(mimetype: "image/jpeg", data)]
}
}
#endif
Expand All @@ -95,7 +95,7 @@ public enum ImageConversionError: Error {
kCGImageDestinationLossyCompressionQuality: imageCompressionQuality,
] as CFDictionary)
if CGImageDestinationFinalize(imageDestination) {
return [.data(mimetype: "image/jpeg", output as Data)]
return [.inlineData(mimetype: "image/jpeg", output as Data)]
}
throw ImageConversionError.couldNotConvertToJPEG(.cgImage(self))
}
Expand All @@ -116,7 +116,7 @@ public enum ImageConversionError: Error {
context.jpegRepresentation(of: self, colorSpace: $0, options: [:])
}
if let jpegData = jpegData {
return [.data(mimetype: "image/jpeg", jpegData)]
return [.inlineData(mimetype: "image/jpeg", jpegData)]
}
throw ImageConversionError.couldNotConvertToJPEG(.ciImage(self))
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ final class GenerativeModelTests: XCTestCase {
withExtension: "json"
)

let response = try await model.countTokens(ModelContent.Part.data(
let response = try await model.countTokens(ModelContent.Part.inlineData(
mimetype: "image/jpeg",
Data()
))
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ final class VertexAIAPITests: XCTestCase {
// convert value of type 'String' to expected element type
// 'Array<ModelContent.Part>.ArrayLiteralElement'. Not sure if there's a way we can get it to
// work.
let _ = try ModelContent(parts: [str, ModelContent.Part.data(
let _ = try ModelContent(parts: [str, ModelContent.Part.inlineData(
mimetype: "foo",
Data()
)] as [any ThrowingPartsRepresentable])
Expand Down
Loading