Skip to content

Commit

Permalink
Add enum Chat.Role
Browse files Browse the repository at this point in the history
So that `Chat` has a safer initializer `init(role: Role, content: String)`  than `init(role: String, content: String)`
  • Loading branch information
tomdai committed Mar 10, 2023
1 parent d0493cf commit 35d97bf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/OpenAI/OpenAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,20 @@ public extension OpenAI {
public let role: String
public let content: String

public enum Role: String {
case system
case assistant
case user
}

public init(role: String, content: String) {
self.role = role
self.content = content
}

public init(role: Role, content: String) {
self.init(role: role.rawValue, content: content)
}
}

struct ChatQuery: Codable {
Expand Down

0 comments on commit 35d97bf

Please sign in to comment.