From 03b729488007f17f18fd8be8d2b4d6dced6fe23b Mon Sep 17 00:00:00 2001 From: XMLHexagram Date: Tue, 23 Dec 2025 00:28:30 +0100 Subject: [PATCH 1/6] ci: enable all traits in ci --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 611b570e..1e7cbdc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,10 +42,10 @@ jobs: ${{ runner.os }}-swift-${{ matrix.swift }}-spm- - name: Build - run: swift build -v + run: swift build -v --traits MLX,Llama,CoreML - name: Test - run: swift test -v + run: swift test -v --traits MLX,Llama,CoreML test-linux: name: Swift ${{ matrix.swift-version }} on Linux @@ -66,7 +66,7 @@ jobs: toolchain: ${{ matrix.swift-version }} - name: Build - run: swift build -v + run: swift build -v --traits MLX,Llama,CoreML - name: Test - run: swift test -v + run: swift test -v --traits MLX,Llama,CoreML From e556114817f68e15e0ae35cb5bdb6c8a5a1b3af1 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 5 Jan 2026 04:52:27 -1000 Subject: [PATCH 2/6] Don't run tests with traits --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e7cbdc5..07141ede 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: run: swift build -v --traits MLX,Llama,CoreML - name: Test - run: swift test -v --traits MLX,Llama,CoreML + run: swift test -v test-linux: name: Swift ${{ matrix.swift-version }} on Linux From dc0eb717651f4f0bc9c37ac9dc9e6954859d1c98 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 5 Jan 2026 04:52:35 -1000 Subject: [PATCH 3/6] Don't build or test with traits on Linux --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07141ede..0094d72b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: toolchain: ${{ matrix.swift-version }} - name: Build - run: swift build -v --traits MLX,Llama,CoreML + run: swift build -v - name: Test - run: swift test -v --traits MLX,Llama,CoreML + run: swift test -v From 49964fb9c95cfb6d511d4a702af412fb5958ec07 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 5 Jan 2026 05:02:06 -1000 Subject: [PATCH 4/6] fix: use convertTranscriptToMLXChat in streamResponse Co-authored-by: XMLHexagram --- .../Models/CoreMLLanguageModel.swift | 10 +--------- .../Models/MLXLanguageModel.swift | 20 ++++++++----------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift b/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift index c27bdc87..cde04e41 100644 --- a/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift +++ b/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift @@ -214,15 +214,7 @@ // MARK: - Image Validation private func validateNoImageSegments(in session: LanguageModelSession) throws { - // Check for image segments in instructions - if let instructions = session.instructions { - for segment in instructions.segments { - if case .image = segment { - throw CoreMLLanguageModelError.unsupportedFeature - } - } - } - + // Note: Instructions is a plain text type without segments, so no image check needed there. // Check for image segments in the most recent prompt for entry in session.transcript.reversed() { if case .prompt(let p) = entry { diff --git a/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift b/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift index 77accfb5..fb5d05b3 100644 --- a/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift +++ b/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift @@ -357,19 +357,15 @@ import Foundation // MARK: - Tool Conversion private func convertToolToMLXSpec(_ tool: any Tool) -> ToolSpec { - // Convert AnyLanguageModel's GenerationSchema to JSON-compatible dictionary - let parametersDict: [String: Any] + // Convert AnyLanguageModel's GenerationSchema to Sendable dictionary + // using MLXLMCommon.JSONValue which is already Sendable + let parametersValue: JSONValue do { let resolvedSchema = tool.parameters.withResolvedRoot() ?? tool.parameters - let encoder = JSONEncoder() - let data = try encoder.encode(resolvedSchema) - if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] { - parametersDict = json - } else { - parametersDict = ["type": "object", "properties": [:], "required": []] - } + let data = try JSONEncoder().encode(resolvedSchema) + parametersValue = try JSONDecoder().decode(JSONValue.self, from: data) } catch { - parametersDict = ["type": "object", "properties": [:], "required": []] + parametersValue = .object(["type": .string("object"), "properties": .object([:]), "required": .array([])]) } return [ @@ -377,8 +373,8 @@ import Foundation "function": [ "name": tool.name, "description": tool.description, - "parameters": parametersDict, - ], + "parameters": parametersValue, + ] as [String: any Sendable], ] } From 371bc8fc7b94a612454897553626fc528fb3651f Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 5 Jan 2026 05:10:58 -1000 Subject: [PATCH 5/6] swift format -i --recursive . --- Sources/AnyLanguageModel/Models/MLXLanguageModel.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift b/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift index fb5d05b3..1f13824d 100644 --- a/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift +++ b/Sources/AnyLanguageModel/Models/MLXLanguageModel.swift @@ -175,7 +175,8 @@ import Foundation let hub = self.hub let directory = self.directory - let stream: AsyncThrowingStream.Snapshot, any Error> = .init { continuation in + let stream: AsyncThrowingStream.Snapshot, any Error> = .init { + continuation in let task = Task { @Sendable in do { let context: ModelContext @@ -213,7 +214,8 @@ import Foundation case .chunk(let text): accumulatedText += text let raw = GeneratedContent(accumulatedText) - let content: Content.PartiallyGenerated = (accumulatedText as! Content).asPartiallyGenerated() + let content: Content.PartiallyGenerated = (accumulatedText as! Content) + .asPartiallyGenerated() continuation.yield(.init(content: content, rawContent: raw)) case .info, .toolCall: break From 6cbd0d0ea684f9922239046e052a8033149e95aa Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 5 Jan 2026 05:12:37 -1000 Subject: [PATCH 6/6] Remove -v flag from swift commands --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0094d72b..64537485 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,10 +42,10 @@ jobs: ${{ runner.os }}-swift-${{ matrix.swift }}-spm- - name: Build - run: swift build -v --traits MLX,Llama,CoreML + run: swift build --traits MLX,Llama,CoreML - name: Test - run: swift test -v + run: swift test test-linux: name: Swift ${{ matrix.swift-version }} on Linux @@ -66,7 +66,7 @@ jobs: toolchain: ${{ matrix.swift-version }} - name: Build - run: swift build -v + run: swift build - name: Test - run: swift test -v + run: swift test