Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -11,6 +11,51 @@ tags:
|
|
| 11 |
library_name: coreml
|
| 12 |
---
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# FunctionGemma-270M for Apple CoreML (ANE-optimized)
|
| 15 |
|
| 16 |
CoreML conversion of `google/functiongemma-270m-it` produced with the
|
|
|
|
| 11 |
library_name: coreml
|
| 12 |
---
|
| 13 |
|
| 14 |
+
## Use it from Swift
|
| 15 |
+
|
| 16 |
+
<!-- swift-usage-begin -->
|
| 17 |
+
### Add the package
|
| 18 |
+
|
| 19 |
+
`Package.swift`:
|
| 20 |
+
|
| 21 |
+
```swift
|
| 22 |
+
.package(url: "https://github.com/john-rocky/CoreML-LLM", branch: "main"),
|
| 23 |
+
|
| 24 |
+
// In your target:
|
| 25 |
+
.product(name: "CoreMLLLM", package: "CoreML-LLM"),
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
Platforms: iOS 18+ / macOS 15+.
|
| 29 |
+
|
| 30 |
+
### Download + call
|
| 31 |
+
|
| 32 |
+
```swift
|
| 33 |
+
import CoreMLLLM
|
| 34 |
+
|
| 35 |
+
let modelsDir = try FileManager.default.url(
|
| 36 |
+
for: .applicationSupportDirectory, in: .userDomainMask,
|
| 37 |
+
appropriateFor: nil, create: true)
|
| 38 |
+
|
| 39 |
+
// Pulls the bundle from this repo on first call, then loads.
|
| 40 |
+
let fg = try await FunctionGemma.downloadAndLoad(modelsDir: modelsDir)
|
| 41 |
+
|
| 42 |
+
// Plain chat-templated generation
|
| 43 |
+
let stream = try await fg.generate("How do I list files in Swift?")
|
| 44 |
+
for await chunk in stream { print(chunk, terminator: "") }
|
| 45 |
+
|
| 46 |
+
// Function-call generation (returns a single JSON object)
|
| 47 |
+
let json = try await fg.generateFunctionCall(
|
| 48 |
+
tools: tools, // your [String: Any] schema
|
| 49 |
+
userMessage: "Get me weather for Tokyo")
|
| 50 |
+
print(json)
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
See [`Gemma3FunctionGemma.swift`](https://github.com/john-rocky/CoreML-LLM/blob/main/Sources/CoreMLLLM/Gemma3FunctionGemma.swift)
|
| 54 |
+
for the full API.
|
| 55 |
+
<!-- swift-usage-end -->
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
# FunctionGemma-270M for Apple CoreML (ANE-optimized)
|
| 60 |
|
| 61 |
CoreML conversion of `google/functiongemma-270m-it` produced with the
|