Skip to content

Commit

Permalink
use partsValue
Browse files Browse the repository at this point in the history
  • Loading branch information
morganchen12 committed Feb 20, 2024
1 parent 0adb052 commit d962763
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Sources/GoogleAI/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}
6 changes: 3 additions & 3 deletions Sources/GoogleAI/PartsRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)]
}
}

0 comments on commit d962763

Please sign in to comment.