Skip to content

Commit 097d34d

Browse files
committed
add customstringconvertible
1 parent 6a6daeb commit 097d34d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/Converse/Role.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@preconcurrency import AWSBedrockRuntime
1717
import Foundation
1818

19-
public struct Role: Codable, Sendable, Equatable {
19+
public struct Role: Codable, Sendable, Equatable, CustomStringConvertible {
2020
private enum RoleType: Codable, Sendable, Equatable {
2121
case user
2222
case assistant
@@ -71,9 +71,19 @@ public struct Role: Codable, Sendable, Equatable {
7171
}
7272
}
7373
/// Returns the type of the role as a string.
74+
public var description: String {
75+
switch self.type {
76+
case .user: return "user"
77+
case .assistant: return "assistant"
78+
}
79+
}
80+
81+
// Equatable
7482
public static func == (lhs: Role, rhs: Role) -> Bool {
7583
lhs.type == rhs.type
7684
}
85+
86+
// convenience static properties for common roles
7787
private init(_ type: RoleType) {
7888
self.type = type
7989
}

0 commit comments

Comments
 (0)