Skip to content

Commit ec88338

Browse files
XMLHexagrammattt
andauthored
Update CI workflow to build on macOS with all traits enabled (#72)
* ci: enable all traits in ci * Don't run tests with traits * Don't build or test with traits on Linux * fix: use convertTranscriptToMLXChat in streamResponse Co-authored-by: XMLHexagram <[email protected]> * swift format -i --recursive . * Remove -v flag from swift commands --------- Co-authored-by: Mattt Zmuda <[email protected]>
1 parent 8dc5a0f commit ec88338

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ jobs:
4242
${{ runner.os }}-swift-${{ matrix.swift }}-spm-
4343
4444
- name: Build
45-
run: swift build -v
45+
run: swift build --traits MLX,Llama,CoreML
4646

4747
- name: Test
48-
run: swift test -v
48+
run: swift test
4949

5050
test-linux:
5151
name: Swift ${{ matrix.swift-version }} on Linux
@@ -66,7 +66,7 @@ jobs:
6666
toolchain: ${{ matrix.swift-version }}
6767

6868
- name: Build
69-
run: swift build -v
69+
run: swift build
7070

7171
- name: Test
72-
run: swift test -v
72+
run: swift test

Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,7 @@
214214
// MARK: - Image Validation
215215

216216
private func validateNoImageSegments(in session: LanguageModelSession) throws {
217-
// Check for image segments in instructions
218-
if let instructions = session.instructions {
219-
for segment in instructions.segments {
220-
if case .image = segment {
221-
throw CoreMLLanguageModelError.unsupportedFeature
222-
}
223-
}
224-
}
225-
217+
// Note: Instructions is a plain text type without segments, so no image check needed there.
226218
// Check for image segments in the most recent prompt
227219
for entry in session.transcript.reversed() {
228220
if case .prompt(let p) = entry {

Sources/AnyLanguageModel/Models/MLXLanguageModel.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ import Foundation
175175
let hub = self.hub
176176
let directory = self.directory
177177

178-
let stream: AsyncThrowingStream<LanguageModelSession.ResponseStream<Content>.Snapshot, any Error> = .init { continuation in
178+
let stream: AsyncThrowingStream<LanguageModelSession.ResponseStream<Content>.Snapshot, any Error> = .init {
179+
continuation in
179180
let task = Task { @Sendable in
180181
do {
181182
let context: ModelContext
@@ -213,7 +214,8 @@ import Foundation
213214
case .chunk(let text):
214215
accumulatedText += text
215216
let raw = GeneratedContent(accumulatedText)
216-
let content: Content.PartiallyGenerated = (accumulatedText as! Content).asPartiallyGenerated()
217+
let content: Content.PartiallyGenerated = (accumulatedText as! Content)
218+
.asPartiallyGenerated()
217219
continuation.yield(.init(content: content, rawContent: raw))
218220
case .info, .toolCall:
219221
break
@@ -357,28 +359,24 @@ import Foundation
357359
// MARK: - Tool Conversion
358360

359361
private func convertToolToMLXSpec(_ tool: any Tool) -> ToolSpec {
360-
// Convert AnyLanguageModel's GenerationSchema to JSON-compatible dictionary
361-
let parametersDict: [String: Any]
362+
// Convert AnyLanguageModel's GenerationSchema to Sendable dictionary
363+
// using MLXLMCommon.JSONValue which is already Sendable
364+
let parametersValue: JSONValue
362365
do {
363366
let resolvedSchema = tool.parameters.withResolvedRoot() ?? tool.parameters
364-
let encoder = JSONEncoder()
365-
let data = try encoder.encode(resolvedSchema)
366-
if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] {
367-
parametersDict = json
368-
} else {
369-
parametersDict = ["type": "object", "properties": [:], "required": []]
370-
}
367+
let data = try JSONEncoder().encode(resolvedSchema)
368+
parametersValue = try JSONDecoder().decode(JSONValue.self, from: data)
371369
} catch {
372-
parametersDict = ["type": "object", "properties": [:], "required": []]
370+
parametersValue = .object(["type": .string("object"), "properties": .object([:]), "required": .array([])])
373371
}
374372

375373
return [
376374
"type": "function",
377375
"function": [
378376
"name": tool.name,
379377
"description": tool.description,
380-
"parameters": parametersDict,
381-
],
378+
"parameters": parametersValue,
379+
] as [String: any Sendable],
382380
]
383381
}
384382

0 commit comments

Comments
 (0)