Update LLMHelper diagnostic reporting and swiftc target version

This commit is contained in:
Adolfo Reyna
2026-08-07 18:29:15 -04:00
parent f579a26cc0
commit 24d6e436a0
2 changed files with 17 additions and 16 deletions
+15 -14
View File
@@ -1,9 +1,4 @@
// LLMHelper.swift - Interface with macOS native on-device LLM (FoundationModels / Apple Intelligence) // LLMHelper.swift - Interface with macOS native Apple Intelligence FoundationModels
//
// Usage:
// llm-helper --check
// llm-helper --prompt "Hello" [--system "System prompt"]
import Foundation import Foundation
import FoundationModels import FoundationModels
@@ -48,17 +43,28 @@ func fail(_ message: String) -> Never {
} }
@main @main
@available(macOS 26.0, *)
struct LLMHelperApp { struct LLMHelperApp {
static func main() async { static func main() async {
let options = parseArguments() let options = parseArguments()
let model = SystemLanguageModel.default
let isAvailable = model.isAvailable
if options.check { if options.check {
let model = SystemLanguageModel.default var attemptError: String = ""
let isAvailable = model.isAvailable do {
let session = LanguageModelSession(model: model)
_ = try await session.respond(to: "test")
} catch {
attemptError = error.localizedDescription
}
emit([ emit([
"available": isAvailable, "available": isAvailable,
"model": "macOS SystemLanguageModel", "model": "macOS SystemLanguageModel",
"reason": isAvailable ? "macOS Apple Intelligence model available" : "SystemLanguageModel unavailable on this hardware/OS configuration" "attemptError": attemptError,
"reason": isAvailable ? "macOS Apple Intelligence model available" : "SystemLanguageModel isAvailable returned false (\(attemptError))"
]) ])
exit(0) exit(0)
} }
@@ -68,11 +74,6 @@ struct LLMHelperApp {
} }
do { do {
let model = SystemLanguageModel.default
guard model.isAvailable else {
fail("macOS SystemLanguageModel is not available on this machine")
}
let instructions = options.systemPrompt ?? "" let instructions = options.systemPrompt ?? ""
let session: LanguageModelSession let session: LanguageModelSession
if !instructions.isEmpty { if !instructions.isEmpty {
+2 -2
View File
@@ -24,12 +24,12 @@ else
fi fi
fi fi
if swiftc -O LLMHelper.swift -o llm-helper 2>/dev/null; then if swiftc -O -parse-as-library -target arm64-apple-macosx26.0 LLMHelper.swift -o llm-helper 2>/dev/null; then
echo "built $HERE/llm-helper" echo "built $HERE/llm-helper"
if ./llm-helper --check >/dev/null 2>&1; then if ./llm-helper --check >/dev/null 2>&1; then
echo "llm-helper runs — ./llm-helper --check for details" echo "llm-helper runs — ./llm-helper --check for details"
fi fi
else else
echo "could not build llm-helper with FoundationModels; fallback to Python MLX/PyObjC bridge will be available" echo "could not build llm-helper with FoundationModels; fallback to Python MLX bridge will be available"
fi fi