Skip to content

Commit bda4433

Browse files
feat: conforms to Sendable (#14)
1 parent d5fd9f8 commit bda4433

File tree

13 files changed

+47
-46
lines changed

13 files changed

+47
-46
lines changed

.github/workflows/code-quality.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ on:
1010

1111
jobs:
1212
test-ios:
13-
runs-on: macos-14
13+
runs-on: macos-15
1414

1515
steps:
1616
- uses: actions/checkout@v4
1717

1818
- name: Build and test
19-
run: xcodebuild test -scheme LLMChatOpenAI -destination 'platform=iOS Simulator,name=iPhone 15 Pro'
19+
run: xcodebuild test -scheme LLMChatOpenAI -destination 'platform=iOS Simulator,name=iPhone 16 Pro'
2020

2121
test-macos:
22-
runs-on: macos-14
22+
runs-on: macos-15
2323

2424
steps:
2525
- uses: actions/checkout@v4

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515

1616
jobs:
1717
deploy:
18-
runs-on: macos-14
18+
runs-on: macos-15
1919

2020
environment:
2121
name: github-pages

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
targets: ["LLMChatOpenAI"]),
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/kevinhermawan/swift-json-schema.git", exact: "1.0.3"),
15+
.package(url: "https://github.com/kevinhermawan/swift-json-schema.git", .upToNextMajor(from: "2.0.1")),
1616
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.4.3"))
1717
],
1818
targets: [

Playground/Playground.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
287287
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
288288
SWIFT_EMIT_LOC_STRINGS = YES;
289-
SWIFT_VERSION = 5.0;
289+
SWIFT_VERSION = 6.0;
290290
TARGETED_DEVICE_FAMILY = "1,2";
291291
};
292292
name = Debug;
@@ -320,7 +320,7 @@
320320
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
321321
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
322322
SWIFT_EMIT_LOC_STRINGS = YES;
323-
SWIFT_VERSION = 5.0;
323+
SWIFT_VERSION = 6.0;
324324
TARGETED_DEVICE_FAMILY = "1,2";
325325
};
326326
name = Release;

Playground/Playground.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Playground/Playground/ViewModels/AppViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ enum ServiceProvider: String, CaseIterable {
1515
case groq = "Groq"
1616
}
1717

