Skip to content

Commit

Permalink
feat: conforms to Sendable (#7)
Browse files Browse the repository at this point in the history
* feat: conforms to `Sendable`

* update machine to macOS 15
  • Loading branch information
kevinhermawan authored Oct 29, 2024
1 parent 108b534 commit 1f78b37
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ on:

jobs:
test-ios:
runs-on: macos-14
runs-on: macos-15

steps:
- uses: actions/checkout@v4

- name: Build and test
run: xcodebuild test -scheme LLMChatAnthropic -destination 'platform=iOS Simulator,name=iPhone 15 Pro'
run: xcodebuild test -scheme LLMChatAnthropic -destination 'platform=iOS Simulator,name=iPhone 16 Pro'

test-macos:
runs-on: macos-14
runs-on: macos-15

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:

jobs:
deploy:
runs-on: macos-14
runs-on: macos-15

environment:
name: github-pages
Expand Down
7 changes: 4 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "06dc2e95b68bc2724f9c03ba87b83f54df32fd04fd513286c95461b51735da74",
"pins" : [
{
"identity" : "swift-docc-plugin",
Expand All @@ -23,10 +24,10 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/kevinhermawan/swift-json-schema.git",
"state" : {
"revision" : "48cade5fb09c6fdc86adcf9af7e43a2c7582a65a",
"version" : "1.0.3"
"revision" : "4a9284e44d8ef2bfc863734e9ff535909ae6b27a",
"version" : "2.0.1"
}
}
],
"version" : 2
"version" : 3
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -12,7 +12,7 @@ let package = Package(
targets: ["LLMChatAnthropic"]),
],
dependencies: [
.package(url: "https://github.com/kevinhermawan/swift-json-schema.git", exact: "1.0.3"),
.package(url: "https://github.com/kevinhermawan/swift-json-schema.git", .upToNextMajor(from: "2.0.1")),
.package(url: "https://github.com/apple/swift-docc-plugin.git", .upToNextMajor(from: "1.4.3"))
],
targets: [
Expand Down
4 changes: 2 additions & 2 deletions Playground/Playground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ai.hermawan.swift-llm-chat-anthropic.Playground";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -314,7 +314,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ai.hermawan.swift-llm-chat-anthropic.Playground";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"location" : "https://github.com/kevinhermawan/swift-ai-model-retriever.git",
"state" : {
"branch" : "main",
"revision" : "585de8246341cf0b715357ecfd57c20aea52545c"
"revision" : "b9cd7cd4a68969b4158a2a5a0bc59311028737da"
}
},
{
"identity" : "swift-json-schema",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kevinhermawan/swift-json-schema.git",
"state" : {
"revision" : "48cade5fb09c6fdc86adcf9af7e43a2c7582a65a",
"version" : "1.0.3"
"revision" : "4a9284e44d8ef2bfc863734e9ff535909ae6b27a",
"version" : "2.0.1"
}
}
],
Expand Down
6 changes: 3 additions & 3 deletions Sources/LLMChatAnthropic/ChatCompletion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A struct that represents a chat completion response.
public struct ChatCompletion: Decodable {
public struct ChatCompletion: Decodable, Sendable {
/// A unique identifier for the chat completion.
public let id: String

Expand All @@ -31,7 +31,7 @@ public struct ChatCompletion: Decodable {
public let usage: Usage?

/// A struct that represents a content in the chat completion.
public struct Content: Decodable {
public struct Content: Decodable, Sendable {
/// The type of the content element.
public let type: String

Expand Down Expand Up @@ -63,7 +63,7 @@ public struct ChatCompletion: Decodable {
}

/// A struct that represents usage statistics for the chat completion.
public struct Usage: Decodable {
public struct Usage: Decodable, Sendable {
/// The number of input tokens used.
public let inputTokens: Int

Expand Down
6 changes: 3 additions & 3 deletions Sources/LLMChatAnthropic/ChatCompletionChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A struct that represents a streamed chunk of a chat completion response.
public struct ChatCompletionChunk {
public struct ChatCompletionChunk: Sendable {
/// A unique identifier for the chat completion.
public var id: String

Expand All @@ -31,7 +31,7 @@ public struct ChatCompletionChunk {
public var usage: Usage?

/// A struct that represents the delta content in a chat completion chunk.
public struct Delta: Decodable {
public struct Delta: Decodable, Sendable {
/// The type of the delta content.
public var type: String

Expand All @@ -50,7 +50,7 @@ public struct ChatCompletionChunk {
}

/// A struct that represents usage statistics for the chat completion chunk.
public struct Usage: Decodable {
public struct Usage: Decodable, Sendable {
/// The number of input tokens used.
public var inputTokens: Int

Expand Down
10 changes: 5 additions & 5 deletions Sources/LLMChatAnthropic/ChatMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A struct that represents a message in a chat conversation.
public struct ChatMessage: Encodable {
public struct ChatMessage: Encodable, Sendable {
/// The role of the participant in the chat conversation.
public let role: Role

Expand All @@ -19,14 +19,14 @@ public struct ChatMessage: Encodable {
public var cacheControl: CacheControl?

/// An enum that represents the role of a participant in the chat.
public enum Role: String, Codable {
public enum Role: String, Codable, Sendable {
case system
case user
case assistant
}

/// An enum that represents the content of a chat message.
public enum Content: Encodable {
public enum Content: Encodable, Sendable {
/// A case that represents text content.
case text(String)

Expand Down Expand Up @@ -103,12 +103,12 @@ public struct ChatMessage: Encodable {
}

/// A struct that represents cache control settings for a system message.
public struct CacheControl: Encodable {
public struct CacheControl: Encodable, Sendable {
/// The type of cache control.
public let type: `Type`

/// An enum that represents the types of cache control.
public enum `Type`: String, Encodable, CaseIterable {
public enum `Type`: String, Encodable, Sendable, CaseIterable {
/// A case that represents ephemeral cache control.
case ephemeral
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/LLMChatAnthropic/ChatOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import JSONSchema

/// A struct that represents the options of a chat completion request.
public struct ChatOptions: Encodable {
public struct ChatOptions: Encodable, Sendable {
/// The maximum number of tokens to generate.
public let maxTokens: Int?

Expand Down Expand Up @@ -65,7 +65,7 @@ public struct ChatOptions: Encodable {
}

/// A struct that represents a tool available for the model to use.
public struct Tool: Encodable {
public struct Tool: Encodable, Sendable {
/// The name of the tool.
public let name: String

Expand Down Expand Up @@ -100,7 +100,7 @@ public struct ChatOptions: Encodable {
}

/// An enum that represents the tool choice for the model.
public enum ToolChoice: Encodable {
public enum ToolChoice: Encodable, Sendable {
/// Allows the model to use any available tool.
case any

Expand Down
2 changes: 1 addition & 1 deletion Sources/LLMChatAnthropic/LLMChatAnthropic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// A struct that facilitates interactions with Anthropic and Anthropic-compatible chat completion APIs.
public struct LLMChatAnthropic {
public struct LLMChatAnthropic: Sendable {
private let apiKey: String
private let endpoint: URL
private var headers: [String: String]? = nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/LLMChatAnthropic/LLMChatAnthropicError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// An enum that represents errors from the chat completion request.
public enum LLMChatAnthropicError: LocalizedError {
public enum LLMChatAnthropicError: LocalizedError, Sendable {
/// A case that represents a server-side error response.
///
/// - Parameter message: The error message from the server.
Expand Down

0 comments on commit 1f78b37

Please sign in to comment.