@inferrlm/react-native-mlx 0.2.0-inferrlm.2 → 0.4.0

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.
Files changed (102) hide show
  1. package/MLXReactNative.podspec +9 -3
  2. package/ios/Sources/AudioCaptureManager.swift +110 -0
  3. package/ios/Sources/HybridLLM.swift +562 -74
  4. package/ios/Sources/HybridSTT.swift +202 -0
  5. package/ios/Sources/HybridTTS.swift +145 -0
  6. package/ios/Sources/JSONHelpers.swift +9 -0
  7. package/ios/Sources/ModelDownloader.swift +26 -12
  8. package/ios/Sources/StreamEventEmitter.swift +132 -0
  9. package/ios/Sources/ThinkingStateMachine.swift +206 -0
  10. package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +1 -1
  11. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +76 -1
  12. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +338 -1
  13. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +28 -1
  14. package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +17 -1
  15. package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +31 -1
  16. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +1 -1
  17. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +18 -3
  18. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +1 -1
  19. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +1 -1
  20. package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.cpp +11 -0
  21. package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.hpp +149 -0
  22. package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.cpp +11 -0
  23. package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.hpp +128 -0
  24. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_.swift +62 -0
  25. package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
  26. package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
  27. package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
  28. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
  29. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_AnyMap_.swift +47 -0
  30. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift +47 -0
  31. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___.swift +67 -0
  32. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
  33. package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +47 -0
  34. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +1 -1
  35. package/nitrogen/generated/ios/swift/GenerationStats.swift +14 -3
  36. package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +3 -2
  37. package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +38 -2
  38. package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +1 -1
  39. package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +1 -1
  40. package/nitrogen/generated/ios/swift/HybridSTTSpec.swift +66 -0
  41. package/nitrogen/generated/ios/swift/HybridSTTSpec_cxx.swift +286 -0
  42. package/nitrogen/generated/ios/swift/HybridTTSSpec.swift +63 -0
  43. package/nitrogen/generated/ios/swift/HybridTTSSpec_cxx.swift +229 -0
  44. package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +44 -2
  45. package/nitrogen/generated/ios/swift/LLMMessage.swift +1 -1
  46. package/nitrogen/generated/ios/swift/STTLoadOptions.swift +66 -0
  47. package/nitrogen/generated/ios/swift/TTSGenerateOptions.swift +78 -0
  48. package/nitrogen/generated/ios/swift/TTSLoadOptions.swift +66 -0
  49. package/nitrogen/generated/ios/swift/ToolDefinition.swift +113 -0
  50. package/nitrogen/generated/ios/swift/ToolParameter.swift +69 -0
  51. package/nitrogen/generated/shared/c++/GenerationStats.hpp +7 -3
  52. package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +2 -1
  53. package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +3 -2
  54. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +1 -1
  55. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +1 -1
  56. package/nitrogen/generated/shared/c++/HybridSTTSpec.cpp +32 -0
  57. package/nitrogen/generated/shared/c++/HybridSTTSpec.hpp +78 -0
  58. package/nitrogen/generated/shared/c++/HybridTTSSpec.cpp +29 -0
  59. package/nitrogen/generated/shared/c++/HybridTTSSpec.hpp +78 -0
  60. package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +10 -3
  61. package/nitrogen/generated/shared/c++/LLMMessage.hpp +1 -1
  62. package/nitrogen/generated/shared/c++/STTLoadOptions.hpp +76 -0
  63. package/nitrogen/generated/shared/c++/TTSGenerateOptions.hpp +80 -0
  64. package/nitrogen/generated/shared/c++/TTSLoadOptions.hpp +76 -0
  65. package/nitrogen/generated/shared/c++/ToolDefinition.hpp +93 -0
  66. package/nitrogen/generated/shared/c++/ToolParameter.hpp +87 -0
  67. package/package.json +13 -8
  68. package/src/index.ts +48 -4
  69. package/src/llm.ts +90 -5
  70. package/src/models.ts +347 -0
  71. package/src/specs/LLM.nitro.ts +111 -7
  72. package/src/specs/STT.nitro.ts +35 -0
  73. package/src/specs/TTS.nitro.ts +30 -0
  74. package/src/stt.ts +67 -0
  75. package/src/tool-utils.ts +74 -0
  76. package/src/tts.ts +60 -0
  77. package/lib/module/index.js +0 -6
  78. package/lib/module/index.js.map +0 -1
  79. package/lib/module/llm.js +0 -125
  80. package/lib/module/llm.js.map +0 -1
  81. package/lib/module/modelManager.js +0 -79
  82. package/lib/module/modelManager.js.map +0 -1
  83. package/lib/module/models.js +0 -41
  84. package/lib/module/models.js.map +0 -1
  85. package/lib/module/package.json +0 -1
  86. package/lib/module/specs/LLM.nitro.js +0 -4
  87. package/lib/module/specs/LLM.nitro.js.map +0 -1
  88. package/lib/module/specs/ModelManager.nitro.js +0 -4
  89. package/lib/module/specs/ModelManager.nitro.js.map +0 -1
  90. package/lib/typescript/package.json +0 -1
  91. package/lib/typescript/src/index.d.ts +0 -6
  92. package/lib/typescript/src/index.d.ts.map +0 -1
  93. package/lib/typescript/src/llm.d.ts +0 -87
  94. package/lib/typescript/src/llm.d.ts.map +0 -1
  95. package/lib/typescript/src/modelManager.d.ts +0 -53
  96. package/lib/typescript/src/modelManager.d.ts.map +0 -1
  97. package/lib/typescript/src/models.d.ts +0 -29
  98. package/lib/typescript/src/models.d.ts.map +0 -1
  99. package/lib/typescript/src/specs/LLM.nitro.d.ts +0 -88
  100. package/lib/typescript/src/specs/LLM.nitro.d.ts.map +0 -1
  101. package/lib/typescript/src/specs/ModelManager.nitro.d.ts +0 -41
  102. package/lib/typescript/src/specs/ModelManager.nitro.d.ts.map +0 -1
