@inferrlm/react-native-mlx 0.2.0-inferrlm.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MLXReactNative.podspec +42 -0
- package/ios/Bridge.h +8 -0
- package/ios/Sources/HybridLLM.swift +245 -0
- package/ios/Sources/HybridModelManager.swift +77 -0
- package/ios/Sources/LLMError.swift +6 -0
- package/ios/Sources/MLXReactNative.h +16 -0
- package/ios/Sources/ModelDownloader.swift +103 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/llm.js +125 -0
- package/lib/module/llm.js.map +1 -0
- package/lib/module/modelManager.js +79 -0
- package/lib/module/modelManager.js.map +1 -0
- package/lib/module/models.js +41 -0
- package/lib/module/models.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/specs/LLM.nitro.js +4 -0
- package/lib/module/specs/LLM.nitro.js.map +1 -0
- package/lib/module/specs/ModelManager.nitro.js +4 -0
- package/lib/module/specs/ModelManager.nitro.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/llm.d.ts +87 -0
- package/lib/typescript/src/llm.d.ts.map +1 -0
- package/lib/typescript/src/modelManager.d.ts +53 -0
- package/lib/typescript/src/modelManager.d.ts.map +1 -0
- package/lib/typescript/src/models.d.ts +29 -0
- package/lib/typescript/src/models.d.ts.map +1 -0
- package/lib/typescript/src/specs/LLM.nitro.d.ts +88 -0
- package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/ModelManager.nitro.d.ts +41 -0
- package/lib/typescript/src/specs/ModelManager.nitro.d.ts.map +1 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +60 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +98 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +399 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +62 -0
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +41 -0
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +40 -0
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +160 -0
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +116 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +47 -0
- package/nitrogen/generated/ios/swift/GenerationStats.swift +69 -0
- package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +67 -0
- package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +285 -0
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +60 -0
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +234 -0
- package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +138 -0
- package/nitrogen/generated/ios/swift/LLMMessage.swift +47 -0
- package/nitrogen/generated/shared/c++/GenerationStats.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +35 -0
- package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +87 -0
- package/nitrogen/generated/shared/c++/LLMMessage.hpp +79 -0
- package/package.json +142 -0
- package/src/index.ts +6 -0
- package/src/llm.ts +144 -0
- package/src/modelManager.ts +88 -0
- package/src/models.ts +45 -0
- package/src/specs/LLM.nitro.ts +98 -0
- package/src/specs/ModelManager.nitro.ts +44 -0
package/package.json
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inferrlm/react-native-mlx",
|
|
3
|
+
"version": "0.2.0-inferrlm.1",
|
|
4
|
+
"description": "MLX Swift integration for React Native - InferrLM fork with enhanced features",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "rm -rf lib && bun typecheck && bob build",
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"clean": "rm -rf android/build node_modules/**/android/build lib android/.cxx node_modules/**/android/.cxx",
|
|
14
|
+
"release": "release-it",
|
|
15
|
+
"specs": "bun typecheck && nitrogen --logLevel=\\\"debug\\\" && bun run build",
|
|
16
|
+
"specs:pod": "bun specs && bun --cwd ../example pod"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"nitro",
|
|
21
|
+
"nitro-module",
|
|
22
|
+
"expo",
|
|
23
|
+
"llm",
|
|
24
|
+
"mlx",
|
|
25
|
+
"mlx-swift",
|
|
26
|
+
"apple",
|
|
27
|
+
"apple-silicon",
|
|
28
|
+
"react-native-mlx",
|
|
29
|
+
"ai",
|
|
30
|
+
"on-device-ai",
|
|
31
|
+
"inferrlm",
|
|
32
|
+
"ios"
|
|
33
|
+
],
|
|
34
|
+
"files": [
|
|
35
|
+
"src",
|
|
36
|
+
"react-native.config.js",
|
|
37
|
+
"lib",
|
|
38
|
+
"nitrogen",
|
|
39
|
+
"cpp",
|
|
40
|
+
"android/build.gradle",
|
|
41
|
+
"android/gradle.properties",
|
|
42
|
+
"android/CMakeLists.txt",
|
|
43
|
+
"android/src",
|
|
44
|
+
"ios/**/*.h",
|
|
45
|
+
"ios/**/*.m",
|
|
46
|
+
"ios/**/*.mm",
|
|
47
|
+
"ios/**/*.cpp",
|
|
48
|
+
"ios/**/*.swift",
|
|
49
|
+
"app.plugin.js",
|
|
50
|
+
"*.podspec",
|
|
51
|
+
"README.md"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/sbhjt-gr/react-native-nitro-mlx.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Subhajit Ghosh <sbhjt.gr@gmail.com>",
|
|
58
|
+
"contributors": [
|
|
59
|
+
"Henry Paulino <me@henrypl.com> (original author)"
|
|
60
|
+
],
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"bugs": "https://github.com/sbhjt-gr/react-native-nitro-mlx/issues",
|
|
63
|
+
"homepage": "https://github.com/sbhjt-gr/react-native-nitro-mlx#readme",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"registry": "https://registry.npmjs.org/",
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@expo/config-plugins": "^9.0.10",
|
|
70
|
+
"@release-it/bumper": "^7.0.5",
|
|
71
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
72
|
+
"nitrogen": "^0.31.10",
|
|
73
|
+
"react-native-builder-bob": "^0.39.1",
|
|
74
|
+
"release-it": "^19.0.4"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"react": "*",
|
|
78
|
+
"react-native": "*",
|
|
79
|
+
"react-native-nitro-modules": "*"
|
|
80
|
+
},
|
|
81
|
+
"release-it": {
|
|
82
|
+
"npm": {
|
|
83
|
+
"publish": true,
|
|
84
|
+
"skipVersion": true
|
|
85
|
+
},
|
|
86
|
+
"github": {
|
|
87
|
+
"release": true,
|
|
88
|
+
"releaseName": "v${version}"
|
|
89
|
+
},
|
|
90
|
+
"hooks": {
|
|
91
|
+
"after:bump": "bun specs",
|
|
92
|
+
"before:release": "bun run build"
|
|
93
|
+
},
|
|
94
|
+
"git": {
|
|
95
|
+
"commitMessage": "chore: release ${version}",
|
|
96
|
+
"tagName": "v${version}",
|
|
97
|
+
"requireCleanWorkingDir": false
|
|
98
|
+
},
|
|
99
|
+
"plugins": {
|
|
100
|
+
"@release-it/conventional-changelog": {
|
|
101
|
+
"preset": {
|
|
102
|
+
"name": "conventionalcommits",
|
|
103
|
+
"types": [
|
|
104
|
+
{
|
|
105
|
+
"type": "feat",
|
|
106
|
+
"section": "✨ Features"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"type": "fix",
|
|
110
|
+
"section": "🐞 Fixes"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"type": "chore(deps)",
|
|
114
|
+
"section": "🛠️ Dependency Upgrades"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"type": "perf",
|
|
118
|
+
"section": "🏎️ Performance Improvements"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "docs",
|
|
122
|
+
"section": "📚 Documentation"
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"react-native-builder-bob": {
|
|
130
|
+
"source": "src",
|
|
131
|
+
"output": "lib",
|
|
132
|
+
"targets": [
|
|
133
|
+
[
|
|
134
|
+
"module",
|
|
135
|
+
{
|
|
136
|
+
"esm": true
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"typescript"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LLM, type Message } from './llm'
|
|
2
|
+
export { ModelManager } from './modelManager'
|
|
3
|
+
export { MLXModel } from './models'
|
|
4
|
+
|
|
5
|
+
export type { GenerationStats, LLM as LLMSpec, LLMLoadOptions } from './specs/LLM.nitro'
|
|
6
|
+
export type { ModelManager as ModelManagerSpec } from './specs/ModelManager.nitro'
|
package/src/llm.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { GenerationStats, LLMLoadOptions, LLM as LLMSpec } from './specs/LLM.nitro'
|
|
3
|
+
|
|
4
|
+
let instance: LLMSpec | null = null
|
|
5
|
+
|
|
6
|
+
export type Message = {
|
|
7
|
+
role: 'user' | 'assistant' | 'system'
|
|
8
|
+
content: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getInstance(): LLMSpec {
|
|
12
|
+
if (!instance) {
|
|
13
|
+
instance = NitroModules.createHybridObject<LLMSpec>('LLM')
|
|
14
|
+
}
|
|
15
|
+
return instance
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* LLM text generation using MLX on Apple Silicon.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { LLM } from 'react-native-nitro-mlx'
|
|
24
|
+
*
|
|
25
|
+
* // Load a model
|
|
26
|
+
* await LLM.load('mlx-community/Qwen3-0.6B-4bit', progress => {
|
|
27
|
+
* console.log(`Loading: ${(progress * 100).toFixed(0)}%`)
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* // Stream a response
|
|
31
|
+
* await LLM.stream('Hello!', token => {
|
|
32
|
+
* process.stdout.write(token)
|
|
33
|
+
* })
|
|
34
|
+
*
|
|
35
|
+
* // Get generation stats
|
|
36
|
+
* const stats = LLM.getLastGenerationStats()
|
|
37
|
+
* console.log(`${stats.tokensPerSecond} tokens/sec`)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const LLM = {
|
|
41
|
+
/**
|
|
42
|
+
* Load a model into memory. Downloads the model from HuggingFace if not already cached.
|
|
43
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
44
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
45
|
+
*/
|
|
46
|
+
load(modelId: string, options: LLMLoadOptions): Promise<void> {
|
|
47
|
+
return getInstance().load(modelId, options)
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Generate a complete response for a prompt. Blocks until generation is complete.
|
|
52
|
+
* For streaming responses, use `stream()` instead.
|
|
53
|
+
* @param prompt - The input text to generate a response for
|
|
54
|
+
* @returns The complete generated text
|
|
55
|
+
*/
|
|
56
|
+
generate(prompt: string): Promise<string> {
|
|
57
|
+
return getInstance().generate(prompt)
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Stream a response token by token.
|
|
62
|
+
* @param prompt - The input text to generate a response for
|
|
63
|
+
* @param onToken - Callback invoked for each generated token
|
|
64
|
+
* @returns The complete generated text
|
|
65
|
+
*/
|
|
66
|
+
stream(prompt: string, onToken: (token: string) => void): Promise<string> {
|
|
67
|
+
return getInstance().stream(prompt, onToken)
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Stop the current generation. Safe to call even if not generating.
|
|
72
|
+
*/
|
|
73
|
+
stop(): void {
|
|
74
|
+
getInstance().stop()
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Unload the current model and release memory.
|
|
79
|
+
* Call this when you're done with the model to free up memory.
|
|
80
|
+
*/
|
|
81
|
+
unload(): void {
|
|
82
|
+
getInstance().unload()
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get statistics from the last generation.
|
|
87
|
+
* @returns Statistics including token count, tokens/sec, TTFT, and total time
|
|
88
|
+
*/
|
|
89
|
+
getLastGenerationStats(): GenerationStats {
|
|
90
|
+
return getInstance().getLastGenerationStats()
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the message history if management is enabled.
|
|
95
|
+
* @returns Array of messages in the history
|
|
96
|
+
*/
|
|
97
|
+
getHistory(): Message[] {
|
|
98
|
+
return getInstance().getHistory() as Message[]
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Clear the message history.
|
|
103
|
+
*/
|
|
104
|
+
clearHistory(): void {
|
|
105
|
+
getInstance().clearHistory()
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/** Whether a model is currently loaded and ready for generation */
|
|
109
|
+
get isLoaded(): boolean {
|
|
110
|
+
return getInstance().isLoaded
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/** Whether text is currently being generated */
|
|
114
|
+
get isGenerating(): boolean {
|
|
115
|
+
return getInstance().isGenerating
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/** The ID of the currently loaded model, or empty string if none */
|
|
119
|
+
get modelId(): string {
|
|
120
|
+
return getInstance().modelId
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/** Enable debug logging to console */
|
|
124
|
+
get debug(): boolean {
|
|
125
|
+
return getInstance().debug
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
set debug(value: boolean) {
|
|
129
|
+
getInstance().debug = value
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* System prompt used when loading the model.
|
|
134
|
+
* Set this before calling `load()`. Changes require reloading the model.
|
|
135
|
+
* @default "You are a helpful assistant."
|
|
136
|
+
*/
|
|
137
|
+
get systemPrompt(): string {
|
|
138
|
+
return getInstance().systemPrompt
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
set systemPrompt(value: string) {
|
|
142
|
+
getInstance().systemPrompt = value
|
|
143
|
+
},
|
|
144
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { ModelManager as ModelManagerSpec } from './specs/ModelManager.nitro'
|
|
3
|
+
|
|
4
|
+
let instance: ModelManagerSpec | null = null
|
|
5
|
+
|
|
6
|
+
function getInstance(): ModelManagerSpec {
|
|
7
|
+
if (!instance) {
|
|
8
|
+
instance = NitroModules.createHybridObject<ModelManagerSpec>('ModelManager')
|
|
9
|
+
}
|
|
10
|
+
return instance
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Manage MLX model downloads from HuggingFace.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { ModelManager } from 'react-native-nitro-mlx'
|
|
19
|
+
*
|
|
20
|
+
* // Download a model
|
|
21
|
+
* await ModelManager.download('mlx-community/Qwen3-0.6B-4bit', progress => {
|
|
22
|
+
* console.log(`Downloading: ${(progress * 100).toFixed(0)}%`)
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* // Check if downloaded
|
|
26
|
+
* const isReady = await ModelManager.isDownloaded('mlx-community/Qwen3-0.6B-4bit')
|
|
27
|
+
*
|
|
28
|
+
* // List all downloaded models
|
|
29
|
+
* const models = await ModelManager.getDownloadedModels()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const ModelManager = {
|
|
33
|
+
/**
|
|
34
|
+
* Download a model from HuggingFace.
|
|
35
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
36
|
+
* @param progressCallback - Callback invoked with download progress (0-1)
|
|
37
|
+
* @returns Path to the downloaded model directory
|
|
38
|
+
*/
|
|
39
|
+
download(
|
|
40
|
+
modelId: string,
|
|
41
|
+
progressCallback: (progress: number) => void,
|
|
42
|
+
): Promise<string> {
|
|
43
|
+
return getInstance().download(modelId, progressCallback)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Check if a model is already downloaded.
|
|
48
|
+
* @param modelId - HuggingFace model ID
|
|
49
|
+
* @returns True if the model is fully downloaded
|
|
50
|
+
*/
|
|
51
|
+
isDownloaded(modelId: string): Promise<boolean> {
|
|
52
|
+
return getInstance().isDownloaded(modelId)
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get a list of all downloaded model IDs.
|
|
57
|
+
* @returns Array of model IDs that are available locally
|
|
58
|
+
*/
|
|
59
|
+
getDownloadedModels(): Promise<string[]> {
|
|
60
|
+
return getInstance().getDownloadedModels()
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Delete a downloaded model to free up disk space.
|
|
65
|
+
* @param modelId - HuggingFace model ID
|
|
66
|
+
*/
|
|
67
|
+
deleteModel(modelId: string): Promise<void> {
|
|
68
|
+
return getInstance().deleteModel(modelId)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get the local filesystem path for a downloaded model.
|
|
73
|
+
* @param modelId - HuggingFace model ID
|
|
74
|
+
* @returns Absolute path to the model directory
|
|
75
|
+
*/
|
|
76
|
+
getModelPath(modelId: string): Promise<string> {
|
|
77
|
+
return getInstance().getModelPath(modelId)
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/** Enable debug logging to console */
|
|
81
|
+
get debug(): boolean {
|
|
82
|
+
return getInstance().debug
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
set debug(value: boolean) {
|
|
86
|
+
getInstance().debug = value
|
|
87
|
+
},
|
|
88
|
+
}
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export enum MLXModel {
|
|
2
|
+
// Llama 3.2 (Meta) - 1B and 3B variants
|
|
3
|
+
Llama_3_2_1B_Instruct_4bit = 'mlx-community/Llama-3.2-1B-Instruct-4bit',
|
|
4
|
+
Llama_3_2_1B_Instruct_8bit = 'mlx-community/Llama-3.2-1B-Instruct-8bit',
|
|
5
|
+
Llama_3_2_3B_Instruct_4bit = 'mlx-community/Llama-3.2-3B-Instruct-4bit',
|
|
6
|
+
Llama_3_2_3B_Instruct_8bit = 'mlx-community/Llama-3.2-3B-Instruct-8bit',
|
|
7
|
+
|
|
8
|
+
// Qwen 2.5 (Alibaba) - 0.5B, 1.5B, 3B variants
|
|
9
|
+
Qwen2_5_0_5B_Instruct_4bit = 'mlx-community/Qwen2.5-0.5B-Instruct-4bit',
|
|
10
|
+
Qwen2_5_0_5B_Instruct_8bit = 'mlx-community/Qwen2.5-0.5B-Instruct-8bit',
|
|
11
|
+
Qwen2_5_1_5B_Instruct_4bit = 'mlx-community/Qwen2.5-1.5B-Instruct-4bit',
|
|
12
|
+
Qwen2_5_1_5B_Instruct_8bit = 'mlx-community/Qwen2.5-1.5B-Instruct-8bit',
|
|
13
|
+
Qwen2_5_3B_Instruct_4bit = 'mlx-community/Qwen2.5-3B-Instruct-4bit',
|
|
14
|
+
Qwen2_5_3B_Instruct_8bit = 'mlx-community/Qwen2.5-3B-Instruct-8bit',
|
|
15
|
+
|
|
16
|
+
// Qwen 3 - 1.7B variant
|
|
17
|
+
Qwen3_1_7B_4bit = 'mlx-community/Qwen3-1.7B-4bit',
|
|
18
|
+
Qwen3_1_7B_8bit = 'mlx-community/Qwen3-1.7B-8bit',
|
|
19
|
+
|
|
20
|
+
// Gemma 3 (Google) - 1B variant
|
|
21
|
+
Gemma_3_1B_IT_4bit = 'mlx-community/gemma-3-1b-it-4bit',
|
|
22
|
+
Gemma_3_1B_IT_8bit = 'mlx-community/gemma-3-1b-it-8bit',
|
|
23
|
+
|
|
24
|
+
// Phi 3.5 Mini (Microsoft) - ~3.8B but runs well on mobile
|
|
25
|
+
Phi_3_5_Mini_Instruct_4bit = 'mlx-community/Phi-3.5-mini-instruct-4bit',
|
|
26
|
+
Phi_3_5_Mini_Instruct_8bit = 'mlx-community/Phi-3.5-mini-instruct-8bit',
|
|
27
|
+
|
|
28
|
+
// Phi 4 Mini (Microsoft)
|
|
29
|
+
Phi_4_Mini_Instruct_4bit = 'mlx-community/Phi-4-mini-instruct-4bit',
|
|
30
|
+
Phi_4_Mini_Instruct_8bit = 'mlx-community/Phi-4-mini-instruct-8bit',
|
|
31
|
+
|
|
32
|
+
// SmolLM (HuggingFace) - 1.7B
|
|
33
|
+
SmolLM_1_7B_Instruct_4bit = 'mlx-community/SmolLM-1.7B-Instruct-4bit',
|
|
34
|
+
SmolLM_1_7B_Instruct_8bit = 'mlx-community/SmolLM-1.7B-Instruct-8bit',
|
|
35
|
+
|
|
36
|
+
// SmolLM2 (HuggingFace) - 1.7B
|
|
37
|
+
SmolLM2_1_7B_Instruct_4bit = 'mlx-community/SmolLM2-1.7B-Instruct-4bit',
|
|
38
|
+
SmolLM2_1_7B_Instruct_8bit = 'mlx-community/SmolLM2-1.7B-Instruct-8bit',
|
|
39
|
+
|
|
40
|
+
// OpenELM (Apple) - 1.1B and 3B
|
|
41
|
+
OpenELM_1_1B_4bit = 'mlx-community/OpenELM-1_1B-4bit',
|
|
42
|
+
OpenELM_1_1B_8bit = 'mlx-community/OpenELM-1_1B-8bit',
|
|
43
|
+
OpenELM_3B_4bit = 'mlx-community/OpenELM-3B-4bit',
|
|
44
|
+
OpenELM_3B_8bit = 'mlx-community/OpenELM-3B-8bit',
|
|
45
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Statistics from the last text generation.
|
|
5
|
+
*/
|
|
6
|
+
export interface GenerationStats {
|
|
7
|
+
/** Total number of tokens generated */
|
|
8
|
+
tokenCount: number
|
|
9
|
+
/** Generation speed in tokens per second */
|
|
10
|
+
tokensPerSecond: number
|
|
11
|
+
/** Time in milliseconds until the first token was generated */
|
|
12
|
+
timeToFirstToken: number
|
|
13
|
+
/** Total generation time in milliseconds */
|
|
14
|
+
totalTime: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LLMMessage {
|
|
18
|
+
role: string
|
|
19
|
+
content: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Options for loading a model.
|
|
23
|
+
*/
|
|
24
|
+
export interface LLMLoadOptions {
|
|
25
|
+
/** Callback invoked with loading progress (0-1) */
|
|
26
|
+
onProgress?: (progress: number) => void
|
|
27
|
+
/** Additional context to provide to the model */
|
|
28
|
+
additionalContext?: LLMMessage[]
|
|
29
|
+
/** Whether to automatically manage message history */
|
|
30
|
+
manageHistory?: boolean
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Low-level LLM interface for text generation using MLX.
|
|
35
|
+
* @internal Use the `LLM` export from `react-native-nitro-mlx` instead.
|
|
36
|
+
*/
|
|
37
|
+
export interface LLM extends HybridObject<{ ios: 'swift' }> {
|
|
38
|
+
/**
|
|
39
|
+
* Load a model into memory. Downloads from HuggingFace if not already cached.
|
|
40
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
41
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
42
|
+
*/
|
|
43
|
+
load(modelId: string, options?: LLMLoadOptions): Promise<void>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate a complete response for a prompt.
|
|
47
|
+
* @param prompt - The input text to generate a response for
|
|
48
|
+
* @returns The generated text
|
|
49
|
+
*/
|
|
50
|
+
generate(prompt: string): Promise<string>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Stream a response token by token.
|
|
54
|
+
* @param prompt - The input text to generate a response for
|
|
55
|
+
* @param onToken - Callback invoked for each generated token
|
|
56
|
+
* @returns The complete generated text
|
|
57
|
+
*/
|
|
58
|
+
stream(prompt: string, onToken: (token: string) => void): Promise<string>
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Stop the current generation.
|
|
62
|
+
*/
|
|
63
|
+
stop(): void
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Unload the current model and release memory.
|
|
67
|
+
*/
|
|
68
|
+
unload(): void
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get statistics from the last generation.
|
|
72
|
+
* @returns Statistics including token count, speed, and timing
|
|
73
|
+
*/
|
|
74
|
+
getLastGenerationStats(): GenerationStats
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the message history if management is enabled.
|
|
78
|
+
* @returns Array of messages in the history
|
|
79
|
+
*/
|
|
80
|
+
getHistory(): LLMMessage[]
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Clear the message history.
|
|
84
|
+
*/
|
|
85
|
+
clearHistory(): void
|
|
86
|
+
|
|
87
|
+
/** Whether a model is currently loaded */
|
|
88
|
+
readonly isLoaded: boolean
|
|
89
|
+
/** Whether text is currently being generated */
|
|
90
|
+
readonly isGenerating: boolean
|
|
91
|
+
/** The ID of the currently loaded model */
|
|
92
|
+
readonly modelId: string
|
|
93
|
+
|
|
94
|
+
/** Enable debug logging */
|
|
95
|
+
debug: boolean
|
|
96
|
+
/** System prompt used when loading the model */
|
|
97
|
+
systemPrompt: string
|
|
98
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Low-level interface for managing MLX model downloads.
|
|
5
|
+
* @internal Use the `ModelManager` export from `react-native-nitro-mlx` instead.
|
|
6
|
+
*/
|
|
7
|
+
export interface ModelManager extends HybridObject<{ ios: 'swift' }> {
|
|
8
|
+
/**
|
|
9
|
+
* Download a model from HuggingFace.
|
|
10
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
11
|
+
* @param progressCallback - Callback invoked with download progress (0-1)
|
|
12
|
+
* @returns Path to the downloaded model directory
|
|
13
|
+
*/
|
|
14
|
+
download(modelId: string, progressCallback: (progress: number) => void): Promise<string>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check if a model is already downloaded.
|
|
18
|
+
* @param modelId - HuggingFace model ID
|
|
19
|
+
* @returns True if the model is downloaded
|
|
20
|
+
*/
|
|
21
|
+
isDownloaded(modelId: string): Promise<boolean>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get a list of all downloaded model IDs.
|
|
25
|
+
* @returns Array of downloaded model IDs
|
|
26
|
+
*/
|
|
27
|
+
getDownloadedModels(): Promise<string[]>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Delete a downloaded model.
|
|
31
|
+
* @param modelId - HuggingFace model ID
|
|
32
|
+
*/
|
|
33
|
+
deleteModel(modelId: string): Promise<void>
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the local filesystem path for a downloaded model.
|
|
37
|
+
* @param modelId - HuggingFace model ID
|
|
38
|
+
* @returns Path to the model directory
|
|
39
|
+
*/
|
|
40
|
+
getModelPath(modelId: string): Promise<string>
|
|
41
|
+
|
|
42
|
+
/** Enable debug logging */
|
|
43
|
+
debug: boolean
|
|
44
|
+
}
|