From 35d97bf13b60a60d875602e1bdd894fc63fc76dc Mon Sep 17 00:00:00 2001 From: Tom <5054148+tomdai@users.noreply.github.com> Date: Thu, 9 Mar 2023 19:48:40 -0800 Subject: [PATCH] =?UTF-8?q?Add=20enum=20`Chat.Role`=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that `Chat` has a safer initializer `init(role: Role, content: String)` than `init(role: String, content: String)` --- Sources/OpenAI/OpenAI.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/OpenAI/OpenAI.swift b/Sources/OpenAI/OpenAI.swift index 12ef98b6..097413a4 100644 --- a/Sources/OpenAI/OpenAI.swift +++ b/Sources/OpenAI/OpenAI.swift @@ -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 {