18+
@MainActor
1819
@Observable
1920
final class AppViewModel {
20-
var stream: Bool = false
21+
var stream: Bool = true
2122
var openaiAPIKey: String = ""
2223
var openRouterAPIKey: String = ""
2324
var groqAPIKey: String = ""

Sources/LLMChatOpenAI/ChatCompletion.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// A struct that represents a chat completion response.
11-
public struct ChatCompletion: Decodable {
11+
public struct ChatCompletion: Decodable, Sendable {
1212
/// A unique identifier for the chat completion.
1313
public let id: String
1414

@@ -35,7 +35,7 @@ public struct ChatCompletion: Decodable {
3535
/// The usage statistics for the completion request.
3636
public let usage: Usage?
3737

38-
public struct Choice: Decodable {
38+
public struct Choice: Decodable, Sendable {
3939
/// The index of the choice in the list of choices.
4040
public let index: Int
4141

@@ -49,7 +49,7 @@ public struct ChatCompletion: Decodable {
4949
/// Log probability information for the choice.
5050
public let logprobs: Logprobs?
5151

52-
public struct Message: Decodable {
52+
public struct Message: Decodable, Sendable {
5353
/// The role of the author of this message.
5454
public let role: String
5555

@@ -62,7 +62,7 @@ public struct ChatCompletion: Decodable {
6262
/// An array of ``ToolCall`` generated by the model.
6363
public let toolCalls: [ToolCall]?
6464

65-
public struct ToolCall: Codable {
65+
public struct ToolCall: Decodable, Sendable {
6666
/// The ID of the tool call.
6767
public let id: String
6868

@@ -72,7 +72,7 @@ public struct ChatCompletion: Decodable {
7272
/// The function that the model called.
7373
public let function: Function
7474

75-
public struct Function: Codable {
75+
public struct Function: Codable, Sendable {
7676
/// The name of the function to call.
7777
public let name: String
7878

@@ -91,7 +91,7 @@ public struct ChatCompletion: Decodable {
9191
}
9292

9393
/// The reason the model stopped generating tokens.
94-
public enum FinishReason: String, Decodable {
94+
public enum FinishReason: String, Decodable, Sendable {
9595
/// The model reached a natural stop point or a provided stop sequence.
9696
case stop
9797

@@ -105,14 +105,14 @@ public struct ChatCompletion: Decodable {
105105
case contentFilter = "content_filter"
106106
}
107107

108-
public struct Logprobs: Decodable {
108+
public struct Logprobs: Decodable, Sendable {
109109
/// An array of message content tokens with log probability information.
110110
public let content: [TokenInfo]?
111111

112112
/// An array of message refusal tokens with log probability information.
113113
public let refusal: [TokenInfo]?
114114

115-
public struct TokenInfo: Decodable {
115+
public struct TokenInfo: Decodable, Sendable {
116116
/// The token.
117117
public let token: String
118118

@@ -144,7 +144,7 @@ public struct ChatCompletion: Decodable {
144144
}
145145
}
146146

147-
public struct Usage: Decodable {
147+
public struct Usage: Decodable, Sendable {
148148
/// Number of tokens in the generated completion.
149149
public let completionTokens: Int
150150

@@ -160,7 +160,7 @@ public struct ChatCompletion: Decodable {
160160
/// Breakdown of tokens used in the prompt.
161161
public let promptTokensDetails: PromptTokensDetails?
162162

163-
public struct CompletionTokensDetails: Decodable {
163+
public struct CompletionTokensDetails: Decodable, Sendable {
164164
/// Tokens generated by the model for reasoning.
165165
public let reasoningTokens: Int
166166

@@ -169,7 +169,7 @@ public struct ChatCompletion: Decodable {
169169
}
170170
}
171171

172-
public struct PromptTokensDetails: Decodable {
172+
public struct PromptTokensDetails: Decodable, Sendable {
173173
/// Cached tokens present in the prompt.
174174
public let cachedTokens: Int
175175

Sources/LLMChatOpenAI/ChatCompletionChunk.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// A struct that represents a streamed chunk of a chat completion response.
11-
public struct ChatCompletionChunk: Decodable {
11+
public struct ChatCompletionChunk: Decodable, Sendable {
1212
/// A unique identifier for the chat completion. Each chunk has the same identifier.
1313
public let id: String
1414

@@ -35,7 +35,7 @@ public struct ChatCompletionChunk: Decodable {
3535
/// Usage statistics for the completion request.
3636
public let usage: Usage?
3737

38-
public struct Choice: Decodable {
38+
public struct Choice: Decodable, Sendable {
3939
/// The index of the choice in the list of choices.
4040
public let index: Int
4141

@@ -49,7 +49,7 @@ public struct ChatCompletionChunk: Decodable {
4949
/// Log probability information for the choice.
5050
public let logprobs: Logprobs?
5151

52-
public struct Delta: Decodable {
52+
public struct Delta: Decodable, Sendable {
5353
/// The role of the author of this message.
5454
public let role: String?
5555

@@ -62,7 +62,7 @@ public struct ChatCompletionChunk: Decodable {
6262
/// An array of ``ToolCall`` generated by the model.
6363
public var toolCalls: [ToolCall]?
6464

65-
public struct ToolCall: Decodable {
65+
public struct ToolCall: Decodable, Sendable {
6666
/// The ID of the tool call.
6767
public let id: String?
6868

@@ -72,7 +72,7 @@ public struct ChatCompletionChunk: Decodable {
7272
/// The function that the model called.
7373
public var function: Function?
7474

75-
public struct Function: Decodable {
75+
public struct Function: Decodable, Sendable {
7676
/// The name of the function to call.
7777
public var name: String?
7878

@@ -90,7 +90,7 @@ public struct ChatCompletionChunk: Decodable {
9090
}
9191

9292
/// The reason the model stopped generating tokens.
93-
public enum FinishReason: String, Decodable {
93+
public enum FinishReason: String, Decodable, Sendable {
9494
/// The model reached a natural stop point or a provided stop sequence.
9595
case stop
9696

@@ -104,14 +104,14 @@ public struct ChatCompletionChunk: Decodable {
104104
case contentFilter = "content_filter"
105105
}
106106

107-
public struct Logprobs: Decodable {
107+
public struct Logprobs: Decodable, Sendable {
108108
/// An array of message content tokens with log probability information.
109109
public let content: [TokenInfo]?
110110

111111
/// An array of message refusal tokens with log probability information.
112112
public let refusal: [TokenInfo]?
113113

114-
public struct TokenInfo: Decodable {
114+
public struct TokenInfo: Decodable, Sendable {
115115
/// The token.
116116
public let token: String
117117

@@ -136,7 +136,7 @@ public struct ChatCompletionChunk: Decodable {
136136
}
137137
}
138138

139-
public struct Usage: Decodable {
139+
public struct Usage: Decodable, Sendable {
140140
/// Number of tokens in the generated completion.
141141
public let completionTokens: Int?
142142

@@ -152,7 +152,7 @@ public struct ChatCompletionChunk: Decodable {
152152
/// Breakdown of tokens used in the prompt.
153153
public let promptTokensDetails: PromptTokensDetails?
154154

155-
public struct CompletionTokensDetails: Decodable {
155+
public struct CompletionTokensDetails: Decodable, Sendable {
156156
/// Tokens generated by the model for reasoning.
157157
public let reasoningTokens: Int
158158

@@ -161,7 +161,7 @@ public struct ChatCompletionChunk: Decodable {
161161
}
162162
}
163163

164-
public struct PromptTokensDetails: Decodable {
164+
public struct PromptTokensDetails: Decodable, Sendable {
165165
/// Cached tokens present in the prompt.
166166
public let cachedTokens: Int
167167

Sources/LLMChatOpenAI/ChatMessage.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// A struct that represents a message in a chat conversation.
11-
public struct ChatMessage: Encodable {
11+
public struct ChatMessage: Encodable, Sendable {
1212
/// The role of the message's author.
1313
public let role: Role
1414

@@ -19,20 +19,20 @@ public struct ChatMessage: Encodable {
1919
/// Provides the model information to differentiate between participants of the same role.
2020
public let name: String?
2121

22-
public enum Role: String, Codable {
22+
public enum Role: String, Encodable, Sendable {
2323
case system
2424
case user
2525
case assistant
2626
}
2727

28-
public enum Content: Encodable {
28+
public enum Content: Encodable, Sendable {
2929
/// Text content of the message.
3030
case text(String)
3131

3232
/// Image content of the message.
3333
case image(String, detail: ImageDetail = .auto)
3434

35-
public enum ImageDetail: String, Encodable, CaseIterable {
35+
public enum ImageDetail: String, Encodable, Sendable, CaseIterable {
3636
/// High detail mode. The model first sees the low res image (using 85 tokens) and then creates detailed crops using 170 tokens for each 512px x 512px tile.
3737
case high
3838

0 commit comments

Comments
 (0)