Update LLMHelper diagnostic reporting and swiftc target version
This commit is contained in:
+15
-14
@@ -1,9 +1,4 @@
|
||||
// LLMHelper.swift - Interface with macOS native on-device LLM (FoundationModels / Apple Intelligence)
|
||||
//
|
||||
// Usage:
|
||||
// llm-helper --check
|
||||
// llm-helper --prompt "Hello" [--system "System prompt"]
|
||||
|
||||
// LLMHelper.swift - Interface with macOS native Apple Intelligence FoundationModels
|
||||
import Foundation
|
||||
import FoundationModels
|
||||
|
||||
@@ -48,17 +43,28 @@ func fail(_ message: String) -> Never {
|
||||
}
|
||||
|
||||
@main
|
||||
@available(macOS 26.0, *)
|
||||
struct LLMHelperApp {
|
||||
static func main() async {
|
||||
let options = parseArguments()
|
||||
|
||||
let model = SystemLanguageModel.default
|
||||
let isAvailable = model.isAvailable
|
||||
|
||||
if options.check {
|
||||
let model = SystemLanguageModel.default
|
||||
let isAvailable = model.isAvailable
|
||||
var attemptError: String = ""
|
||||
do {
|
||||
let session = LanguageModelSession(model: model)
|
||||
_ = try await session.respond(to: "test")
|
||||
} catch {
|
||||
attemptError = error.localizedDescription
|
||||
}
|
||||
|
||||
emit([
|
||||
"available": isAvailable,
|
||||
"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)
|
||||
}
|
||||
@@ -68,11 +74,6 @@ struct LLMHelperApp {
|
||||
}
|
||||
|
||||
do {
|
||||
let model = SystemLanguageModel.default
|
||||
guard model.isAvailable else {
|
||||
fail("macOS SystemLanguageModel is not available on this machine")
|
||||
}
|
||||
|
||||
let instructions = options.systemPrompt ?? ""
|
||||
let session: LanguageModelSession
|
||||
if !instructions.isEmpty {
|
||||
|
||||
+2
-2
@@ -24,12 +24,12 @@ else
|
||||
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"
|
||||
if ./llm-helper --check >/dev/null 2>&1; then
|
||||
echo "llm-helper runs — ./llm-helper --check for details"
|
||||
fi
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user