### Start the Example App Packager Source: https://github.com/cactus-compute/cactus-react-native/blob/main/CONTRIBUTING.md Starts the Metro bundler for the example application, allowing for development and testing of library changes. ```sh yarn example start ``` -------------------------------- ### Run Example App on Android Source: https://github.com/cactus-compute/cactus-react-native/blob/main/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/cactus-compute/cactus-react-native/blob/main/CONTRIBUTING.md Builds and runs the example application on an iOS device or simulator. ```sh yarn example ios ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/cactus-compute/cactus-react-native/blob/main/example/README.md Run this command from the root of your React Native project to start the Metro dev server. This is necessary for building and running your app. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Quick Start: Initialize and Generate Text Source: https://github.com/cactus-compute/cactus-react-native/blob/main/README.md Initialize CactusLM, download a model, generate a text completion, and clean up resources. ```typescript import { CactusLM, type CactusLMMessage } from 'cactus-react-native'; // Create a new instance const cactusLM = new CactusLM(); // Download the model await cactusLM.download({ onProgress: (progress) => console.log(`Download: ${Math.round(progress * 100)}%`) }); // Generate a completion const messages: CactusLMMessage[] = [ { role: 'user', content: 'What is the capital of France?' } ]; const result = await cactusLM.complete({ messages }); console.log(result.response); // "The capital of France is Paris." // Clean up resources await cactusLM.destroy(); ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/cactus-compute/cactus-react-native/blob/main/CONTRIBUTING.md Run this command in the root directory to install all required dependencies for the monorepo using Yarn workspaces. ```sh yarn ``` -------------------------------- ### CactusIndex Workflow Example Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/api-reference/CactusIndex.md Demonstrates a complete workflow for using CactusIndex, including initialization, adding documents, searching, retrieving, and cleanup. ```typescript import { CactusIndex } from 'cactus-react-native'; // 1. Create and initialize index const index = new CactusIndex('documents', 768); await index.init(); // 2. Add documents with embeddings await index.add({ ids: [1, 2, 3], documents: [ 'Machine learning applications in healthcare', 'Deep learning for computer vision', 'Natural language processing techniques' ], embeddings: [ [/* 768-dim embedding */], [/* 768-dim embedding */], [/* 768-dim embedding */] ], metadatas: ['healthcare.txt', 'vision.txt', 'nlp.txt'] }); // 3. Search for similar documents const queryResult = await index.query({ embeddings: [[/* query embedding */]], options: { topK: 3 } }); console.log('Most similar documents:'); queryResult.ids[0].forEach((id, i) => { console.log(`ID ${id}: similarity ${queryResult.scores[0][i]}`); }); // 4. Retrieve full documents const getResult = await index.get({ ids: queryResult.ids[0] }); getResult.documents.forEach(doc => { console.log('Document:', doc); }); // 5. Clean up await index.destroy(); ``` -------------------------------- ### Install cactus-react-native Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/README.md Install the cactus-react-native package and its peer dependency react-native-nitro-modules using npm. ```bash npm install cactus-react-native react-native-nitro-modules ``` -------------------------------- ### Instantiate CactusLM with Default Model Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/api-reference/CactusLM.md Create a CactusLM instance using the default model slug. This is the simplest way to get started. ```typescript import { CactusLM } from 'cactus-react-native'; // Create with default model const cactusLM = new CactusLM(); ``` -------------------------------- ### Organize and Display Models by Capability Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/api-reference/ModelRegistry.md An example function that retrieves all models, organizes them by their capabilities, and then logs detailed information including model size for different quantization levels. This helps in understanding model distribution and resource requirements. ```typescript import { CactusLM, CactusSTT, CactusAudio, getRegistry } from 'cactus-react-native'; async function listAvailableModels() { const registry = await getRegistry(); // Group models by capability const modelsByCapability: { [key: string]: string[] } = {}; Object.entries(registry).forEach(([slug, model]) => { model.capabilities.forEach(cap => { if (!modelsByCapability[cap]) { modelsByCapability[cap] = []; } modelsByCapability[cap].push(slug); }); }); // Display organized results Object.entries(modelsByCapability).forEach(([capability, models]) => { console.log(` ${capability}:`); models.forEach(model => { const sizes = registry[model].quantization; console.log(` ${model}`); console.log(` Int8: ${sizes.int8.sizeMb} MB`); console.log(` Int4: ${sizes.int4.sizeMb} MB`); if (sizes.int8.pro?.apple) { console.log(` Int8 Pro: Available`); } if (sizes.int4.pro?.apple) { console.log(` Int4 Pro: Available`); } }); }); } listAvailableModels(); ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/cactus-compute/cactus-react-native/blob/main/example/README.md Before running the iOS app, install CocoaPods dependencies. This command is typically run once or after updating native dependencies. ```sh bundle install bundle exec pod install ``` -------------------------------- ### streamTranscribeStart Source: https://github.com/cactus-compute/cactus-react-native/blob/main/README.md Starts a streaming transcription session. This method initializes the streaming state and sets `isStreamTranscribing` to true. ```APIDOC ## streamTranscribeStart(options?: CactusSTTStreamTranscribeStartOptions) ### Description Starts a streaming transcription session. If a session is already active, this method returns immediately. The `streamTranscribeConfirmed` and `streamTranscribePending` states are cleared before starting, and `isStreamTranscribing` is set to `true`. ### Parameters - **options** (CactusSTTStreamTranscribeStartOptions) - Optional configuration for the streaming session. ### Returns - `Promise` ``` -------------------------------- ### Start Streaming Transcription Session Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/api-reference/CactusSTT.md Initiates a streaming transcription session for real-time transcription. Configure parameters like `confirmationThreshold`, `minChunkSize`, and `language`. The session is idempotent if already active. ```typescript await cactusSTT.streamTranscribeStart({ confirmationThreshold: 0.99, minChunkSize: 32000, language: 'en' }); ``` -------------------------------- ### Get Available Audio Models Source: https://github.com/cactus-compute/cactus-react-native/blob/main/_autodocs/api-reference/CactusAudio.md Use the getModels method to retrieve a list of all audio models available in the registry. This can be useful for inspecting available models and their capabilities. ```typescript async getModels(): Promise ``` ```typescript const models = await cactusAudio.getModels(); models.forEach(model => { console.log(`${model.slug}: ${model.capabilities.join(', ')}`); }); ``` -------------------------------- ### Quick Start: React Hook for Text Generation Source: https://github.com/cactus-compute/cactus-react-native/blob/main/README.md Utilize the useCactusLM hook in React Native to manage model download, generation, and display completion results. ```tsx import { useCactusLM } from 'cactus-react-native'; const App = () => { const cactusLM = useCactusLM(); useEffect(() => { // Download the model if not already available if (!cactusLM.isDownloaded) { cactusLM.download(); } }, []); const handleGenerate = () => { // Generate a completion cactusLM.complete({ messages: [{ role: 'user', content: 'Hello!' }], }); }; if (cactusLM.isDownloading) { return ( Downloading model: {Math.round(cactusLM.downloadProgress * 100)}% ); } return ( <>