@@ -0,0 +1,74 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules'
2
+ import type { z } from 'zod'
3
+ import type { ToolDefinition, ToolParameter, ToolParameterType } from './specs/LLM.nitro'
4
+
5
+ type ZodObjectSchema = z.ZodObject<z.core.$ZodShape>
6
+ type InferArgs<T extends ZodObjectSchema> = z.infer<T>
7
+
8
+ export interface TypeSafeToolDefinition<T extends ZodObjectSchema> {
9
+ name: string
10
+ description: string
11
+ arguments: T
12
+ handler: (args: InferArgs<T>) => Promise<Record<string, unknown>>
13
+ }
14
+
15
+ function getZodTypeString(zodType: z.ZodType): ToolParameterType {
16
+ const typeName = zodType._zod.def.type
17
+ switch (typeName) {
18
+ case 'string':
19
+ return 'string'
20
+ case 'number':
21
+ case 'int':
22
+ return 'number'
23
+ case 'boolean':
24
+ return 'boolean'
25
+ case 'array':
26
+ return 'array'
27
+ case 'object':
28
+ return 'object'
29
+ case 'optional':
30
+ return getZodTypeString((zodType as z.ZodOptional<z.ZodType>)._zod.def.innerType)
31
+ case 'default':
32
+ return getZodTypeString((zodType as z.ZodDefault<z.ZodType>)._zod.def.innerType)
33
+ default:
34
+ return 'string'
35
+ }
36
+ }
37
+
38
+ function isZodOptional(zodType: z.ZodType): boolean {
39
+ const typeName = zodType._zod.def.type
40
+ return typeName === 'optional' || typeName === 'default'
41
+ }
42
+
43
+ function zodSchemaToParameters(schema: ZodObjectSchema): ToolParameter[] {
44
+ const shape = schema._zod.def.shape
45
+ const parameters: ToolParameter[] = []
46
+
47
+ for (const [key, zodType] of Object.entries(shape)) {
48
+ const zType = zodType as z.ZodType
49
+ parameters.push({
50
+ name: key,
51
+ type: getZodTypeString(zType),
52
+ description: zType.description ?? '',
53
+ required: !isZodOptional(zType),
54
+ })
55
+ }
56
+
57
+ return parameters
58
+ }
59
+
60
+ export function createTool<T extends ZodObjectSchema>(
61
+ definition: TypeSafeToolDefinition<T>,
62
+ ): ToolDefinition {
63
+ return {
64
+ name: definition.name,
65
+ description: definition.description,
66
+ parameters: zodSchemaToParameters(definition.arguments),
67
+ handler: async (args: AnyMap) => {
68
+ const argsObj = args as unknown as Record<string, unknown>
69
+ const parsedArgs = definition.arguments.parse(argsObj)
70
+ const result = await definition.handler(parsedArgs)
71
+ return result as unknown as AnyMap
72
+ },
73
+ }
74
+ }
package/src/tts.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { NitroModules } from 'react-native-nitro-modules'
2
+ import type {
3
+ TTS as TTSSpec,
4
+ TTSLoadOptions,
5
+ TTSGenerateOptions,
6
+ } from './specs/TTS.nitro'
7
+
8
+ let instance: TTSSpec | null = null
9
+
10
+ function getInstance(): TTSSpec {
11
+ if (!instance) {
12
+ instance = NitroModules.createHybridObject<TTSSpec>('TTS')
13
+ }
14
+ return instance
15
+ }
16
+
17
+ export const TTS = {
18
+ load(modelId: string, options?: TTSLoadOptions): Promise<void> {
19
+ return getInstance().load(modelId, options)
20
+ },
21
+
22
+ generate(
23
+ text: string,
24
+ options?: TTSGenerateOptions
25
+ ): Promise<ArrayBuffer> {
26
+ return getInstance().generate(text, options)
27
+ },
28
+
29
+ stream(
30
+ text: string,
31
+ onAudioChunk: (audio: ArrayBuffer) => void,
32
+ options?: TTSGenerateOptions
33
+ ): Promise<void> {
34
+ return getInstance().stream(text, onAudioChunk, options)
35
+ },
36
+
37
+ stop(): void {
38
+ getInstance().stop()
39
+ },
40
+
41
+ unload(): void {
42
+ getInstance().unload()
43
+ },
44
+
45
+ get isLoaded(): boolean {
46
+ return getInstance().isLoaded
47
+ },
48
+
49
+ get isGenerating(): boolean {
50
+ return getInstance().isGenerating
51
+ },
52
+
53
+ get modelId(): string {
54
+ return getInstance().modelId
55
+ },
56
+
57
+ get sampleRate(): number {
58
+ return getInstance().sampleRate
59
+ },
60
+ }
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- export { LLM } from "./llm.js";
4
- export { ModelManager } from "./modelManager.js";
5
- export { MLXModel } from "./models.js";
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["LLM","ModelManager","MLXModel"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,GAAG,QAAsB,UAAO;AACzC,SAASC,YAAY,QAAQ,mBAAgB;AAC7C,SAASC,QAAQ,QAAQ,aAAU","ignoreList":[]}
package/lib/module/llm.js DELETED
@@ -1,125 +0,0 @@
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('LLM');
8
- }
9
- return instance;
10
- }
11
-
12
- /**
13
- * LLM text generation using MLX on Apple Silicon.
14
- *
15
- * @example
16
- * ```ts
17
- * import { LLM } from 'react-native-nitro-mlx'
18
- *
19
- * // Load a model
20
- * await LLM.load('mlx-community/Qwen3-0.6B-4bit', progress => {
21
- * console.log(`Loading: ${(progress * 100).toFixed(0)}%`)
22
- * })
23
- *
24
- * // Stream a response
25
- * await LLM.stream('Hello!', token => {
26
- * process.stdout.write(token)
27
- * })
28
- *
29
- * // Get generation stats
30
- * const stats = LLM.getLastGenerationStats()
31
- * console.log(`${stats.tokensPerSecond} tokens/sec`)
32
- * ```
33
- */
34
- export const LLM = {
35
- /**
36
- * Load a model into memory. Downloads the model from HuggingFace if not already cached.
37
- * @param modelId - HuggingFace model ID (e.g., 'mlx-community/Qwen3-0.6B-4bit')
38
- * @param options - Callback invoked with loading progress (0-1)
39
- */
40
- load(modelId, options) {
41
- return getInstance().load(modelId, options);
42
- },
43
- /**
44
- * Generate a complete response for a prompt. Blocks until generation is complete.
45
- * For streaming responses, use `stream()` instead.
46
- * @param prompt - The input text to generate a response for
47
- * @returns The complete generated text
48
- */
49
- generate(prompt) {
50
- return getInstance().generate(prompt);
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, onToken) {
59
- return getInstance().stream(prompt, onToken);
60
- },
61
- /**
62
- * Stop the current generation. Safe to call even if not generating.
63
- */
64
- stop() {
65
- getInstance().stop();
66
- },
67
- /**
68
- * Unload the current model and release memory.
69
- * Call this when you're done with the model to free up memory.
70
- */
71
- unload() {
72
- getInstance().unload();
73
- },
74
- /**
75
- * Get statistics from the last generation.
76
- * @returns Statistics including token count, tokens/sec, TTFT, and total time
77
- */
78
- getLastGenerationStats() {
79
- return getInstance().getLastGenerationStats();
80
- },
81
- /**
82
- * Get the message history if management is enabled.
83
- * @returns Array of messages in the history
84
- */
85
- getHistory() {
86
- return getInstance().getHistory();
87
- },
88
- /**
89
- * Clear the message history.
90
- */
91
- clearHistory() {
92
- getInstance().clearHistory();
93
- },
94
- /** Whether a model is currently loaded and ready for generation */
95
- get isLoaded() {
96
- return getInstance().isLoaded;
97
- },
98
- /** Whether text is currently being generated */
99
- get isGenerating() {
100
- return getInstance().isGenerating;
101
- },
102
- /** The ID of the currently loaded model, or empty string if none */
103
- get modelId() {
104
- return getInstance().modelId;
105
- },
106
- /** Enable debug logging to console */
107
- get debug() {
108
- return getInstance().debug;
109
- },
110
- set debug(value) {
111
- getInstance().debug = value;
112
- },
113
- /**
114
- * System prompt used when loading the model.
115
- * Set this before calling `load()`. Changes require reloading the model.
116
- * @default "You are a helpful assistant."
117
- */
118
- get systemPrompt() {
119
- return getInstance().systemPrompt;
120
- },
121
- set systemPrompt(value) {
122
- getInstance().systemPrompt = value;
123
- }
124
- };
125
- //# sourceMappingURL=llm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["NitroModules","instance","getInstance","createHybridObject","LLM","load","modelId","options","generate","prompt","stream","onToken","stop","unload","getLastGenerationStats","getHistory","clearHistory","isLoaded","isGenerating","debug","value","systemPrompt"],"sourceRoot":"../../src","sources":["llm.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,IAAIC,QAAwB,GAAG,IAAI;AAOnC,SAASC,WAAWA,CAAA,EAAY;EAC9B,IAAI,CAACD,QAAQ,EAAE;IACbA,QAAQ,GAAGD,YAAY,CAACG,kBAAkB,CAAU,KAAK,CAAC;EAC5D;EACA,OAAOF,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,GAAG,GAAG;EACjB;AACF;AACA;AACA;AACA;EACEC,IAAIA,CAACC,OAAe,EAAEC,OAAuB,EAAiB;IAC5D,OAAOL,WAAW,CAAC,CAAC,CAACG,IAAI,CAACC,OAAO,EAAEC,OAAO,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEC,QAAQA,CAACC,MAAc,EAAmB;IACxC,OAAOP,WAAW,CAAC,CAAC,CAACM,QAAQ,CAACC,MAAM,CAAC;EACvC,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEC,MAAMA,CAACD,MAAc,EAAEE,OAAgC,EAAmB;IACxE,OAAOT,WAAW,CAAC,CAAC,CAACQ,MAAM,CAACD,MAAM,EAAEE,OAAO,CAAC;EAC9C,CAAC;EAED;AACF;AACA;EACEC,IAAIA,CAAA,EAAS;IACXV,WAAW,CAAC,CAAC,CAACU,IAAI,CAAC,CAAC;EACtB,CAAC;EAED;AACF;AACA;AACA;EACEC,MAAMA,CAAA,EAAS;IACbX,WAAW,CAAC,CAAC,CAACW,MAAM,CAAC,CAAC;EACxB,CAAC;EAED;AACF;AACA;AACA;EACEC,sBAAsBA,CAAA,EAAoB;IACxC,OAAOZ,WAAW,CAAC,CAAC,CAACY,sBAAsB,CAAC,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;EACEC,UAAUA,CAAA,EAAc;IACtB,OAAOb,WAAW,CAAC,CAAC,CAACa,UAAU,CAAC,CAAC;EACnC,CAAC;EAED;AACF;AACA;EACEC,YAAYA,CAAA,EAAS;IACnBd,WAAW,CAAC,CAAC,CAACc,YAAY,CAAC,CAAC;EAC9B,CAAC;EAED;EACA,IAAIC,QAAQA,CAAA,EAAY;IACtB,OAAOf,WAAW,CAAC,CAAC,CAACe,QAAQ;EAC/B,CAAC;EAED;EACA,IAAIC,YAAYA,CAAA,EAAY;IAC1B,OAAOhB,WAAW,CAAC,CAAC,CAACgB,YAAY;EACnC,CAAC;EAED;EACA,IAAIZ,OAAOA,CAAA,EAAW;IACpB,OAAOJ,WAAW,CAAC,CAAC,CAACI,OAAO;EAC9B,CAAC;EAED;EACA,IAAIa,KAAKA,CAAA,EAAY;IACnB,OAAOjB,WAAW,CAAC,CAAC,CAACiB,KAAK;EAC5B,CAAC;EAED,IAAIA,KAAKA,CAACC,KAAc,EAAE;IACxBlB,WAAW,CAAC,CAAC,CAACiB,KAAK,GAAGC,KAAK;EAC7B,CAAC;EAED;AACF;AACA;AACA;AACA;EACE,IAAIC,YAAYA,CAAA,EAAW;IACzB,OAAOnB,WAAW,CAAC,CAAC,CAACmB,YAAY;EACnC,CAAC;EAED,IAAIA,YAAYA,CAACD,KAAa,EAAE;IAC9BlB,WAAW,CAAC,CAAC,CAACmB,YAAY,GAAGD,KAAK;EACpC;AACF,CAAC","ignoreList":[]}
@@ -1,79 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1,41 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1 +0,0 @@
1
- {"type":"module"}
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export {};
4
- //# sourceMappingURL=LLM.nitro.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/LLM.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export {};
4
- //# sourceMappingURL=ModelManager.nitro.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/ModelManager.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"type":"module"}
@@ -1,6 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,87 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,53 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,29 +0,0 @@
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
@@ -1 +0,0 @@
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"}