Skip to content

Commit 40a196d

Browse files
Merge pull request #5 from laike9m/main
Fix build errors, set minimum target to macOS 13, specify the dependencies' versions
2 parents 59563cc + d65ae55 commit 40a196d

File tree

8 files changed

+39
-27
lines changed

8 files changed

+39
-27
lines changed

.swiftformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--disable all

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.

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
name: "PolyAI",
88
platforms: [
99
.iOS(.v15),
10-
.macOS(.v14)
10+
.macOS(.v13)
1111
],
1212
products: [
1313
// Products define the executables and libraries a package produces, making them visible to other packages.
@@ -17,8 +17,8 @@ let package = Package(
1717
],
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
20-
.package(url: "https://github.com/jamesrochabrun/SwiftOpenAI", branch: "main"),
21-
.package(url: "https://github.com/jamesrochabrun/SwiftAnthropic", branch: "main"),
20+
.package(url: "https://github.com/jamesrochabrun/SwiftOpenAI", from: "4.0.6"),
21+
.package(url: "https://github.com/jamesrochabrun/SwiftAnthropic", from: "2.1.3"),
2222
],
2323
targets: [
2424
// Targets are the basic building blocks of a package, defining a module or a test suite.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Currently, the package supports OpenAI, Azure, Anthropic, Gemini, Groq, DeepSeek
9797
```swift
9898

9999
// OpenAI
100-
let openAIConfiguration: LLMConfiguration = .openAI(.api(key: "your_openai_api_key_here")
100+
let openAIConfiguration: LLMConfiguration = .openAI(.api(key: "your_openai_api_key_here"))
101101

102102
// Gemini
103103
let geminiConfiguration: LLMConfiguration = .openAI(.gemini(apiKey: "your_gemini_api_key_here"))

Sources/PolyAI/Interfaces/Response/Message/LLMMessageResponse+Anthropic.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,35 @@ import SwiftAnthropic
1111
// MARK: Anthropic
1212

1313
extension MessageResponse: LLMMessageResponse {
14-
14+
public var id: String? {
15+
nil
16+
}
17+
18+
public var model: String? {
19+
nil
20+
}
21+
1522
public var createdAt: Int? {
1623
nil
1724
}
18-
25+
1926
public var contentDescription: String {
2027
content.map { contentItem in
2128
switch contentItem {
22-
case .text(let text, _):
29+
case let .text(text, _):
2330
return text
24-
case .toolUse(let toolUSe):
31+
case let .toolUse(toolUSe):
2532
return "Tool: \(toolUSe.name)"
33+
case .thinking:
34+
return ""
2635
}
2736
}.first ?? ""
2837
}
29-
38+
3039
public var usageMetrics: UsageMetrics {
3140
ChatUsageMetrics(inputTokens: usage.inputTokens ?? 0, outputTokens: usage.outputTokens, totalTokens: nil)
3241
}
33-
42+
3443
public var tools: [ToolUsage] {
3544
[]
3645
}
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// LLMMessageResponse+OpenAI.swift
3-
//
3+
//
44
//
55
// Created by James Rochabrun on 4/15/24.
66
//
@@ -11,24 +11,27 @@ import SwiftOpenAI
1111
// MARK: OpenAI
1212

1313
extension ChatCompletionObject: LLMMessageResponse {
14-
1514
public var createdAt: Int? {
1615
created
1716
}
18-
17+
1918
public var contentDescription: String {
20-
choices.first?.message.content ?? ""
19+
choices?.first?.message?.content ?? ""
2120
}
22-
21+
2322
public var usageMetrics: UsageMetrics {
24-
ChatUsageMetrics(inputTokens: usage?.promptTokens ?? 0, outputTokens: usage?.completionTokens ?? 0, totalTokens: usage?.totalTokens)
23+
ChatUsageMetrics(
24+
inputTokens: usage?.promptTokens ?? 0,
25+
outputTokens: usage?.completionTokens ?? 0,
26+
totalTokens: usage?.totalTokens ?? 0
27+
)
2528
}
26-
29+
2730
public var tools: [ToolUsage] {
2831
[]
2932
}
30-
33+
3134
public var role: String {
32-
choices.first?.message.role ?? "unknown"
35+
choices?.first?.message?.role ?? "unknown"
3336
}
3437
}

Sources/PolyAI/Interfaces/Response/Message/LLMMessageResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import Foundation
1212
/// A protocol defining the required properties for a response from an LLM service.
1313
public protocol LLMMessageResponse {
1414
/// A unique identifier for the message.
15-
var id: String { get }
15+
var id: String? { get }
1616

1717
/// The model of the LLM that processed the message.
18-
var model: String { get }
18+
var model: String? { get }
1919

2020
/// The role associated with the message, such as "user" or "assistant".
2121
var role: String { get }

Sources/PolyAI/Interfaces/Response/Stream/LLMMessageStreamResponse+OpenAI.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import SwiftOpenAI
1111
// MARK: OpenAI
1212

1313
extension ChatCompletionChunkObject: LLMMessageStreamResponse {
14-
1514
public var content: String? {
16-
choices.first?.delta.content
15+
choices?.first?.delta?.content
1716
}
1817
}

0 commit comments

Comments
 (0)