Claude for Foundation Models क्या है?
Claude for Foundation Models Apple के Foundation Models APIs के ज़रिए Claude चलाएँ, उसी सेशन कोड के साथ जो आप ऑन-डिवाइस मॉडल के लिए इस्तेमाल करते हैं. यह App Orchestration टूल्स की App Frameworks श्रेणी में आता है; ओपन सोर्स है, Swift में लिखा गया है और Apache-2.0 लाइसेंस के तहत है।
सारांश
Claude for Foundation Models Anthropic का Swift पैकेज है, जो Apple के Foundation Models framework के अंदर Claude को एक server-side language model बना देता है। यह Claude को framework के `LanguageModel` प्रोटोकॉल से जोड़ता है, इसलिए ऐप `LanguageModelSession` के ज़रिए उससे बात करता है: `respond(to:)`, `streamResponse(to:)`, guided generation और tool calling, ठीक वैसे ही जैसे वह Apple के on-device model से करता। प्रोवाइडर बदलना उस मॉडल को बदलने जितना आसान है जिसे आप session को देते हैं, उसके आसपास के call sites को दोबारा लिखना नहीं पड़ता।
एंट्री पॉइंट `ClaudeLanguageModel` है। मॉडल आइडेंटिफ़ायर `ClaudeModel` की values हैं, जो compiled-in constants के रूप में आते हैं। ये API model IDs को मिरर करते हैं और हर मॉडल की capabilities रखते हैं, यानी कौन से sampling parameters, effort levels, thinking modes, structured output और image input वह स्वीकार करता है। पैकेज इन capabilities का इस्तेमाल यह तय करने के लिए करता है कि कौन से request fields भेजने हैं, क्योंकि ऐसा field भेजना जिसे मॉडल reject करे, एक hard error है। जो ID अभी compiled-in नहीं है, उसे यह घोषित करके बनाया जा सकता है कि वह क्या स्वीकार करता है।
तीन authentication modes उन तरीकों को कवर करते हैं जिनमें Apple ऐप असल में बनते हैं: App Attest (सुझाया गया तरीका, जहाँ हर install यह साबित करता है कि वह असली कॉपी है और इस्तेमाल का बिल आपके Anthropic workspace पर जाता है, इसलिए ऐप में कोई key नहीं जाती और backend की ज़रूरत नहीं पड़ती), simulator पर iteration के लिए सादी API key, और आपके अपने relay की ओर इशारा करने वाला proxied mode। Server-side tools, यानी web search और code execution, response stream होते समय transcript में activity के रूप में दिखते हैं, जिन्हें आप inline render कर सकते हैं। यह पैकेज OS 27 betas को टारगेट करता है, Apache-2.0 लाइसेंस के तहत है, और Anthropic इसे best-effort आधार पर मेंटेन करता है, बाहरी contributions स्वीकार किए बिना।
यह क्या करता है
- Claude को Apple के Foundation Models `LanguageModel` प्रोटोकॉल से जोड़ता है, यानी वही `LanguageModelSession` API जो on-device model के लिए है
- Capability-aware requests: हर `ClaudeModel` constant घोषित करता है कि वह कौन से sampling parameters, effort levels और modalities स्वीकार करता है, इसलिए असमर्थित fields कभी नहीं भेजे जाते
- App Attest authentication: ऐप में कोई API key नहीं जाती और developer backend की ज़रूरत नहीं पड़ती। API-key और proxied modes simulator पर काम करने और custom relays के लिए हैं
- `streamResponse(to:)` के ज़रिए streaming, जिसमें हर element एक cumulative snapshot होता है
- `@Generable` types और `@Guide` annotations के ज़रिए typed structured output
- Server-side web search और code execution को inline transcript activity के रूप में render किया जाता है, और thinking signatures व citations हर turn में replay होते हैं
शुरू करें
इस पैकेज के लिए Xcode 27 और OS 27 target (iOS, macOS, visionOS या watchOS) चाहिए, साथ ही एक credential: Anthropic console से App Attest client ID, या simulator के लिए API key।
Swift Package Manager dependency जोड़ें
इसे Package.swift में जोड़ें, या Xcode में File ▸ Add Package Dependencies… का इस्तेमाल करके repository URL पेस्ट करें।
dependencies: [
.package(url: "https://github.com/anthropics/ClaudeForFoundationModels.git", from: "0.1.0")
]मॉडल बनाएँ और एक turn चलाएँ
ClaudeLanguageModel एंट्री पॉइंट है। इसे LanguageModelSession को दें और session का इस्तेमाल वैसे ही करें जैसे आप किसी भी Foundation Models प्रोवाइडर के साथ करते हैं।
import FoundationModels
import ClaudeForFoundationModels
let model = ClaudeLanguageModel(
name: .sonnet5,
auth: .apiKey(ProcessInfo.processInfo.environment["ANTHROPIC_API_KEY"] ?? "")
)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "Plan a 4-day trip to Buenos Aires.")
print(response.content)शिप होने वाले ऐप के लिए App Attest पर जाएँ
Anthropic console में ऐप की team और bundle ID रजिस्टर करें, App Attest entitlement जोड़ें, और one-time attestation का खर्च पहले prompt पर नहीं, बल्कि लॉन्च के समय ही चुका दें। इसके लिए physical device ज़रूरी है।
let model = ClaudeLanguageModel(name: .sonnet5, auth: .appAttest(clientID: "clid_..."))
try await model.authenticateIfNeeded()Typed result माँगें
किसी type पर @Generable annotation लगाएँ और उसे `generating:` को पास करें; response content उसी type की value होता है।
@Generable
struct Trip {
@Guide(description: "Destination city") var destination: String
@Guide(description: "Length in days") var days: Int
}
let response = try await session.respond(to: "Plan a trip to Tokyo.", generating: Trip.self)
print(response.content.destination)साथ दिया गया example आज़माएँ
Examples/ClaudeExample एक chat turn को terminal पर stream करता है और token usage प्रिंट करता है; --search उस turn के लिए server-side web search चालू करता है। इसे चलाने के लिए macOS 27 host चाहिए।
ANTHROPIC_API_KEY=<key> swift run ClaudeExample "What should I see in Kyoto?"कमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।
कब इस्तेमाल करें
- Apple-platform फ़ीचर का प्रोटोटाइप on-device model पर बनाएँ, फिर session कोड दोबारा लिखे बिना उसे Claude पर ले जाएँ
- ऐसा Claude-backed iOS या macOS ऐप बनाएँ जिसमें कोई निकाली जा सकने वाली API key न हो, बल्कि बंडल किए गए secret की जगह App Attest का इस्तेमाल हो
- free text को parse करने की बजाय @Generable से मॉडल से सीधे typed values लें
- स्ट्रीमिंग chat UI में web-search और code-execution activity को inline render करें
How Claude for Foundation Models compares
Claude for Foundation Models alongside other open-source app frameworks tools AI/TLDR tracks, ranked by GitHub stars.
| टूल | स्टार | यह क्या करता है |
|---|---|---|
| LangChain | ★ 150k | आपस में जुड़ने वाले और बदले जा सकने वाले components से agents और LLM ऐप बनाएं |
| LlamaIndex | ★ 53.1k | रिट्रीवल और एजेंट्स के ज़रिए भाषा मॉडल को अपने डेटा से जोड़ें |
| Haystack | ★ 27.2k | प्रोडक्शन RAG पाइपलाइन और LLM एजेंट बनाने के लिए ओपन सोर्स Python फ़्रेमवर्क |
| Jina | ★ 21.9k | gRPC, HTTP और WebSockets पर संवाद करने वाली AI सर्विस बनाएं और चलाएं |
| RocketRide | ★ 19.9k | एक ओपन सोर्स, MIT लाइसेंस वाला AI मेटा-हार्नेस, जो C++ रनटाइम पर चलता है: VS Code, CLI, Python और TypeScript SDK, या इसके बिल्ट-इन MCP सर्वर से AI एजेंट और RAG पाइपलाइन बनाएं, टेस्ट करें और चलाएं |
| LLM | ★ 12.9k | कमांड लाइन से दर्जनों लैंग्वेज मॉडल इस्तेमाल करें, और हर एक को SQLite में लॉग करें |
| Prompt Flow | ★ 11.3k | लिंक्ड flows के साथ production-quality LLM ऐप्स बनाएँ, टेस्ट करें और शिप करें |
| Claude for Foundation Models | ★ 378 | Apple के Foundation Models APIs के ज़रिए Claude चलाएँ, उसी सेशन कोड के साथ जो आप ऑन-डिवाइस मॉडल के लिए इस्तेमाल करते हैं |
