You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{LLM}from'react-native-nitro-mlx'awaitLLM.load('mlx-community/Qwen3-0.6B-4bit',{onProgress: (progress)=>{console.log(`Loading: ${(progress*100).toFixed(0)}%`)}})constresponse=awaitLLM.generate('What is the capital of France?')console.log(response)
Load with Additional Context
You can provide conversation history or few-shot examples when loading the model:
awaitLLM.load('mlx-community/Qwen3-0.6B-4bit',{onProgress: (progress)=>{console.log(`Loading: ${(progress*100).toFixed(0)}%`)},additionalContext: [{role: 'user',content: 'What is machine learning?'},{role: 'assistant',content: 'Machine learning is...'},{role: 'user',content: 'Can you explain neural networks?'}]})
Streaming
letresponse=''awaitLLM.stream('Tell me a story',(token)=>{response+=tokenconsole.log(response)})
Stop Generation
LLM.stop()
Text-to-Speech
import{TTS,MLXModel}from'react-native-nitro-mlx'awaitTTS.load(MLXModel.PocketTTS,{onProgress: (progress)=>{console.log(`Loading: ${(progress*100).toFixed(0)}%`)}})constaudioBuffer=awaitTTS.generate('Hello world!',{voice: 'alba',speed: 1.0})// Or stream audio chunks as they're generatedawaitTTS.stream('Hello world!',(chunk)=>{// Process each audio chunk},{voice: 'alba'})
Available voices: alba, azelma, cosette, eponine, fantine, javert, jean, marius
Speech-to-Text
import{STT,MLXModel}from'react-native-nitro-mlx'awaitSTT.load(MLXModel.GLM_ASR_Nano_4bit,{onProgress: (progress)=>{console.log(`Loading: ${(progress*100).toFixed(0)}%`)}})// Transcribe an audio bufferconsttext=awaitSTT.transcribe(audioBuffer)// Or use live microphone transcriptionawaitSTT.startListening()constpartial=awaitSTT.transcribeBuffer()// Get current transcriptconstfinal=awaitSTT.stopListening()// Stop and get final transcript
Any MLX-compatible model from Hugging Face should work. The package exports an MLXModel enum with pre-defined models for convenience that are more likely to run well on-device: