@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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
let instance = null;
|
|
5
|
+
function getInstance() {
|
|
6
|
+
if (!instance) {
|
|
7
|
+
instance = NitroModules.createHybridObject('ModelManager');
|
|
8
|
+
}
|
|
9
|
+
return instance;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Manage MLX model downloads from HuggingFace.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { ModelManager } from 'react-native-nitro-mlx'
|
|
18
|
+
*
|
|
19
|
+
* // Download a model
|
|
20
|
+
* await ModelManager.download('mlx-community/Qwen3-0.6B-4bit', progress => {
|
|
21
|
+
* console.log(`Downloading: ${(progress * 100).toFixed(0)}%`)
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // Check if downloaded
|
|
25
|
+
* const isReady = await ModelManager.isDownloaded('mlx-community/Qwen3-0.6B-4bit')
|
|
26
|
+
*
|
|
27
|
+
* // List all downloaded models
|
|
28
|
+
* const models = await ModelManager.getDownloadedModels()
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const ModelManager = {
|
|
32
|
+
/**
|
|
33
|
+
* Download a model from HuggingFace.
|
|
34
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
35
|
+
* @param progressCallback - Callback invoked with download progress (0-1)
|
|
36
|
+
* @returns Path to the downloaded model directory
|
|
37
|
+
*/
|
|
38
|
+
download(modelId, progressCallback) {
|
|
39
|
+
return getInstance().download(modelId, progressCallback);
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Check if a model is already downloaded.
|
|
43
|
+
* @param modelId - HuggingFace model ID
|
|
44
|
+
* @returns True if the model is fully downloaded
|
|
45
|
+
*/
|
|
46
|
+
isDownloaded(modelId) {
|
|
47
|
+
return getInstance().isDownloaded(modelId);
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Get a list of all downloaded model IDs.
|
|
51
|
+
* @returns Array of model IDs that are available locally
|
|
52
|
+
*/
|
|
53
|
+
getDownloadedModels() {
|
|
54
|
+
return getInstance().getDownloadedModels();
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Delete a downloaded model to free up disk space.
|
|
58
|
+
* @param modelId - HuggingFace model ID
|
|
59
|
+
*/
|
|
60
|
+
deleteModel(modelId) {
|
|
61
|
+
return getInstance().deleteModel(modelId);
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Get the local filesystem path for a downloaded model.
|
|
65
|
+
* @param modelId - HuggingFace model ID
|
|
66
|
+
* @returns Absolute path to the model directory
|
|
67
|
+
*/
|
|
68
|
+
getModelPath(modelId) {
|
|
69
|
+
return getInstance().getModelPath(modelId);
|
|
70
|
+
},
|
|
71
|
+
/** Enable debug logging to console */
|
|
72
|
+
get debug() {
|
|
73
|
+
return getInstance().debug;
|
|
74
|
+
},
|
|
75
|
+
set debug(value) {
|
|
76
|
+
getInstance().debug = value;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=modelManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","instance","getInstance","createHybridObject","ModelManager","download","modelId","progressCallback","isDownloaded","getDownloadedModels","deleteModel","getModelPath","debug","value"],"sourceRoot":"../../src","sources":["modelManager.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,IAAIC,QAAiC,GAAG,IAAI;AAE5C,SAASC,WAAWA,CAAA,EAAqB;EACvC,IAAI,CAACD,QAAQ,EAAE;IACbA,QAAQ,GAAGD,YAAY,CAACG,kBAAkB,CAAmB,cAAc,CAAC;EAC9E;EACA,OAAOF,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,YAAY,GAAG;EAC1B;AACF;AACA;AACA;AACA;AACA;EACEC,QAAQA,CACNC,OAAe,EACfC,gBAA4C,EAC3B;IACjB,OAAOL,WAAW,CAAC,CAAC,CAACG,QAAQ,CAACC,OAAO,EAAEC,gBAAgB,CAAC;EAC1D,CAAC;EAED;AACF;AACA;AACA;AACA;EACEC,YAAYA,CAACF,OAAe,EAAoB;IAC9C,OAAOJ,WAAW,CAAC,CAAC,CAACM,YAAY,CAACF,OAAO,CAAC;EAC5C,CAAC;EAED;AACF;AACA;AACA;EACEG,mBAAmBA,CAAA,EAAsB;IACvC,OAAOP,WAAW,CAAC,CAAC,CAACO,mBAAmB,CAAC,CAAC;EAC5C,CAAC;EAED;AACF;AACA;AACA;EACEC,WAAWA,CAACJ,OAAe,EAAiB;IAC1C,OAAOJ,WAAW,CAAC,CAAC,CAACQ,WAAW,CAACJ,OAAO,CAAC;EAC3C,CAAC;EAED;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACL,OAAe,EAAmB;IAC7C,OAAOJ,WAAW,CAAC,CAAC,CAACS,YAAY,CAACL,OAAO,CAAC;EAC5C,CAAC;EAED;EACA,IAAIM,KAAKA,CAAA,EAAY;IACnB,OAAOV,WAAW,CAAC,CAAC,CAACU,KAAK;EAC5B,CAAC;EAED,IAAIA,KAAKA,CAACC,KAAc,EAAE;IACxBX,WAAW,CAAC,CAAC,CAACU,KAAK,GAAGC,KAAK;EAC7B;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export let MLXModel = /*#__PURE__*/function (MLXModel) {
|
|
4
|
+
// Llama 3.2 (Meta) - 1B and 3B variants
|
|
5
|
+
MLXModel["Llama_3_2_1B_Instruct_4bit"] = "mlx-community/Llama-3.2-1B-Instruct-4bit";
|
|
6
|
+
MLXModel["Llama_3_2_1B_Instruct_8bit"] = "mlx-community/Llama-3.2-1B-Instruct-8bit";
|
|
7
|
+
MLXModel["Llama_3_2_3B_Instruct_4bit"] = "mlx-community/Llama-3.2-3B-Instruct-4bit";
|
|
8
|
+
MLXModel["Llama_3_2_3B_Instruct_8bit"] = "mlx-community/Llama-3.2-3B-Instruct-8bit";
|
|
9
|
+
// Qwen 2.5 (Alibaba) - 0.5B, 1.5B, 3B variants
|
|
10
|
+
MLXModel["Qwen2_5_0_5B_Instruct_4bit"] = "mlx-community/Qwen2.5-0.5B-Instruct-4bit";
|
|
11
|
+
MLXModel["Qwen2_5_0_5B_Instruct_8bit"] = "mlx-community/Qwen2.5-0.5B-Instruct-8bit";
|
|
12
|
+
MLXModel["Qwen2_5_1_5B_Instruct_4bit"] = "mlx-community/Qwen2.5-1.5B-Instruct-4bit";
|
|
13
|
+
MLXModel["Qwen2_5_1_5B_Instruct_8bit"] = "mlx-community/Qwen2.5-1.5B-Instruct-8bit";
|
|
14
|
+
MLXModel["Qwen2_5_3B_Instruct_4bit"] = "mlx-community/Qwen2.5-3B-Instruct-4bit";
|
|
15
|
+
MLXModel["Qwen2_5_3B_Instruct_8bit"] = "mlx-community/Qwen2.5-3B-Instruct-8bit";
|
|
16
|
+
// Qwen 3 - 1.7B variant
|
|
17
|
+
MLXModel["Qwen3_1_7B_4bit"] = "mlx-community/Qwen3-1.7B-4bit";
|
|
18
|
+
MLXModel["Qwen3_1_7B_8bit"] = "mlx-community/Qwen3-1.7B-8bit";
|
|
19
|
+
// Gemma 3 (Google) - 1B variant
|
|
20
|
+
MLXModel["Gemma_3_1B_IT_4bit"] = "mlx-community/gemma-3-1b-it-4bit";
|
|
21
|
+
MLXModel["Gemma_3_1B_IT_8bit"] = "mlx-community/gemma-3-1b-it-8bit";
|
|
22
|
+
// Phi 3.5 Mini (Microsoft) - ~3.8B but runs well on mobile
|
|
23
|
+
MLXModel["Phi_3_5_Mini_Instruct_4bit"] = "mlx-community/Phi-3.5-mini-instruct-4bit";
|
|
24
|
+
MLXModel["Phi_3_5_Mini_Instruct_8bit"] = "mlx-community/Phi-3.5-mini-instruct-8bit";
|
|
25
|
+
// Phi 4 Mini (Microsoft)
|
|
26
|
+
MLXModel["Phi_4_Mini_Instruct_4bit"] = "mlx-community/Phi-4-mini-instruct-4bit";
|
|
27
|
+
MLXModel["Phi_4_Mini_Instruct_8bit"] = "mlx-community/Phi-4-mini-instruct-8bit";
|
|
28
|
+
// SmolLM (HuggingFace) - 1.7B
|
|
29
|
+
MLXModel["SmolLM_1_7B_Instruct_4bit"] = "mlx-community/SmolLM-1.7B-Instruct-4bit";
|
|
30
|
+
MLXModel["SmolLM_1_7B_Instruct_8bit"] = "mlx-community/SmolLM-1.7B-Instruct-8bit";
|
|
31
|
+
// SmolLM2 (HuggingFace) - 1.7B
|
|
32
|
+
MLXModel["SmolLM2_1_7B_Instruct_4bit"] = "mlx-community/SmolLM2-1.7B-Instruct-4bit";
|
|
33
|
+
MLXModel["SmolLM2_1_7B_Instruct_8bit"] = "mlx-community/SmolLM2-1.7B-Instruct-8bit";
|
|
34
|
+
// OpenELM (Apple) - 1.1B and 3B
|
|
35
|
+
MLXModel["OpenELM_1_1B_4bit"] = "mlx-community/OpenELM-1_1B-4bit";
|
|
36
|
+
MLXModel["OpenELM_1_1B_8bit"] = "mlx-community/OpenELM-1_1B-8bit";
|
|
37
|
+
MLXModel["OpenELM_3B_4bit"] = "mlx-community/OpenELM-3B-4bit";
|
|
38
|
+
MLXModel["OpenELM_3B_8bit"] = "mlx-community/OpenELM-3B-8bit";
|
|
39
|
+
return MLXModel;
|
|
40
|
+
}({});
|
|
41
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MLXModel"],"sourceRoot":"../../src","sources":["models.ts"],"mappings":";;AAAA,WAAYA,QAAQ,0BAARA,QAAQ;EAClB;EADUA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAOlB;EAPUA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAelB;EAfUA,QAAQ;EAARA,QAAQ;EAmBlB;EAnBUA,QAAQ;EAARA,QAAQ;EAuBlB;EAvBUA,QAAQ;EAARA,QAAQ;EA2BlB;EA3BUA,QAAQ;EAARA,QAAQ;EA+BlB;EA/BUA,QAAQ;EAARA,QAAQ;EAmClB;EAnCUA,QAAQ;EAARA,QAAQ;EAuClB;EAvCUA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/LLM.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/ModelManager.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LLM, type Message } from './llm';
|
|
2
|
+
export { ModelManager } from './modelManager';
|
|
3
|
+
export { MLXModel } from './models';
|
|
4
|
+
export type { GenerationStats, LLM as LLMSpec, LLMLoadOptions } from './specs/LLM.nitro';
|
|
5
|
+
export type { ModelManager as ModelManagerSpec } from './specs/ModelManager.nitro';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,YAAY,EAAE,eAAe,EAAE,GAAG,IAAI,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACxF,YAAY,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { GenerationStats, LLMLoadOptions } from './specs/LLM.nitro';
|
|
2
|
+
export type Message = {
|
|
3
|
+
role: 'user' | 'assistant' | 'system';
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* LLM text generation using MLX on Apple Silicon.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { LLM } from 'react-native-nitro-mlx'
|
|
12
|
+
*
|
|
13
|
+
* // Load a model
|
|
14
|
+
* await LLM.load('mlx-community/Qwen3-0.6B-4bit', progress => {
|
|
15
|
+
* console.log(`Loading: ${(progress * 100).toFixed(0)}%`)
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Stream a response
|
|
19
|
+
* await LLM.stream('Hello!', token => {
|
|
20
|
+
* process.stdout.write(token)
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* // Get generation stats
|
|
24
|
+
* const stats = LLM.getLastGenerationStats()
|
|
25
|
+
* console.log(`${stats.tokensPerSecond} tokens/sec`)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const LLM: {
|
|
29
|
+
/**
|
|
30
|
+
* Load a model into memory. Downloads the model from HuggingFace if not already cached.
|
|
31
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
32
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
33
|
+
*/
|
|
34
|
+
load(modelId: string, options: LLMLoadOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a complete response for a prompt. Blocks until generation is complete.
|
|
37
|
+
* For streaming responses, use `stream()` instead.
|
|
38
|
+
* @param prompt - The input text to generate a response for
|
|
39
|
+
* @returns The complete generated text
|
|
40
|
+
*/
|
|
41
|
+
generate(prompt: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Stream a response token by token.
|
|
44
|
+
* @param prompt - The input text to generate a response for
|
|
45
|
+
* @param onToken - Callback invoked for each generated token
|
|
46
|
+
* @returns The complete generated text
|
|
47
|
+
*/
|
|
48
|
+
stream(prompt: string, onToken: (token: string) => void): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Stop the current generation. Safe to call even if not generating.
|
|
51
|
+
*/
|
|
52
|
+
stop(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Unload the current model and release memory.
|
|
55
|
+
* Call this when you're done with the model to free up memory.
|
|
56
|
+
*/
|
|
57
|
+
unload(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get statistics from the last generation.
|
|
60
|
+
* @returns Statistics including token count, tokens/sec, TTFT, and total time
|
|
61
|
+
*/
|
|
62
|
+
getLastGenerationStats(): GenerationStats;
|
|
63
|
+
/**
|
|
64
|
+
* Get the message history if management is enabled.
|
|
65
|
+
* @returns Array of messages in the history
|
|
66
|
+
*/
|
|
67
|
+
getHistory(): Message[];
|
|
68
|
+
/**
|
|
69
|
+
* Clear the message history.
|
|
70
|
+
*/
|
|
71
|
+
clearHistory(): void;
|
|
72
|
+
/** Whether a model is currently loaded and ready for generation */
|
|
73
|
+
readonly isLoaded: boolean;
|
|
74
|
+
/** Whether text is currently being generated */
|
|
75
|
+
readonly isGenerating: boolean;
|
|
76
|
+
/** The ID of the currently loaded model, or empty string if none */
|
|
77
|
+
readonly modelId: string;
|
|
78
|
+
/** Enable debug logging to console */
|
|
79
|
+
debug: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* System prompt used when loading the model.
|
|
82
|
+
* Set this before calling `load()`. Changes require reloading the model.
|
|
83
|
+
* @default "You are a helpful assistant."
|
|
84
|
+
*/
|
|
85
|
+
systemPrompt: string;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../../src/llm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAkB,MAAM,mBAAmB,CAAA;AAIxF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AASD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,GAAG;IACd;;;;OAIG;kBACW,MAAM,WAAW,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7D;;;;;OAKG;qBACc,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzC;;;;;OAKG;mBACY,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzE;;OAEG;YACK,IAAI;IAIZ;;;OAGG;cACO,IAAI;IAId;;;OAGG;8BACuB,eAAe;IAIzC;;;OAGG;kBACW,OAAO,EAAE;IAIvB;;OAEG;oBACa,IAAI;IAIpB,mEAAmE;uBACnD,OAAO;IAIvB,gDAAgD;2BAC5B,OAAO;IAI3B,oEAAoE;sBACrD,MAAM;IAIrB,sCAAsC;WACzB,OAAO;IAQpB;;;;OAIG;kBACiB,MAAM;CAO3B,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manage MLX model downloads from HuggingFace.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { ModelManager } from 'react-native-nitro-mlx'
|
|
7
|
+
*
|
|
8
|
+
* // Download a model
|
|
9
|
+
* await ModelManager.download('mlx-community/Qwen3-0.6B-4bit', progress => {
|
|
10
|
+
* console.log(`Downloading: ${(progress * 100).toFixed(0)}%`)
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* // Check if downloaded
|
|
14
|
+
* const isReady = await ModelManager.isDownloaded('mlx-community/Qwen3-0.6B-4bit')
|
|
15
|
+
*
|
|
16
|
+
* // List all downloaded models
|
|
17
|
+
* const models = await ModelManager.getDownloadedModels()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const ModelManager: {
|
|
21
|
+
/**
|
|
22
|
+
* Download a model from HuggingFace.
|
|
23
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
24
|
+
* @param progressCallback - Callback invoked with download progress (0-1)
|
|
25
|
+
* @returns Path to the downloaded model directory
|
|
26
|
+
*/
|
|
27
|
+
download(modelId: string, progressCallback: (progress: number) => void): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a model is already downloaded.
|
|
30
|
+
* @param modelId - HuggingFace model ID
|
|
31
|
+
* @returns True if the model is fully downloaded
|
|
32
|
+
*/
|
|
33
|
+
isDownloaded(modelId: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Get a list of all downloaded model IDs.
|
|
36
|
+
* @returns Array of model IDs that are available locally
|
|
37
|
+
*/
|
|
38
|
+
getDownloadedModels(): Promise<string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a downloaded model to free up disk space.
|
|
41
|
+
* @param modelId - HuggingFace model ID
|
|
42
|
+
*/
|
|
43
|
+
deleteModel(modelId: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the local filesystem path for a downloaded model.
|
|
46
|
+
* @param modelId - HuggingFace model ID
|
|
47
|
+
* @returns Absolute path to the model directory
|
|
48
|
+
*/
|
|
49
|
+
getModelPath(modelId: string): Promise<string>;
|
|
50
|
+
/** Enable debug logging to console */
|
|
51
|
+
debug: boolean;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=modelManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelManager.d.ts","sourceRoot":"","sources":["../../../src/modelManager.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY;IACvB;;;;;OAKG;sBAEQ,MAAM,oBACG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAC3C,OAAO,CAAC,MAAM,CAAC;IAIlB;;;;OAIG;0BACmB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/C;;;OAGG;2BACoB,OAAO,CAAC,MAAM,EAAE,CAAC;IAIxC;;;OAGG;yBACkB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3C;;;;OAIG;0BACmB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C,sCAAsC;WACzB,OAAO;CAOrB,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum MLXModel {
|
|
2
|
+
Llama_3_2_1B_Instruct_4bit = "mlx-community/Llama-3.2-1B-Instruct-4bit",
|
|
3
|
+
Llama_3_2_1B_Instruct_8bit = "mlx-community/Llama-3.2-1B-Instruct-8bit",
|
|
4
|
+
Llama_3_2_3B_Instruct_4bit = "mlx-community/Llama-3.2-3B-Instruct-4bit",
|
|
5
|
+
Llama_3_2_3B_Instruct_8bit = "mlx-community/Llama-3.2-3B-Instruct-8bit",
|
|
6
|
+
Qwen2_5_0_5B_Instruct_4bit = "mlx-community/Qwen2.5-0.5B-Instruct-4bit",
|
|
7
|
+
Qwen2_5_0_5B_Instruct_8bit = "mlx-community/Qwen2.5-0.5B-Instruct-8bit",
|
|
8
|
+
Qwen2_5_1_5B_Instruct_4bit = "mlx-community/Qwen2.5-1.5B-Instruct-4bit",
|
|
9
|
+
Qwen2_5_1_5B_Instruct_8bit = "mlx-community/Qwen2.5-1.5B-Instruct-8bit",
|
|
10
|
+
Qwen2_5_3B_Instruct_4bit = "mlx-community/Qwen2.5-3B-Instruct-4bit",
|
|
11
|
+
Qwen2_5_3B_Instruct_8bit = "mlx-community/Qwen2.5-3B-Instruct-8bit",
|
|
12
|
+
Qwen3_1_7B_4bit = "mlx-community/Qwen3-1.7B-4bit",
|
|
13
|
+
Qwen3_1_7B_8bit = "mlx-community/Qwen3-1.7B-8bit",
|
|
14
|
+
Gemma_3_1B_IT_4bit = "mlx-community/gemma-3-1b-it-4bit",
|
|
15
|
+
Gemma_3_1B_IT_8bit = "mlx-community/gemma-3-1b-it-8bit",
|
|
16
|
+
Phi_3_5_Mini_Instruct_4bit = "mlx-community/Phi-3.5-mini-instruct-4bit",
|
|
17
|
+
Phi_3_5_Mini_Instruct_8bit = "mlx-community/Phi-3.5-mini-instruct-8bit",
|
|
18
|
+
Phi_4_Mini_Instruct_4bit = "mlx-community/Phi-4-mini-instruct-4bit",
|
|
19
|
+
Phi_4_Mini_Instruct_8bit = "mlx-community/Phi-4-mini-instruct-8bit",
|
|
20
|
+
SmolLM_1_7B_Instruct_4bit = "mlx-community/SmolLM-1.7B-Instruct-4bit",
|
|
21
|
+
SmolLM_1_7B_Instruct_8bit = "mlx-community/SmolLM-1.7B-Instruct-8bit",
|
|
22
|
+
SmolLM2_1_7B_Instruct_4bit = "mlx-community/SmolLM2-1.7B-Instruct-4bit",
|
|
23
|
+
SmolLM2_1_7B_Instruct_8bit = "mlx-community/SmolLM2-1.7B-Instruct-8bit",
|
|
24
|
+
OpenELM_1_1B_4bit = "mlx-community/OpenELM-1_1B-4bit",
|
|
25
|
+
OpenELM_1_1B_8bit = "mlx-community/OpenELM-1_1B-8bit",
|
|
26
|
+
OpenELM_3B_4bit = "mlx-community/OpenELM-3B-4bit",
|
|
27
|
+
OpenELM_3B_8bit = "mlx-community/OpenELM-3B-8bit"
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/models.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAElB,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IAGvE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IACvE,wBAAwB,2CAA2C;IACnE,wBAAwB,2CAA2C;IAGnE,eAAe,kCAAkC;IACjD,eAAe,kCAAkC;IAGjD,kBAAkB,qCAAqC;IACvD,kBAAkB,qCAAqC;IAGvD,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IAGvE,wBAAwB,2CAA2C;IACnE,wBAAwB,2CAA2C;IAGnE,yBAAyB,4CAA4C;IACrE,yBAAyB,4CAA4C;IAGrE,0BAA0B,6CAA6C;IACvE,0BAA0B,6CAA6C;IAGvE,iBAAiB,oCAAoC;IACrD,iBAAiB,oCAAoC;IACrD,eAAe,kCAAkC;IACjD,eAAe,kCAAkC;CAClD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
/**
|
|
3
|
+
* Statistics from the last text generation.
|
|
4
|
+
*/
|
|
5
|
+
export interface GenerationStats {
|
|
6
|
+
/** Total number of tokens generated */
|
|
7
|
+
tokenCount: number;
|
|
8
|
+
/** Generation speed in tokens per second */
|
|
9
|
+
tokensPerSecond: number;
|
|
10
|
+
/** Time in milliseconds until the first token was generated */
|
|
11
|
+
timeToFirstToken: number;
|
|
12
|
+
/** Total generation time in milliseconds */
|
|
13
|
+
totalTime: number;
|
|
14
|
+
}
|
|
15
|
+
export interface LLMMessage {
|
|
16
|
+
role: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}
|
|
19
|
+
/** Options for loading a model.
|
|
20
|
+
*/
|
|
21
|
+
export interface LLMLoadOptions {
|
|
22
|
+
/** Callback invoked with loading progress (0-1) */
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
/** Additional context to provide to the model */
|
|
25
|
+
additionalContext?: LLMMessage[];
|
|
26
|
+
/** Whether to automatically manage message history */
|
|
27
|
+
manageHistory?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Low-level LLM interface for text generation using MLX.
|
|
31
|
+
* @internal Use the `LLM` export from `react-native-nitro-mlx` instead.
|
|
32
|
+
*/
|
|
33
|
+
export interface LLM extends HybridObject<{
|
|
34
|
+
ios: 'swift';
|
|
35
|
+
}> {
|
|
36
|
+
/**
|
|
37
|
+
* Load a model into memory. Downloads from HuggingFace if not already cached.
|
|
38
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
39
|
+
* @param options - Callback invoked with loading progress (0-1)
|
|
40
|
+
*/
|
|
41
|
+
load(modelId: string, options?: LLMLoadOptions): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a complete response for a prompt.
|
|
44
|
+
* @param prompt - The input text to generate a response for
|
|
45
|
+
* @returns The generated text
|
|
46
|
+
*/
|
|
47
|
+
generate(prompt: string): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Stream a response token by token.
|
|
50
|
+
* @param prompt - The input text to generate a response for
|
|
51
|
+
* @param onToken - Callback invoked for each generated token
|
|
52
|
+
* @returns The complete generated text
|
|
53
|
+
*/
|
|
54
|
+
stream(prompt: string, onToken: (token: string) => void): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Stop the current generation.
|
|
57
|
+
*/
|
|
58
|
+
stop(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Unload the current model and release memory.
|
|
61
|
+
*/
|
|
62
|
+
unload(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get statistics from the last generation.
|
|
65
|
+
* @returns Statistics including token count, speed, and timing
|
|
66
|
+
*/
|
|
67
|
+
getLastGenerationStats(): GenerationStats;
|
|
68
|
+
/**
|
|
69
|
+
* Get the message history if management is enabled.
|
|
70
|
+
* @returns Array of messages in the history
|
|
71
|
+
*/
|
|
72
|
+
getHistory(): LLMMessage[];
|
|
73
|
+
/**
|
|
74
|
+
* Clear the message history.
|
|
75
|
+
*/
|
|
76
|
+
clearHistory(): void;
|
|
77
|
+
/** Whether a model is currently loaded */
|
|
78
|
+
readonly isLoaded: boolean;
|
|
79
|
+
/** Whether text is currently being generated */
|
|
80
|
+
readonly isGenerating: boolean;
|
|
81
|
+
/** The ID of the currently loaded model */
|
|
82
|
+
readonly modelId: string;
|
|
83
|
+
/** Enable debug logging */
|
|
84
|
+
debug: boolean;
|
|
85
|
+
/** System prompt used when loading the model */
|
|
86
|
+
systemPrompt: string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=LLM.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLM.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/LLM.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAA;IACvB,+DAA+D;IAC/D,gBAAgB,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;GACG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,iDAAiD;IACjD,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAA;IAChC,sDAAsD;IACtD,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,GAAI,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC;IACzD;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9D;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEzC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEzE;;OAEG;IACH,IAAI,IAAI,IAAI,CAAA;IAEZ;;OAEG;IACH,MAAM,IAAI,IAAI,CAAA;IAEd;;;OAGG;IACH,sBAAsB,IAAI,eAAe,CAAA;IAEzC;;;OAGG;IACH,UAAU,IAAI,UAAU,EAAE,CAAA;IAE1B;;OAEG;IACH,YAAY,IAAI,IAAI,CAAA;IAEpB,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB,2BAA2B;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAA;CACrB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
/**
|
|
3
|
+
* Low-level interface for managing MLX model downloads.
|
|
4
|
+
* @internal Use the `ModelManager` export from `react-native-nitro-mlx` instead.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModelManager extends HybridObject<{
|
|
7
|
+
ios: 'swift';
|
|
8
|
+
}> {
|
|
9
|
+
/**
|
|
10
|
+
* Download a model from HuggingFace.
|
|
11
|
+
* @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
|
|
12
|
+
* @param progressCallback - Callback invoked with download progress (0-1)
|
|
13
|
+
* @returns Path to the downloaded model directory
|
|
14
|
+
*/
|
|
15
|
+
download(modelId: string, progressCallback: (progress: number) => void): Promise<string>;
|
|
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
|
+
* Get a list of all downloaded model IDs.
|
|
24
|
+
* @returns Array of downloaded model IDs
|
|
25
|
+
*/
|
|
26
|
+
getDownloadedModels(): Promise<string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete a downloaded model.
|
|
29
|
+
* @param modelId - HuggingFace model ID
|
|
30
|
+
*/
|
|
31
|
+
deleteModel(modelId: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the local filesystem path for a downloaded model.
|
|
34
|
+
* @param modelId - HuggingFace model ID
|
|
35
|
+
* @returns Path to the model directory
|
|
36
|
+
*/
|
|
37
|
+
getModelPath(modelId: string): Promise<string>;
|
|
38
|
+
/** Enable debug logging */
|
|
39
|
+
debug: boolean;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=ModelManager.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelManager.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/ModelManager.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC;IAClE;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAExF;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAE/C;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAExC;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3C;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE9C,2BAA2B;IAC3B,KAAK,EAAE,OAAO,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#
|
|
2
|
+
# MLXReactNative+autolinking.rb
|
|
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
|
+
# This is a Ruby script that adds all files generated by Nitrogen
|
|
9
|
+
# to the given podspec.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your .podspec:
|
|
12
|
+
# ```ruby
|
|
13
|
+
# Pod::Spec.new do |spec|
|
|
14
|
+
# # ...
|
|
15
|
+
#
|
|
16
|
+
# # Add all files generated by Nitrogen
|
|
17
|
+
# load 'nitrogen/generated/ios/MLXReactNative+autolinking.rb'
|
|
18
|
+
# add_nitrogen_files(spec)
|
|
19
|
+
# end
|
|
20
|
+
# ```
|
|
21
|
+
|
|
22
|
+
def add_nitrogen_files(spec)
|
|
23
|
+
Pod::UI.puts "[NitroModules] 🔥 MLXReactNative is boosted by nitro!"
|
|
24
|
+
|
|
25
|
+
spec.dependency "NitroModules"
|
|
26
|
+
|
|
27
|
+
current_source_files = Array(spec.attributes_hash['source_files'])
|
|
28
|
+
spec.source_files = current_source_files + [
|
|
29
|
+
# Generated cross-platform specs
|
|
30
|
+
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
|
|
31
|
+
# Generated bridges for the cross-platform specs
|
|
32
|
+
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
current_public_header_files = Array(spec.attributes_hash['public_header_files'])
|
|
36
|
+
spec.public_header_files = current_public_header_files + [
|
|
37
|
+
# Generated specs
|
|
38
|
+
"nitrogen/generated/shared/**/*.{h,hpp}",
|
|
39
|
+
# Swift to C++ bridging helpers
|
|
40
|
+
"nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
current_private_header_files = Array(spec.attributes_hash['private_header_files'])
|
|
44
|
+
spec.private_header_files = current_private_header_files + [
|
|
45
|
+
# iOS specific specs
|
|
46
|
+
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
|
|
47
|
+
# Views are framework-specific and should be private
|
|
48
|
+
"nitrogen/generated/shared/**/views/**/*"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
|
|
52
|
+
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
|
+
# Use C++ 20
|
|
54
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only C)
|
|
56
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
|
+
# Enables stricter modular headers
|
|
58
|
+
"DEFINES_MODULE" => "YES",
|
|
59
|
+
})
|
|
60
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// MLXReactNative-Swift-Cxx-Bridge.cpp
|
|
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
|
+
#include "MLXReactNative-Swift-Cxx-Bridge.hpp"
|
|
9
|
+
|
|
10
|
+
// Include C++ implementation defined types
|
|
11
|
+
#include "HybridLLMSpecSwift.hpp"
|
|
12
|
+
#include "HybridModelManagerSpecSwift.hpp"
|
|
13
|
+
#include "MLXReactNative-Swift-Cxx-Umbrella.hpp"
|
|
14
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::mlxreactnative::bridge::swift {
|
|
17
|
+
|
|
18
|
+
// pragma MARK: std::function<void()>
|
|
19
|
+
Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
20
|
+
auto swiftClosure = MLXReactNative::Func_void::fromUnsafe(swiftClosureWrapper);
|
|
21
|
+
return [swiftClosure = std::move(swiftClosure)]() mutable -> void {
|
|
22
|
+
swiftClosure.call();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
|
|
27
|
+
Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
28
|
+
auto swiftClosure = MLXReactNative::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
|
|
29
|
+
return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
|
|
30
|
+
swiftClosure.call(error);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// pragma MARK: std::function<void(double /* progress */)>
|
|
35
|
+
Func_void_double create_Func_void_double(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
36
|
+
auto swiftClosure = MLXReactNative::Func_void_double::fromUnsafe(swiftClosureWrapper);
|
|
37
|
+
return [swiftClosure = std::move(swiftClosure)](double progress) mutable -> void {
|
|
38
|
+
swiftClosure.call(progress);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// pragma MARK: std::function<void(const std::string& /* result */)>
|
|
43
|
+
Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
44
|
+
auto swiftClosure = MLXReactNative::Func_void_std__string::fromUnsafe(swiftClosureWrapper);
|
|
45
|
+
return [swiftClosure = std::move(swiftClosure)](const std::string& result) mutable -> void {
|
|
46
|
+
swiftClosure.call(result);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// pragma MARK: std::shared_ptr<HybridLLMSpec>
|
|
51
|
+
std::shared_ptr<HybridLLMSpec> create_std__shared_ptr_HybridLLMSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
52
|
+
MLXReactNative::HybridLLMSpec_cxx swiftPart = MLXReactNative::HybridLLMSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
53
|
+
return std::make_shared<margelo::nitro::mlxreactnative::HybridLLMSpecSwift>(swiftPart);
|
|
54
|
+
}
|
|
55
|
+
void* NON_NULL get_std__shared_ptr_HybridLLMSpec_(std__shared_ptr_HybridLLMSpec_ cppType) {
|
|
56
|
+
std::shared_ptr<margelo::nitro::mlxreactnative::HybridLLMSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::mlxreactnative::HybridLLMSpecSwift>(cppType);
|
|
57
|
+
#ifdef NITRO_DEBUG
|
|
58
|
+
if (swiftWrapper == nullptr) [[unlikely]] {
|
|
59
|
+
throw std::runtime_error("Class \"HybridLLMSpec\" is not implemented in Swift!");
|
|
60
|
+
}
|
|
61
|
+
#endif
|
|
62
|
+
MLXReactNative::HybridLLMSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
63
|
+
return swiftPart.toUnsafe();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// pragma MARK: std::function<void(bool /* result */)>
|
|
67
|
+
Func_void_bool create_Func_void_bool(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
68
|
+
auto swiftClosure = MLXReactNative::Func_void_bool::fromUnsafe(swiftClosureWrapper);
|
|
69
|
+
return [swiftClosure = std::move(swiftClosure)](bool result) mutable -> void {
|
|
70
|
+
swiftClosure.call(result);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// pragma MARK: std::function<void(const std::vector<std::string>& /* result */)>
|
|
75
|
+
Func_void_std__vector_std__string_ create_Func_void_std__vector_std__string_(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
76
|
+
auto swiftClosure = MLXReactNative::Func_void_std__vector_std__string_::fromUnsafe(swiftClosureWrapper);
|
|
77
|
+
return [swiftClosure = std::move(swiftClosure)](const std::vector<std::string>& result) mutable -> void {
|
|
78
|
+
swiftClosure.call(result);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// pragma MARK: std::shared_ptr<HybridModelManagerSpec>
|
|
83
|
+
std::shared_ptr<HybridModelManagerSpec> create_std__shared_ptr_HybridModelManagerSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
84
|
+
MLXReactNative::HybridModelManagerSpec_cxx swiftPart = MLXReactNative::HybridModelManagerSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
85
|
+
return std::make_shared<margelo::nitro::mlxreactnative::HybridModelManagerSpecSwift>(swiftPart);
|
|
86
|
+
}
|
|
87
|
+
void* NON_NULL get_std__shared_ptr_HybridModelManagerSpec_(std__shared_ptr_HybridModelManagerSpec_ cppType) {
|
|
88
|
+
std::shared_ptr<margelo::nitro::mlxreactnative::HybridModelManagerSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::mlxreactnative::HybridModelManagerSpecSwift>(cppType);
|
|
89
|
+
#ifdef NITRO_DEBUG
|
|
90
|
+
if (swiftWrapper == nullptr) [[unlikely]] {
|
|
91
|
+
throw std::runtime_error("Class \"HybridModelManagerSpec\" is not implemented in Swift!");
|
|
92
|
+
}
|
|
93
|
+
#endif
|
|
94
|
+
MLXReactNative::HybridModelManagerSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
95
|
+
return swiftPart.toUnsafe();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
} // namespace margelo::nitro::mlxreactnative::bridge::swift
|