react-native-nitro-mlx 0.1.1 → 0.2.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/ios/Sources/HybridLLM.swift +115 -5
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/llm.js +23 -3
- package/lib/module/llm.js.map +1 -1
- package/lib/module/models.js +227 -0
- package/lib/module/models.js.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/llm.d.ts +21 -3
- package/lib/typescript/src/llm.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts +27 -0
- package/lib/typescript/src/models.d.ts.map +1 -1
- package/lib/typescript/src/specs/LLM.nitro.d.ts +29 -2
- package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +87 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +7 -0
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +30 -2
- package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +4 -1
- package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +42 -7
- package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +138 -0
- package/nitrogen/generated/ios/swift/LLMMessage.swift +47 -0
- package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +3 -0
- package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +12 -1
- package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +87 -0
- package/nitrogen/generated/shared/c++/LLMMessage.hpp +79 -0
- package/package.json +1 -9
- package/src/index.ts +10 -3
- package/src/llm.ts +32 -4
- package/src/models.ts +267 -0
- package/src/specs/LLM.nitro.ts +34 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// LLMLoadOptions.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
// Forward declaration of `LLMMessage` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
|
|
28
|
+
|
|
29
|
+
#include <functional>
|
|
30
|
+
#include <optional>
|
|
31
|
+
#include "LLMMessage.hpp"
|
|
32
|
+
#include <vector>
|
|
33
|
+
|
|
34
|
+
namespace margelo::nitro::mlxreactnative {
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A struct which can be represented as a JavaScript object (LLMLoadOptions).
|
|
38
|
+
*/
|
|
39
|
+
struct LLMLoadOptions {
|
|
40
|
+
public:
|
|
41
|
+
std::optional<std::function<void(double /* progress */)>> onProgress SWIFT_PRIVATE;
|
|
42
|
+
std::optional<std::vector<LLMMessage>> additionalContext SWIFT_PRIVATE;
|
|
43
|
+
std::optional<bool> manageHistory SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
LLMLoadOptions() = default;
|
|
47
|
+
explicit LLMLoadOptions(std::optional<std::function<void(double /* progress */)>> onProgress, std::optional<std::vector<LLMMessage>> additionalContext, std::optional<bool> manageHistory): onProgress(onProgress), additionalContext(additionalContext), manageHistory(manageHistory) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
51
|
+
|
|
52
|
+
namespace margelo::nitro {
|
|
53
|
+
|
|
54
|
+
// C++ LLMLoadOptions <> JS LLMLoadOptions (object)
|
|
55
|
+
template <>
|
|
56
|
+
struct JSIConverter<margelo::nitro::mlxreactnative::LLMLoadOptions> final {
|
|
57
|
+
static inline margelo::nitro::mlxreactnative::LLMLoadOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
58
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
59
|
+
return margelo::nitro::mlxreactnative::LLMLoadOptions(
|
|
60
|
+
JSIConverter<std::optional<std::function<void(double)>>>::fromJSI(runtime, obj.getProperty(runtime, "onProgress")),
|
|
61
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::fromJSI(runtime, obj.getProperty(runtime, "additionalContext")),
|
|
62
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "manageHistory"))
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::LLMLoadOptions& arg) {
|
|
66
|
+
jsi::Object obj(runtime);
|
|
67
|
+
obj.setProperty(runtime, "onProgress", JSIConverter<std::optional<std::function<void(double)>>>::toJSI(runtime, arg.onProgress));
|
|
68
|
+
obj.setProperty(runtime, "additionalContext", JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::toJSI(runtime, arg.additionalContext));
|
|
69
|
+
obj.setProperty(runtime, "manageHistory", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.manageHistory));
|
|
70
|
+
return obj;
|
|
71
|
+
}
|
|
72
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
73
|
+
if (!value.isObject()) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
jsi::Object obj = value.getObject(runtime);
|
|
77
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (!JSIConverter<std::optional<std::function<void(double)>>>::canConvert(runtime, obj.getProperty(runtime, "onProgress"))) return false;
|
|
81
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::canConvert(runtime, obj.getProperty(runtime, "additionalContext"))) return false;
|
|
82
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "manageHistory"))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// LLMMessage.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <string>
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::mlxreactnative {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A struct which can be represented as a JavaScript object (LLMMessage).
|
|
34
|
+
*/
|
|
35
|
+
struct LLMMessage {
|
|
36
|
+
public:
|
|
37
|
+
std::string role SWIFT_PRIVATE;
|
|
38
|
+
std::string content SWIFT_PRIVATE;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
LLMMessage() = default;
|
|
42
|
+
explicit LLMMessage(std::string role, std::string content): role(role), content(content) {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
46
|
+
|
|
47
|
+
namespace margelo::nitro {
|
|
48
|
+
|
|
49
|
+
// C++ LLMMessage <> JS LLMMessage (object)
|
|
50
|
+
template <>
|
|
51
|
+
struct JSIConverter<margelo::nitro::mlxreactnative::LLMMessage> final {
|
|
52
|
+
static inline margelo::nitro::mlxreactnative::LLMMessage fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
+
return margelo::nitro::mlxreactnative::LLMMessage(
|
|
55
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "role")),
|
|
56
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "content"))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::LLMMessage& arg) {
|
|
60
|
+
jsi::Object obj(runtime);
|
|
61
|
+
obj.setProperty(runtime, "role", JSIConverter<std::string>::toJSI(runtime, arg.role));
|
|
62
|
+
obj.setProperty(runtime, "content", JSIConverter<std::string>::toJSI(runtime, arg.content));
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
66
|
+
if (!value.isObject()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
jsi::Object obj = value.getObject(runtime);
|
|
70
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "role"))) return false;
|
|
74
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "content"))) return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-mlx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Nitro module package",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -89,14 +89,6 @@
|
|
|
89
89
|
"requireCleanWorkingDir": false
|
|
90
90
|
},
|
|
91
91
|
"plugins": {
|
|
92
|
-
"@release-it/bumper": {
|
|
93
|
-
"out": [
|
|
94
|
-
{
|
|
95
|
-
"file": "package.json",
|
|
96
|
-
"path": "version"
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
},
|
|
100
92
|
"@release-it/conventional-changelog": {
|
|
101
93
|
"preset": {
|
|
102
94
|
"name": "conventionalcommits",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
export { LLM } from './llm'
|
|
1
|
+
export { LLM, type Message } from './llm'
|
|
2
2
|
export { ModelManager } from './modelManager'
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
MLXModel,
|
|
5
|
+
MLXModels,
|
|
6
|
+
ModelFamily,
|
|
7
|
+
type ModelInfo,
|
|
8
|
+
ModelProvider,
|
|
9
|
+
type ModelQuantization,
|
|
10
|
+
} from './models'
|
|
4
11
|
|
|
5
|
-
export type { GenerationStats, LLM as LLMSpec } from './specs/LLM.nitro'
|
|
12
|
+
export type { GenerationStats, LLM as LLMSpec, LLMLoadOptions } from './specs/LLM.nitro'
|
|
6
13
|
export type { ModelManager as ModelManagerSpec } from './specs/ModelManager.nitro'
|
package/src/llm.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
-
import type { GenerationStats, LLM as LLMSpec } from './specs/LLM.nitro'
|
|
2
|
+
import type { GenerationStats, LLMLoadOptions, LLM as LLMSpec } from './specs/LLM.nitro'
|
|
3
3
|
|
|
4
4
|
let instance: LLMSpec | null = null
|
|
5
5
|
|
|
6
|
+
export type Message = {
|
|
7
|
+
role: 'user' | 'assistant' | 'system'
|
|
8
|
+
content: string
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
function getInstance(): LLMSpec {
|
|
7
12
|
if (!instance) {
|
|
8
13
|
instance = NitroModules.createHybridObject<LLMSpec>('LLM')
|
|
@@ -36,10 +41,10 @@ export const LLM = {
|
|
|
36
41
|
/**
|
|
37
42
|
* Load a model into memory. Downloads the model from HuggingFace if not already cached.
|
|
38
43
|
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
39
|
-
* @param
|
|
44
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
40
45
|
*/
|
|
41
|
-
load(modelId: string,
|
|
42
|
-
return getInstance().load(modelId,
|
|
46
|
+
load(modelId: string, options: LLMLoadOptions): Promise<void> {
|
|
47
|
+
return getInstance().load(modelId, options)
|
|
43
48
|
},
|
|
44
49
|
|
|
45
50
|
/**
|
|
@@ -69,6 +74,14 @@ export const LLM = {
|
|
|
69
74
|
getInstance().stop()
|
|
70
75
|
},
|
|
71
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
|
+
|
|
72
85
|
/**
|
|
73
86
|
* Get statistics from the last generation.
|
|
74
87
|
* @returns Statistics including token count, tokens/sec, TTFT, and total time
|
|
@@ -77,6 +90,21 @@ export const LLM = {
|
|
|
77
90
|
return getInstance().getLastGenerationStats()
|
|
78
91
|
},
|
|
79
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
|
+
|
|
80
108
|
/** Whether a model is currently loaded and ready for generation */
|
|
81
109
|
get isLoaded(): boolean {
|
|
82
110
|
return getInstance().isLoaded
|
package/src/models.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
export enum ModelFamily {
|
|
2
|
+
Llama = 'Llama',
|
|
3
|
+
Qwen = 'Qwen',
|
|
4
|
+
Gemma = 'Gemma',
|
|
5
|
+
Phi = 'Phi',
|
|
6
|
+
SmolLM = 'SmolLM',
|
|
7
|
+
OpenELM = 'OpenELM',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum ModelProvider {
|
|
11
|
+
Meta = 'Meta',
|
|
12
|
+
Alibaba = 'Alibaba',
|
|
13
|
+
Google = 'Google',
|
|
14
|
+
Microsoft = 'Microsoft',
|
|
15
|
+
HuggingFace = 'HuggingFace',
|
|
16
|
+
Apple = 'Apple',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ModelQuantization = '4bit' | '8bit'
|
|
20
|
+
|
|
21
|
+
export interface ModelInfo {
|
|
22
|
+
id: MLXModel
|
|
23
|
+
family: ModelFamily
|
|
24
|
+
provider: ModelProvider
|
|
25
|
+
parameters: string
|
|
26
|
+
quantization: ModelQuantization
|
|
27
|
+
displayName: string
|
|
28
|
+
downloadSize: number
|
|
29
|
+
}
|
|
30
|
+
|
|
1
31
|
export enum MLXModel {
|
|
2
32
|
// Llama 3.2 (Meta) - 1B and 3B variants
|
|
3
33
|
Llama_3_2_1B_Instruct_4bit = 'mlx-community/Llama-3.2-1B-Instruct-4bit',
|
|
@@ -43,3 +73,240 @@ export enum MLXModel {
|
|
|
43
73
|
OpenELM_3B_4bit = 'mlx-community/OpenELM-3B-4bit',
|
|
44
74
|
OpenELM_3B_8bit = 'mlx-community/OpenELM-3B-8bit',
|
|
45
75
|
}
|
|
76
|
+
|
|
77
|
+
export const MLXModels: ModelInfo[] = [
|
|
78
|
+
{
|
|
79
|
+
id: MLXModel.Llama_3_2_1B_Instruct_4bit,
|
|
80
|
+
family: ModelFamily.Llama,
|
|
81
|
+
provider: ModelProvider.Meta,
|
|
82
|
+
parameters: '1B',
|
|
83
|
+
quantization: '4bit',
|
|
84
|
+
displayName: 'Llama 3.2 1B Instruct (4-bit)',
|
|
85
|
+
downloadSize: 1407777762,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: MLXModel.Llama_3_2_1B_Instruct_8bit,
|
|
89
|
+
family: ModelFamily.Llama,
|
|
90
|
+
provider: ModelProvider.Meta,
|
|
91
|
+
parameters: '1B',
|
|
92
|
+
quantization: '8bit',
|
|
93
|
+
displayName: 'Llama 3.2 1B Instruct (8-bit)',
|
|
94
|
+
downloadSize: 1313157436,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: MLXModel.Llama_3_2_3B_Instruct_4bit,
|
|
98
|
+
family: ModelFamily.Llama,
|
|
99
|
+
provider: ModelProvider.Meta,
|
|
100
|
+
parameters: '3B',
|
|
101
|
+
quantization: '4bit',
|
|
102
|
+
displayName: 'Llama 3.2 3B Instruct (4-bit)',
|
|
103
|
+
downloadSize: 2019397474,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: MLXModel.Llama_3_2_3B_Instruct_8bit,
|
|
107
|
+
family: ModelFamily.Llama,
|
|
108
|
+
provider: ModelProvider.Meta,
|
|
109
|
+
parameters: '3B',
|
|
110
|
+
quantization: '8bit',
|
|
111
|
+
displayName: 'Llama 3.2 3B Instruct (8-bit)',
|
|
112
|
+
downloadSize: 3413784042,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: MLXModel.Qwen2_5_0_5B_Instruct_4bit,
|
|
116
|
+
family: ModelFamily.Qwen,
|
|
117
|
+
provider: ModelProvider.Alibaba,
|
|
118
|
+
parameters: '0.5B',
|
|
119
|
+
quantization: '4bit',
|
|
120
|
+
displayName: 'Qwen 2.5 0.5B Instruct (4-bit)',
|
|
121
|
+
downloadSize: 278064920,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: MLXModel.Qwen2_5_0_5B_Instruct_8bit,
|
|
125
|
+
family: ModelFamily.Qwen,
|
|
126
|
+
provider: ModelProvider.Alibaba,
|
|
127
|
+
parameters: '0.5B',
|
|
128
|
+
quantization: '8bit',
|
|
129
|
+
displayName: 'Qwen 2.5 0.5B Instruct (8-bit)',
|
|
130
|
+
downloadSize: 525045902,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: MLXModel.Qwen2_5_1_5B_Instruct_4bit,
|
|
134
|
+
family: ModelFamily.Qwen,
|
|
135
|
+
provider: ModelProvider.Alibaba,
|
|
136
|
+
parameters: '1.5B',
|
|
137
|
+
quantization: '4bit',
|
|
138
|
+
displayName: 'Qwen 2.5 1.5B Instruct (4-bit)',
|
|
139
|
+
downloadSize: 868628559,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: MLXModel.Qwen2_5_1_5B_Instruct_8bit,
|
|
143
|
+
family: ModelFamily.Qwen,
|
|
144
|
+
provider: ModelProvider.Alibaba,
|
|
145
|
+
parameters: '1.5B',
|
|
146
|
+
quantization: '8bit',
|
|
147
|
+
displayName: 'Qwen 2.5 1.5B Instruct (8-bit)',
|
|
148
|
+
downloadSize: 1640414038,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: MLXModel.Qwen2_5_3B_Instruct_4bit,
|
|
152
|
+
family: ModelFamily.Qwen,
|
|
153
|
+
provider: ModelProvider.Alibaba,
|
|
154
|
+
parameters: '3B',
|
|
155
|
+
quantization: '4bit',
|
|
156
|
+
displayName: 'Qwen 2.5 3B Instruct (4-bit)',
|
|
157
|
+
downloadSize: 1736293090,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: MLXModel.Qwen2_5_3B_Instruct_8bit,
|
|
161
|
+
family: ModelFamily.Qwen,
|
|
162
|
+
provider: ModelProvider.Alibaba,
|
|
163
|
+
parameters: '3B',
|
|
164
|
+
quantization: '8bit',
|
|
165
|
+
displayName: 'Qwen 2.5 3B Instruct (8-bit)',
|
|
166
|
+
downloadSize: 3279142142,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: MLXModel.Qwen3_1_7B_4bit,
|
|
170
|
+
family: ModelFamily.Qwen,
|
|
171
|
+
provider: ModelProvider.Alibaba,
|
|
172
|
+
parameters: '1.7B',
|
|
173
|
+
quantization: '4bit',
|
|
174
|
+
displayName: 'Qwen 3 1.7B (4-bit)',
|
|
175
|
+
downloadSize: 979502864,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: MLXModel.Qwen3_1_7B_8bit,
|
|
179
|
+
family: ModelFamily.Qwen,
|
|
180
|
+
provider: ModelProvider.Alibaba,
|
|
181
|
+
parameters: '1.7B',
|
|
182
|
+
quantization: '8bit',
|
|
183
|
+
displayName: 'Qwen 3 1.7B (8-bit)',
|
|
184
|
+
downloadSize: 1839729195,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: MLXModel.Gemma_3_1B_IT_4bit,
|
|
188
|
+
family: ModelFamily.Gemma,
|
|
189
|
+
provider: ModelProvider.Google,
|
|
190
|
+
parameters: '1B',
|
|
191
|
+
quantization: '4bit',
|
|
192
|
+
displayName: 'Gemma 3 1B IT (4-bit)',
|
|
193
|
+
downloadSize: 770650946,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: MLXModel.Gemma_3_1B_IT_8bit,
|
|
197
|
+
family: ModelFamily.Gemma,
|
|
198
|
+
provider: ModelProvider.Google,
|
|
199
|
+
parameters: '1B',
|
|
200
|
+
quantization: '8bit',
|
|
201
|
+
displayName: 'Gemma 3 1B IT (8-bit)',
|
|
202
|
+
downloadSize: 1421522471,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: MLXModel.Phi_3_5_Mini_Instruct_4bit,
|
|
206
|
+
family: ModelFamily.Phi,
|
|
207
|
+
provider: ModelProvider.Microsoft,
|
|
208
|
+
parameters: '3.8B',
|
|
209
|
+
quantization: '4bit',
|
|
210
|
+
displayName: 'Phi 3.5 Mini Instruct (4-bit)',
|
|
211
|
+
downloadSize: 2150195856,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: MLXModel.Phi_3_5_Mini_Instruct_8bit,
|
|
215
|
+
family: ModelFamily.Phi,
|
|
216
|
+
provider: ModelProvider.Microsoft,
|
|
217
|
+
parameters: '3.8B',
|
|
218
|
+
quantization: '8bit',
|
|
219
|
+
displayName: 'Phi 3.5 Mini Instruct (8-bit)',
|
|
220
|
+
downloadSize: 4060636056,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: MLXModel.Phi_4_Mini_Instruct_4bit,
|
|
224
|
+
family: ModelFamily.Phi,
|
|
225
|
+
provider: ModelProvider.Microsoft,
|
|
226
|
+
parameters: '3.8B',
|
|
227
|
+
quantization: '4bit',
|
|
228
|
+
displayName: 'Phi 4 Mini Instruct (4-bit)',
|
|
229
|
+
downloadSize: 2173624891,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: MLXModel.Phi_4_Mini_Instruct_8bit,
|
|
233
|
+
family: ModelFamily.Phi,
|
|
234
|
+
provider: ModelProvider.Microsoft,
|
|
235
|
+
parameters: '3.8B',
|
|
236
|
+
quantization: '8bit',
|
|
237
|
+
displayName: 'Phi 4 Mini Instruct (8-bit)',
|
|
238
|
+
downloadSize: 4091536167,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: MLXModel.SmolLM_1_7B_Instruct_4bit,
|
|
242
|
+
family: ModelFamily.SmolLM,
|
|
243
|
+
provider: ModelProvider.HuggingFace,
|
|
244
|
+
parameters: '1.7B',
|
|
245
|
+
quantization: '4bit',
|
|
246
|
+
displayName: 'SmolLM 1.7B Instruct (4-bit)',
|
|
247
|
+
downloadSize: 962855374,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: MLXModel.SmolLM_1_7B_Instruct_8bit,
|
|
251
|
+
family: ModelFamily.SmolLM,
|
|
252
|
+
provider: ModelProvider.HuggingFace,
|
|
253
|
+
parameters: '1.7B',
|
|
254
|
+
quantization: '8bit',
|
|
255
|
+
displayName: 'SmolLM 1.7B Instruct (8-bit)',
|
|
256
|
+
downloadSize: 1818493993,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: MLXModel.SmolLM2_1_7B_Instruct_4bit,
|
|
260
|
+
family: ModelFamily.SmolLM,
|
|
261
|
+
provider: ModelProvider.HuggingFace,
|
|
262
|
+
parameters: '1.7B',
|
|
263
|
+
quantization: '4bit',
|
|
264
|
+
displayName: 'SmolLM2 1.7B Instruct (4-bit)',
|
|
265
|
+
downloadSize: 980000000,
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: MLXModel.SmolLM2_1_7B_Instruct_8bit,
|
|
269
|
+
family: ModelFamily.SmolLM,
|
|
270
|
+
provider: ModelProvider.HuggingFace,
|
|
271
|
+
parameters: '1.7B',
|
|
272
|
+
quantization: '8bit',
|
|
273
|
+
displayName: 'SmolLM2 1.7B Instruct (8-bit)',
|
|
274
|
+
downloadSize: 1850000000,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
id: MLXModel.OpenELM_1_1B_4bit,
|
|
278
|
+
family: ModelFamily.OpenELM,
|
|
279
|
+
provider: ModelProvider.Apple,
|
|
280
|
+
parameters: '1.1B',
|
|
281
|
+
quantization: '4bit',
|
|
282
|
+
displayName: 'OpenELM 1.1B (4-bit)',
|
|
283
|
+
downloadSize: 608162655,
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
id: MLXModel.OpenELM_1_1B_8bit,
|
|
287
|
+
family: ModelFamily.OpenELM,
|
|
288
|
+
provider: ModelProvider.Apple,
|
|
289
|
+
parameters: '1.1B',
|
|
290
|
+
quantization: '8bit',
|
|
291
|
+
displayName: 'OpenELM 1.1B (8-bit)',
|
|
292
|
+
downloadSize: 1148048397,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: MLXModel.OpenELM_3B_4bit,
|
|
296
|
+
family: ModelFamily.OpenELM,
|
|
297
|
+
provider: ModelProvider.Apple,
|
|
298
|
+
parameters: '3B',
|
|
299
|
+
quantization: '4bit',
|
|
300
|
+
displayName: 'OpenELM 3B (4-bit)',
|
|
301
|
+
downloadSize: 1650000000,
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
id: MLXModel.OpenELM_3B_8bit,
|
|
305
|
+
family: ModelFamily.OpenELM,
|
|
306
|
+
provider: ModelProvider.Apple,
|
|
307
|
+
parameters: '3B',
|
|
308
|
+
quantization: '8bit',
|
|
309
|
+
displayName: 'OpenELM 3B (8-bit)',
|
|
310
|
+
downloadSize: 3100000000,
|
|
311
|
+
},
|
|
312
|
+
]
|
package/src/specs/LLM.nitro.ts
CHANGED
|
@@ -14,6 +14,22 @@ export interface GenerationStats {
|
|
|
14
14
|
totalTime: number
|
|
15
15
|
}
|
|
16
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
|
+
|
|
17
33
|
/**
|
|
18
34
|
* Low-level LLM interface for text generation using MLX.
|
|
19
35
|
* @internal Use the `LLM` export from `react-native-nitro-mlx` instead.
|
|
@@ -22,9 +38,9 @@ export interface LLM extends HybridObject<{ ios: 'swift' }> {
|
|
|
22
38
|
/**
|
|
23
39
|
* Load a model into memory. Downloads from HuggingFace if not already cached.
|
|
24
40
|
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
25
|
-
* @param
|
|
41
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
26
42
|
*/
|
|
27
|
-
load(modelId: string,
|
|
43
|
+
load(modelId: string, options?: LLMLoadOptions): Promise<void>
|
|
28
44
|
|
|
29
45
|
/**
|
|
30
46
|
* Generate a complete response for a prompt.
|
|
@@ -46,12 +62,28 @@ export interface LLM extends HybridObject<{ ios: 'swift' }> {
|
|
|
46
62
|
*/
|
|
47
63
|
stop(): void
|
|
48
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Unload the current model and release memory.
|
|
67
|
+
*/
|
|
68
|
+
unload(): void
|
|
69
|
+
|
|
49
70
|
/**
|
|
50
71
|
* Get statistics from the last generation.
|
|
51
72
|
* @returns Statistics including token count, speed, and timing
|
|
52
73
|
*/
|
|
53
74
|
getLastGenerationStats(): GenerationStats
|
|
54
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
|
+
|
|
55
87
|
/** Whether a model is currently loaded */
|
|
56
88
|
readonly isLoaded: boolean
|
|
57
89
|
/** Whether text is currently being generated */
|