Skip to content

Commit 4d71da8

Browse files
committed
[Vertex AI] Rename Part enum case data to inlineData (#13700)
1 parent 5fb5a5b commit 4d71da8

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

FirebaseVertexAI/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
- [changed] **Breaking Change**: The `BlockThreshold` enum in `SafetySetting`
66
has been renamed to `HarmBlockThreshold`. (#13696)
77
- [changed] **Breaking Change**: The `unspecified` case has been removed from
8-
the `FinishReason`, `PromptFeedback` and `HarmProbability` enums; this
9-
scenario is now handled by the existing `unknown` case. (#13699)
8+
the `FinishReason`, `BlockReason` and `HarmProbability` enums; this scenario
9+
is now handled by the existing `unknown` case. (#13699)
10+
- [changed] **Breaking Change**: The `data` case in the `Part` enum has been
11+
renamed to `inlineData`; no functionality changes. (#13700)
1012

1113
# 11.3.0
1214
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)

FirebaseVertexAI/Sample/FunctionCallingSample/ViewModels/FunctionCallingViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class FunctionCallingViewModel: ObservableObject {
156156
case let .functionCall(functionCall):
157157
messages.insert(functionCall.chatMessage(), at: messages.count - 1)
158158
functionCalls.append(functionCall)
159-
case .data, .fileData, .functionResponse:
159+
case .inlineData, .fileData, .functionResponse:
160160
fatalError("Unsupported response content.")
161161
}
162162
}

FirebaseVertexAI/Sources/Chat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class Chat {
155155
case let .text(str):
156156
combinedText += str
157157

158-
case .data, .fileData, .functionCall, .functionResponse:
158+
case .inlineData, .fileData, .functionCall, .functionResponse:
159159
// Don't combine it, just add to the content. If there's any text pending, add that as
160160
// a part.
161161
if !combinedText.isEmpty {

FirebaseVertexAI/Sources/ModelContent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct ModelContent: Equatable, Sendable {
2626
case text(String)
2727

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

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

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

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

6464
/// Returns the text contents of this ``Part``, if it contains text.
@@ -144,7 +144,7 @@ extension ModelContent.Part: Codable {
144144
switch self {
145145
case let .text(a0):
146146
try container.encode(a0, forKey: .text)
147-
case let .data(mimetype, bytes):
147+
case let .inlineData(mimetype, bytes):
148148
var inlineDataContainer = container.nestedContainer(
149149
keyedBy: InlineDataKeys.self,
150150
forKey: .inlineData
@@ -176,7 +176,7 @@ extension ModelContent.Part: Codable {
176176
)
177177
let mimetype = try dataContainer.decode(String.self, forKey: .mimeType)
178178
let bytes = try dataContainer.decode(Data.self, forKey: .bytes)
179-
self = .data(mimetype: mimetype, bytes)
179+
self = .inlineData(mimetype: mimetype, bytes)
180180
} else if values.contains(.functionCall) {
181181
self = try .functionCall(values.decode(FunctionCall.self, forKey: .functionCall))
182182
} else if values.contains(.functionResponse) {

FirebaseVertexAI/Sources/PartsRepresentable+Image.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public enum ImageConversionError: Error {
5757
guard let data = jpegData(compressionQuality: imageCompressionQuality) else {
5858
throw ImageConversionError.couldNotConvertToJPEG(.uiImage(self))
5959
}
60-
return [ModelContent.Part.data(mimetype: "image/jpeg", data)]
60+
return [ModelContent.Part.inlineData(mimetype: "image/jpeg", data)]
6161
}
6262
}
6363

@@ -74,7 +74,7 @@ public enum ImageConversionError: Error {
7474
else {
7575
throw ImageConversionError.couldNotConvertToJPEG(.nsImage(self))
7676
}
77-
return [ModelContent.Part.data(mimetype: "image/jpeg", data)]
77+
return [ModelContent.Part.inlineData(mimetype: "image/jpeg", data)]
7878
}
7979
}
8080
#endif
@@ -95,7 +95,7 @@ public enum ImageConversionError: Error {
9595
kCGImageDestinationLossyCompressionQuality: imageCompressionQuality,
9696
] as CFDictionary)
9797
if CGImageDestinationFinalize(imageDestination) {
98-
return [.data(mimetype: "image/jpeg", output as Data)]
98+
return [.inlineData(mimetype: "image/jpeg", output as Data)]
9999
}
100100
throw ImageConversionError.couldNotConvertToJPEG(.cgImage(self))
101101
}
@@ -116,7 +116,7 @@ public enum ImageConversionError: Error {
116116
context.jpegRepresentation(of: self, colorSpace: $0, options: [:])
117117
}
118118
if let jpegData = jpegData {
119-
return [.data(mimetype: "image/jpeg", jpegData)]
119+
return [.inlineData(mimetype: "image/jpeg", jpegData)]
120120
}
121121
throw ImageConversionError.couldNotConvertToJPEG(.ciImage(self))
122122
}

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ final class GenerativeModelTests: XCTestCase {
11881188
withExtension: "json"
11891189
)
11901190

1191-
let response = try await model.countTokens(ModelContent.Part.data(
1191+
let response = try await model.countTokens(ModelContent.Part.inlineData(
11921192
mimetype: "image/jpeg",
11931193
Data()
11941194
))

FirebaseVertexAI/Tests/Unit/VertexAIAPITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ final class VertexAIAPITests: XCTestCase {
123123
// convert value of type 'String' to expected element type
124124
// 'Array<ModelContent.Part>.ArrayLiteralElement'. Not sure if there's a way we can get it to
125125
// work.
126-
let _ = try ModelContent(parts: [str, ModelContent.Part.data(
126+
let _ = try ModelContent(parts: [str, ModelContent.Part.inlineData(
127127
mimetype: "foo",
128128
Data()
129129
)] as [any ThrowingPartsRepresentable])

0 commit comments

Comments
 (0)