diff --git a/Sources/GoogleAI/ModelContent.swift b/Sources/GoogleAI/ModelContent.swift index edfead4..172fc80 100644 --- a/Sources/GoogleAI/ModelContent.swift +++ b/Sources/GoogleAI/ModelContent.swift @@ -114,7 +114,7 @@ public struct ModelContent: Codable, Equatable { /// ``Part``. See ``ThrowingPartsRepresentable`` for types that can be interpreted as `Part`s. public init(role: String? = "user", parts: some PartsRepresentable) { self.role = role - self.parts = parts.toPartsValue() + self.parts = parts.partsValue } /// Creates a new value from a list of ``Part``s. @@ -135,7 +135,7 @@ public struct ModelContent: Codable, Equatable { /// ``ThrowingPartsRepresentable`` /// for types that can be interpreted as `Part`s. public init(role: String? = "user", _ parts: [PartsRepresentable]) { - let content = parts.flatMap { $0.toPartsValue() } + let content = parts.flatMap { $0.partsValue } self.init(role: role, parts: content) } } diff --git a/Sources/GoogleAI/PartsRepresentable.swift b/Sources/GoogleAI/PartsRepresentable.swift index 5d281ef..05ba0d9 100644 --- a/Sources/GoogleAI/PartsRepresentable.swift +++ b/Sources/GoogleAI/PartsRepresentable.swift @@ -26,13 +26,13 @@ public protocol ThrowingPartsRepresentable { /// ``ThrowingPartsRepresentable`` @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) public protocol PartsRepresentable: ThrowingPartsRepresentable { - func toPartsValue() -> [ModelContent.Part] + var partsValue: [ModelContent.Part] { get } } @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) public extension PartsRepresentable { func tryPartsValue() throws -> [ModelContent.Part] { - return toPartsValue() + return partsValue } } @@ -60,7 +60,7 @@ extension [ThrowingPartsRepresentable]: ThrowingPartsRepresentable { /// Enables a `String` to be passed in as ``ThrowingPartsRepresentable``. @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *) extension String: PartsRepresentable { - public func toPartsValue() -> [ModelContent.Part] { + public var partsValue: [ModelContent.Part] { return [.text(self)] } }