python-apple-fm-sdk

python-apple-fm-sdk

GitHub: https://github.com/apple/python-apple-fm-sdk

⭐ 星星數: 1352

摘要: 這是 Apple 官方維護的 Python SDK,為 macOS 的 Foundation Models 框架提供 Pythonic 的綁定,讓開發者能直接取用 Apple Intelligence 核心的裝置端(on-device)基礎模型。可以用 Python 做批次推論、即時串流文字生成,以及以 schema 約束的引導式生成(guided generation)。

技術堆疊: Python, Swift, Apple Foundation Models, macOS, asyncio

架構: SDK 底層橋接 Apple 的 Foundation Models framework,上層以 Python 包裝出 SystemLanguageModel 與 LanguageModelSession 等介面:先檢查模型可用性,再建立 session 並以 async 方式呼叫 respond() 取得回應。引導生成透過 Python decorator 定義結構化輸出 schema,確保回應型別安全;亦支援自訂模型設定與處理 Swift 應用匯出的 transcript 以進行品質分析。使用門檻為 macOS 26.0+、Xcode 26.0+、Python 3.10+ 且開啟 Apple Intelligence 的相容 Mac,pip install apple-fm-sdk 即可安裝。