Skip to content

Commit

Permalink
Update ModelContent.Part enum decoding strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Mar 5, 2024
1 parent ac4aea1 commit 67932d7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Sources/GoogleAI/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public struct ModelContent: Codable, Equatable {

public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
if let textVal = try? values.decode(String.self, forKey: .text) {
self = .text(textVal)
} else if let dataContainer = try? values.nestedContainer(
keyedBy: InlineDataKeys.self,
forKey: .inlineData
) {
// Get the data here.
if values.contains(.text) {
self = try .text(values.decode(String.self, forKey: .text))
} else if values.contains(.inlineData) {
let dataContainer = try values.nestedContainer(
keyedBy: InlineDataKeys.self,
forKey: .inlineData
)
let mimetype = try dataContainer.decode(String.self, forKey: .mimeType)
let bytes = try dataContainer.decode(Data.self, forKey: .bytes)
self = .data(mimetype: mimetype, bytes)
Expand Down

0 comments on commit 67932d7

Please sign in to comment.