diff --git a/Package.resolved b/Package.resolved index 9916dd1..1ae329d 100644 --- a/Package.resolved +++ b/Package.resolved @@ -19,6 +19,33 @@ "version" : "1.3.1" } }, + { + "identity" : "llama.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattt/llama.swift", + "state" : { + "revision" : "74b6ee3ebbc5441907c3837948f409b71e73e071", + "version" : "1.7211.0" + } + }, + { + "identity" : "mlx-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ml-explore/mlx-swift", + "state" : { + "revision" : "072b684acaae80b6a463abab3a103732f33774bf", + "version" : "0.29.1" + } + }, + { + "identity" : "mlx-swift-lm", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ml-explore/mlx-swift-lm", + "state" : { + "branch" : "main", + "revision" : "d9f46e3a1fe715d01304372089aba5f39c585327" + } + }, { "identity" : "partialjsondecoder", "kind" : "remoteSourceControl", @@ -37,6 +64,24 @@ "version" : "1.3.0" } }, + { + "identity" : "swift-jinja", + "kind" : "remoteSourceControl", + "location" : "https://github.com/huggingface/swift-jinja.git", + "state" : { + "revision" : "06a511d5adab5a812852ff972e65702a24b8ce30", + "version" : "2.2.0" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0c0290ff6b24942dadb83a929ffaaa1481df04a2", + "version" : "1.1.1" + } + }, { "identity" : "swift-syntax", "kind" : "remoteSourceControl", @@ -45,6 +90,15 @@ "revision" : "0687f71944021d616d34d922343dcef086855920", "version" : "600.0.1" } + }, + { + "identity" : "swift-transformers", + "kind" : "remoteSourceControl", + "location" : "https://github.com/huggingface/swift-transformers", + "state" : { + "branch" : "573e5c9", + "revision" : "573e5c9036c2f136b3a8a071da8e8907322403d0" + } } ], "version" : 3 diff --git a/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift b/Sources/AnyLanguageModel/Models/CoreMLLanguageModel.swift index c27bdc8..cde04e4 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 77accfb..fb5d05b 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], ] }