Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "OpenAISwift",
platforms: [.iOS(.v15), .macOS(.v10_15)],
platforms: [.iOS(.v13), .macOS(.v10_15)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
18 changes: 18 additions & 0 deletions Sources/OpenAISwift/Models/ChatMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ public struct ChatMessage: Codable, Identifiable {
self.role = role
self.content = content
}

// MARK: Codable

private enum CodingKeys: String, CodingKey {
case role, content
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
role = try container.decode(ChatRole.self, forKey: .role)
content = try container.decode(String.self, forKey: .content)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(self.role, forKey: .role)
try container.encodeIfPresent(self.content, forKey: .content)
}
}

/// A structure that represents a chat conversation.
Expand Down
5 changes: 5 additions & 0 deletions Sources/OpenAISwift/OpenAISwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class OpenAISwift {
}
}

@available(*, deprecated, message: "Use init(config:) instead")
public convenience init(authToken: String) {
self.init(config: .makeDefaultOpenAI(apiKey: authToken))
}

public init(config: Config) {
self.config = config
}
Expand Down