{"_id":"@bariscelik/llama.rn","_rev":"3-4601f1d6673eeddcf08ab7dc986b87a7","name":"@bariscelik/llama.rn","dist-tags":{"latest":"0.6.17"},"versions":{"0.6.8":{"name":"@bariscelik/llama.rn","version":"0.6.8","keywords":["react-native","ios","android","large language model","LLM","Local LLM","llama.cpp","llama","llama-2"],"author":{"url":"https://github.com/mybigday","name":"Jhen-Jie Hong","email":"developer@jhen.me"},"license":"MIT","_id":"@bariscelik/llama.rn@0.6.8","maintainers":[{"name":"bariscelik","email":"bariscelikweb@gmail.com"}],"homepage":"https://github.com/bariscelik/llama.rn#readme","bugs":{"url":"https://github.com/bariscelik/llama.rn/issues"},"dist":{"shasum":"37f11fc627cd3755fa5b8f8bfe146dae76e4734a","tarball":"https://registry.npmjs.org/@bariscelik/llama.rn/-/llama.rn-0.6.8.tgz","fileCount":437,"integrity":"sha512-SAtDXU4ZvwhAP5JkjeDnB1OiS0z+LCe/U4Z6dJTTIzT1UyW2RnnIdl3zikDPnKwX8safPwPcw9QRfTjvHy+pgw==","signatures":[{"sig":"MEUCIGsw2VlhDXQGnRg0dJNBGLOJ7a/fv/uJvcNzHZQVgG5hAiEA3024RhXNzOJGxcZwKUz9zzQUXjzeJ34UBrt8t1Rbdxk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":77492297},"jest":{"preset":"react-native","modulePathIgnorePatterns":["<rootDir>/example/node_modules","<rootDir>/lib/"]},"main":"lib/commonjs/index","types":"lib/typescript/index.d.ts","module":"lib/module/index","source":"src/index","engines":{"node":">= 16.0.0"},"gitHead":"2f117b81ba386eab23c3912f102f35a6ca2b6575","scripts":{"lint":"eslint \"**/*.{js,ts,tsx}\"","test":"jest","build":"bob build","clean":"del-cli example/ios/build","docgen":"typedoc src/index.ts --plugin typedoc-plugin-markdown --readme none --out docs/API","example":"npm --prefix example","prepack":"./scripts/build-ios.sh && bob build","release":"release-it","bootstrap":"./scripts/bootstrap.sh","build:ios":"cd example/ios && xcodebuild -workspace RNLlamaExample.xcworkspace -scheme RNLlamaExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO","typecheck":"tsc --noEmit","build:android":"cd example/android && ./gradlew assembleDebug","build:android-libs":"./scripts/build-android.sh","build:ios-frameworks":"./scripts/build-ios.sh"},"_npmUser":{"name":"bariscelik","email":"bariscelikweb@gmail.com"},"prettier":{"semi":false,"tabWidth":2,"printWidth":80,"singleQuote":true,"trailingComma":"all"},"commitlint":{"extends":["@commitlint/config-conventional"]},"release-it":{"git":{"tagName":"v${version}","commitMessage":"chore: release ${version}"},"npm":{"publish":true,"skipChecks":true},"github":{"release":true},"plugins":{"@release-it/conventional-changelog":{"preset":"angular"}}},"repository":{"url":"git+https://github.com/bariscelik/llama.rn.git","type":"git"},"_npmVersion":"11.4.2","description":"React Native binding of llama.cpp","directories":{},"resolutions":{"@types/react":"17.0.21"},"_nodeVersion":"23.10.0","eslintConfig":{"env":{"jest":true,"browser":true},"rules":{"global-require":0,"react/no-array-index-key":0},"extends":"@fugood/eslint-config-react","globals":{},"settings":{"import/resolver":{"node":{"extensions":[".js",".jsx",".ts",".tsx"]}}},"overrides":[{"files":["*.ts","*.tsx"],"rules":{"no-undef":"off","no-shadow":"off","no-unused-vars":"off","func-call-spacing":"off","import/extensions":["error","ignorePackages",{"js":"never","ts":"never","jsx":"never","tsx":"never"}],"react/require-default-props":"off","@typescript-eslint/no-shadow":1,"react/jsx-filename-extension":[1,{"extensions":[".js",".jsx",".tsx"]}],"@typescript-eslint/no-unused-vars":["error",{"argsIgnorePattern":"^_","destructuredArrayIgnorePattern":"^_"}],"@typescript-eslint/func-call-spacing":1},"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint/eslint-plugin"]}]},"eslintIgnore":["node_modules/","lib/","*.d.ts","llama.cpp/"],"react-native":"src/index","codegenConfig":{"name":"RNLlamaSpec","type":"modules","jsSrcsDir":"src"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^28.1.1","react":"18.2.0","eslint":"^8.4.1","del-cli":"^5.0.0","typedoc":"^0.24.7","prettier":"^2.0.5","commitlint":"^17.0.2","release-it":"^15.0.0","typescript":"^5.0.2","@types/jest":"^28.1.2","pod-install":"^0.1.0","@types/react":"~17.0.21","react-native":"0.72.3","@types/react-native":"0.70.0","@evilmartians/lefthook":"^1.2.2","typedoc-plugin-markdown":"^3.15.3","react-native-builder-bob":"^0.37.0","@fugood/eslint-config-react":"^0.5.0","@commitlint/config-conventional":"^17.0.2","@release-it/conventional-changelog":"^5.0.0","@react-native-community/eslint-config":"^3.0.2"},"peerDependencies":{"react":"*","react-native":"*"},"_npmOperationalInternal":{"tmp":"tmp/llama.rn_0.6.8_1755282585499_0.3670906375009173","host":"s3://npm-registry-packages-npm-production"},"react-native-builder-bob":{"output":"lib","source":"src","targets":["commonjs","module",["typescript",{"project":"tsconfig.build.json"}]]}},"0.6.16":{"name":"@bariscelik/llama.rn","version":"0.6.16","keywords":["react-native","ios","android","large language model","LLM","Local LLM","llama.cpp","llama","llama-2"],"author":{"url":"https://github.com/mybigday","name":"Jhen-Jie Hong","email":"developer@jhen.me"},"license":"MIT","_id":"@bariscelik/llama.rn@0.6.16","maintainers":[{"name":"bariscelik","email":"bariscelikweb@gmail.com"}],"homepage":"https://github.com/bariscelik/llama.rn#readme","bugs":{"url":"https://github.com/bariscelik/llama.rn/issues"},"dist":{"shasum":"d6c620d75f54632fd224992ef36faf867bc425e5","tarball":"https://registry.npmjs.org/@bariscelik/llama.rn/-/llama.rn-0.6.16.tgz","fileCount":456,"integrity":"sha512-rPfFfdCjMRA5BWDlU3OZGrHdHfBJygwUnxX5GBiWztq2doGBv1wR+z8vwfBuJP8k1h7+ohLS7St6FlWq5O2xHQ==","signatures":[{"sig":"MEYCIQCrSdGxdo2nThFE6FHQjDzRKVwkZ86iMb9vhLTJPP9PCwIhAMIMzwbEuv6tuy5P1IvQBx/iP4HXia1zqKQIHJhHFQBi","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":583309745},"jest":{"preset":"react-native","modulePathIgnorePatterns":["<rootDir>/example/node_modules","<rootDir>/lib/"]},"main":"lib/commonjs/index","types":"lib/typescript/index.d.ts","module":"lib/module/index","source":"src/index","engines":{"node":">= 16.0.0"},"gitHead":"b500e4abb36b2ed13e14f8d53c92eb30e28555db","scripts":{"lint":"eslint \"**/*.{js,ts,tsx}\"","test":"jest","build":"bob build","clean":"del-cli example/ios/build","docgen":"typedoc src/index.ts --plugin typedoc-plugin-markdown --readme none --out docs/API","example":"npm --prefix example","prepack":"./scripts/build-ios.sh && ./scripts/build-android.sh && bob build","release":"release-it","bootstrap":"./scripts/bootstrap.sh","build:ios":"cd example/ios && xcodebuild -workspace RNLlamaExample.xcworkspace -scheme RNLlamaExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO","typecheck":"tsc --noEmit","build:android":"cd example/android && ./gradlew assembleDebug","build:android-libs":"./scripts/build-android.sh","build:ios-frameworks":"./scripts/build-ios.sh"},"_npmUser":{"name":"bariscelik","email":"bariscelikweb@gmail.com"},"prettier":{"semi":false,"tabWidth":2,"printWidth":80,"singleQuote":true,"trailingComma":"all"},"commitlint":{"extends":["@commitlint/config-conventional"]},"release-it":{"git":{"tagName":"v${version}","commitMessage":"chore: release ${version}"},"npm":{"publish":true,"skipChecks":true},"github":{"release":true},"plugins":{"@release-it/conventional-changelog":{"preset":"angular"}}},"repository":{"url":"git+https://github.com/bariscelik/llama.rn.git","type":"git"},"_npmVersion":"11.5.2","description":"React Native binding of llama.cpp","directories":{},"resolutions":{"@types/react":"17.0.21"},"_nodeVersion":"23.10.0","eslintConfig":{"env":{"jest":true,"browser":true},"rules":{"global-require":0,"react/no-array-index-key":0},"extends":"@fugood/eslint-config-react","globals":{},"settings":{"import/resolver":{"node":{"extensions":[".js",".jsx",".ts",".tsx"]}}},"overrides":[{"files":["*.ts","*.tsx"],"rules":{"no-undef":"off","no-shadow":"off","no-unused-vars":"off","func-call-spacing":"off","import/extensions":["error","ignorePackages",{"js":"never","ts":"never","jsx":"never","tsx":"never"}],"react/require-default-props":"off","@typescript-eslint/no-shadow":1,"react/jsx-filename-extension":[1,{"extensions":[".js",".jsx",".tsx"]}],"@typescript-eslint/no-unused-vars":["error",{"argsIgnorePattern":"^_","destructuredArrayIgnorePattern":"^_"}],"@typescript-eslint/func-call-spacing":1},"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint/eslint-plugin"]}]},"eslintIgnore":["node_modules/","lib/","*.d.ts","llama.cpp/"],"react-native":"src/index","codegenConfig":{"name":"RNLlamaSpec","type":"modules","jsSrcsDir":"src"},"publishConfig":{"registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^28.1.1","react":"18.2.0","eslint":"^8.4.1","del-cli":"^5.0.0","typedoc":"^0.24.7","prettier":"^2.0.5","commitlint":"^17.0.2","release-it":"^15.0.0","typescript":"^5.0.2","@types/jest":"^28.1.2","pod-install":"^0.1.0","@types/react":"~17.0.21","react-native":"0.72.3","@types/react-native":"0.70.0","@evilmartians/lefthook":"^1.2.2","typedoc-plugin-markdown":"^3.15.3","react-native-builder-bob":"^0.37.0","@fugood/eslint-config-react":"^0.5.0","@commitlint/config-conventional":"^17.0.2","@release-it/conventional-changelog":"^5.0.0","@react-native-community/eslint-config":"^3.0.2"},"peerDependencies":{"react":"*","react-native":"*"},"_npmOperationalInternal":{"tmp":"tmp/llama.rn_0.6.16_1758292842305_0.7474739462535231","host":"s3://npm-registry-packages-npm-production"},"react-native-builder-bob":{"output":"lib","source":"src","targets":["commonjs","module",["typescript",{"project":"tsconfig.build.json"}]]}},"0.6.17":{"name":"@bariscelik/llama.rn","version":"0.6.17","description":"React Native binding of llama.cpp","main":"lib/commonjs/index","module":"lib/module/index","types":"lib/typescript/index.d.ts","react-native":"src/index","source":"src/index","scripts":{"bootstrap":"./scripts/bootstrap.sh","docgen":"typedoc src/index.ts --plugin typedoc-plugin-markdown --readme none --out docs/API","test":"jest","typecheck":"tsc --noEmit","lint":"eslint \"**/*.{js,ts,tsx}\"","build":"bob build","prepack":"./scripts/build-ios.sh && ./scripts/build-android.sh && bob build","release":"release-it","example":"npm --prefix example","build:ios-frameworks":"./scripts/build-ios.sh","build:ios":"cd example/ios && xcodebuild -workspace RNLlamaExample.xcworkspace -scheme RNLlamaExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO","build:android-libs":"./scripts/build-android.sh","build:android":"cd example/android && ./gradlew assembleDebug","clean":"del-cli example/ios/build"},"keywords":["react-native","ios","android","large language model","LLM","Local LLM","llama.cpp","llama","llama-2"],"repository":{"type":"git","url":"git+https://github.com/bariscelik/llama.rn.git"},"author":{"name":"Jhen-Jie Hong","email":"developer@jhen.me","url":"https://github.com/mybigday"},"license":"MIT","bugs":{"url":"https://github.com/bariscelik/llama.rn/issues"},"homepage":"https://github.com/bariscelik/llama.rn#readme","publishConfig":{"registry":"https://registry.npmjs.org/"},"devDependencies":{"@commitlint/config-conventional":"^17.0.2","@evilmartians/lefthook":"^1.2.2","@fugood/eslint-config-react":"^0.5.0","@react-native-community/eslint-config":"^3.0.2","@release-it/conventional-changelog":"^5.0.0","@types/jest":"^28.1.2","@types/react":"~17.0.21","@types/react-native":"0.70.0","commitlint":"^17.0.2","del-cli":"^5.0.0","eslint":"^8.4.1","jest":"^28.1.1","pod-install":"^0.1.0","prettier":"^2.0.5","react":"18.2.0","react-native":"0.72.3","react-native-builder-bob":"^0.37.0","release-it":"^15.0.0","typedoc":"^0.24.7","typedoc-plugin-markdown":"^3.15.3","typescript":"^5.0.2"},"resolutions":{"@types/react":"17.0.21"},"peerDependencies":{"react":"*","react-native":"*"},"engines":{"node":">= 16.0.0"},"jest":{"preset":"react-native","modulePathIgnorePatterns":["<rootDir>/example/node_modules","<rootDir>/lib/"]},"commitlint":{"extends":["@commitlint/config-conventional"]},"release-it":{"git":{"commitMessage":"chore: release ${version}","tagName":"v${version}"},"npm":{"publish":true,"skipChecks":true},"github":{"release":true},"plugins":{"@release-it/conventional-changelog":{"preset":"angular"}}},"eslintConfig":{"extends":"@fugood/eslint-config-react","env":{"browser":true,"jest":true},"globals":{},"rules":{"react/no-array-index-key":0,"global-require":0},"overrides":[{"files":["*.ts","*.tsx"],"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint/eslint-plugin"],"rules":{"@typescript-eslint/no-unused-vars":["error",{"argsIgnorePattern":"^_","destructuredArrayIgnorePattern":"^_"}],"no-unused-vars":"off","no-shadow":"off","@typescript-eslint/no-shadow":1,"no-undef":"off","func-call-spacing":"off","@typescript-eslint/func-call-spacing":1,"import/extensions":["error","ignorePackages",{"js":"never","jsx":"never","ts":"never","tsx":"never"}],"react/jsx-filename-extension":[1,{"extensions":[".js",".jsx",".tsx"]}],"react/require-default-props":"off"}}],"settings":{"import/resolver":{"node":{"extensions":[".js",".jsx",".ts",".tsx"]}}}},"eslintIgnore":["node_modules/","lib/","*.d.ts","llama.cpp/"],"prettier":{"trailingComma":"all","tabWidth":2,"semi":false,"singleQuote":true,"printWidth":80},"react-native-builder-bob":{"source":"src","output":"lib","targets":["commonjs","module",["typescript",{"project":"tsconfig.build.json"}]]},"codegenConfig":{"name":"RNLlamaSpec","type":"modules","jsSrcsDir":"src"},"_id":"@bariscelik/llama.rn@0.6.17","gitHead":"34296c54651f86c1d55f505918b5066780603f50","_nodeVersion":"23.10.0","_npmVersion":"11.5.2","dist":{"integrity":"sha512-ykttr59xv2w0VjdXr1F2tlf/A5ps05B2uV2FQVM6f0yqQiSaOHnUMGYBFQL/ifg2AoeVY6Ie7QiuMXXYt8vyfQ==","shasum":"c5d698b8fd83535b7c01ad869b51ca96df58c5ec","tarball":"https://registry.npmjs.org/@bariscelik/llama.rn/-/llama.rn-0.6.17.tgz","fileCount":456,"unpackedSize":582983345,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDloRcbGDccpSJTNYRCZXwzOkxZJczGL9gpUto5k/b66QIgD2IJ5XnKU1OIqcIuzHIJZ21PQg2qN1WolV10EeTqKa8="}]},"_npmUser":{"name":"bariscelik","email":"bariscelikweb@gmail.com"},"directories":{},"maintainers":[{"name":"bariscelik","email":"bariscelikweb@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/llama.rn_0.6.17_1758295830728_0.5419660931972328"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-15T18:29:45.380Z","modified":"2025-09-19T15:30:32.806Z","0.6.8":"2025-08-15T18:29:45.950Z","0.6.16":"2025-09-19T14:40:44.239Z","0.6.17":"2025-09-19T15:30:32.631Z"},"bugs":{"url":"https://github.com/bariscelik/llama.rn/issues"},"author":{"name":"Jhen-Jie Hong","email":"developer@jhen.me","url":"https://github.com/mybigday"},"license":"MIT","homepage":"https://github.com/bariscelik/llama.rn#readme","keywords":["react-native","ios","android","large language model","LLM","Local LLM","llama.cpp","llama","llama-2"],"repository":{"type":"git","url":"git+https://github.com/bariscelik/llama.rn.git"},"description":"React Native binding of llama.cpp","maintainers":[{"name":"bariscelik","email":"bariscelikweb@gmail.com"}],"readme":"# @bariscelik/llama.rn\n\n[![Actions Status](https://github.com/bariscelik/llama.rn/workflows/CI/badge.svg)](https://github.com/bariscelik/llama.rn/actions)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![npm](https://img.shields.io/npm/v/@bariscelik/llama.rn.svg)](https://www.npmjs.com/package/@bariscelik/llama.rn/)\n\nReact Native binding of [llama.cpp](https://github.com/ggerganov/llama.cpp).\n\n[llama.cpp](https://github.com/ggerganov/llama.cpp): Inference of [LLaMA](https://arxiv.org/abs/2302.13971) model in pure C/C++\n\n## Installation\n\n```sh\nnpm install @bariscelik/llama.rn\n```\n\n#### iOS\n\nPlease re-run `npx pod-install` again.\n\nBy default, `@bariscelik/llama.rn` will use pre-built `rnllama.xcframework` for iOS. If you want to build from source, please set `RNLLAMA_BUILD_FROM_SOURCE` to `1` in your Podfile.\n\n#### Android\n\nAdd proguard rule if it's enabled in project (android/app/proguard-rules.pro):\n\n```proguard\n# @bariscelik/llama.rn\n-keep class com.rnllama.** { *; }\n```\n\nBy default, `@bariscelik/llama.rn` will use pre-built libraries for Android. If you want to build from source, please set `rnllamaBuildFromSource` to `true` in `android/gradle.properties`.\n\n## Obtain the model\n\nYou can search HuggingFace for available models (Keyword: [`GGUF`](https://huggingface.co/search/full-text?q=GGUF&type=model)).\n\nFor get a GGUF model or quantize manually, see [`Prepare and Quantize`](https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#prepare-and-quantize) section in llama.cpp.\n\n## Usage\n\n> **💡** You can find complete examples in the [example](example) project.\n\nLoad model info only:\n\n```js\nimport { loadLlamaModelInfo } from '@bariscelik/llama.rn'\n\nconst modelPath = 'file://<path to gguf model>'\nconsole.log('Model Info:', await loadLlamaModelInfo(modelPath))\n```\n\nInitialize a Llama context & do completion:\n\n```js\nimport { initLlama } from '@bariscelik/llama.rn'\n\n// Initial a Llama context with the model (may take a while)\nconst context = await initLlama({\n  model: modelPath,\n  use_mlock: true,\n  n_ctx: 2048,\n  n_gpu_layers: 99, // number of layers to store in VRAM (Currently only for iOS)\n  // embedding: true, // use embedding\n})\n\nconst stopWords = ['</s>', '<|end|>', '<|eot_id|>', '<|end_of_text|>', '<|im_end|>', '<|EOT|>', '<|END_OF_TURN_TOKEN|>', '<|end_of_turn|>', '<|endoftext|>']\n\n// Do chat completion\nconst msgResult = await context.completion(\n  {\n    messages: [\n      {\n        role: 'system',\n        content: 'This is a conversation between user and assistant, a friendly chatbot.',\n      },\n      {\n        role: 'user',\n        content: 'Hello!',\n      },\n    ],\n    n_predict: 100,\n    stop: stopWords,\n    // ...other params\n  },\n  (data) => {\n    // This is a partial completion callback\n    const { token } = data\n  },\n)\nconsole.log('Result:', msgResult.text)\nconsole.log('Timings:', msgResult.timings)\n\n// Or do text completion\nconst textResult = await context.completion(\n  {\n    prompt: 'This is a conversation between user and llama, a friendly chatbot. respond in simple markdown.\\n\\nUser: Hello!\\nLlama:',\n    n_predict: 100,\n    stop: [...stopWords, 'Llama:', 'User:'],\n    // ...other params\n  },\n  (data) => {\n    // This is a partial completion callback\n    const { token } = data\n  },\n)\nconsole.log('Result:', textResult.text)\nconsole.log('Timings:', textResult.timings)\n```\n\nThe binding's deisgn inspired by [server.cpp](https://github.com/ggerganov/llama.cpp/tree/master/examples/server) example in llama.cpp:\n\n- `/completion` and `/chat/completions`: `context.completion(params, partialCompletionCallback)`\n- `/tokenize`: `context.tokenize(content)`\n- `/detokenize`: `context.detokenize(tokens)`\n- `/embedding`: `context.embedding(content)`\n- `/rerank`: `context.rerank(query, documents, params)`\n- ... Other methods\n\nPlease visit the [Documentation](docs/API) for more details.\n\nYou can also visit the [example](example) to see how to use it.\n\n## Multimodal (Vision & Audio)\n\n`llama.rn` supports multimodal capabilities including vision (images) and audio processing. This allows you to interact with models that can understand both text and media content.\n\n### Supported Media Formats\n\n**Images (Vision):**\n- JPEG, PNG, BMP, GIF, TGA, HDR, PIC, PNM\n- Base64 encoded images (data URLs)\n- Local file paths\n- \\* Not supported HTTP URLs yet\n\n**Audio:**\n- WAV, MP3 formats\n- Base64 encoded audio (data URLs)\n- Local file paths\n- \\* Not supported HTTP URLs yet\n\n### Setup\n\nFirst, you need a multimodal model and its corresponding multimodal projector (mmproj) file, see [how to obtain mmproj](https://github.com/ggml-org/llama.cpp/tree/master/tools/mtmd#how-to-obtain-mmproj) for more details.\n\n### Initialize Multimodal Support\n\n```js\nimport { initLlama } from '@bariscelik/llama.rn'\n\n// First initialize the model context\nconst context = await initLlama({\n  model: 'path/to/your/multimodal-model.gguf',\n  n_ctx: 4096,\n  n_gpu_layers: 99, // Recommended for multimodal models\n  // Important: Disable context shifting for multimodal\n  ctx_shift: false,\n})\n\n// Initialize multimodal support with mmproj file\nconst success = await context.initMultimodal({\n  path: 'path/to/your/mmproj-model.gguf',\n  use_gpu: true, // Recommended for better performance\n})\n\n// Check if multimodal is enabled\nconsole.log('Multimodal enabled:', await context.isMultimodalEnabled())\n\nif (success) {\n  console.log('Multimodal support initialized!')\n\n  // Check what modalities are supported\n  const support = await context.getMultimodalSupport()\n  console.log('Vision support:', support.vision)\n  console.log('Audio support:', support.audio)\n} else {\n  console.log('Failed to initialize multimodal support')\n}\n\n// Release multimodal context\nawait context.releaseMultimodal()\n```\n\n### Usage Examples\n\n#### Vision (Image Processing)\n\n```js\nconst result = await context.completion({\n  messages: [\n    {\n      role: 'user',\n      content: [\n        {\n          type: 'text',\n          text: 'What do you see in this image?',\n        },\n        {\n          type: 'image_url',\n          image_url: {\n            url: 'file:///path/to/image.jpg',\n            // or base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD...'\n          },\n        },\n      ],\n    },\n  ],\n  n_predict: 100,\n  temperature: 0.1,\n})\n\nconsole.log('AI Response:', result.text)\n```\n\n#### Audio Processing\n\n```js\n// Method 1: Using structured message content (Recommended)\nconst result = await context.completion({\n  messages: [\n    {\n      role: 'user',\n      content: [\n        {\n          type: 'text',\n          text: 'Transcribe or describe this audio:',\n        },\n        {\n          type: 'input_audio',\n          input_audio: {\n            data: 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10...',\n            // or url: 'file:///path/to/audio.wav',\n            format: 'wav', // or 'mp3'\n          },\n        },\n      ],\n    },\n  ],\n  n_predict: 200,\n})\n\nconsole.log('Transcription:', result.text)\n```\n\n### Tokenization with Media\n\n```js\n// Tokenize text with media\nconst tokenizeResult = await context.tokenize(\n  'Describe this image: <__media__>',\n  {\n    media_paths: ['file:///path/to/image.jpg']\n  }\n)\n\nconsole.log('Tokens:', tokenizeResult.tokens)\nconsole.log('Has media:', tokenizeResult.has_media)\nconsole.log('Media positions:', tokenizeResult.chunk_pos_media)\n```\n\n### Notes\n\n- **Context Shifting**: Multimodal models require `ctx_shift: false` to maintain media token positioning\n- **Memory**: Multimodal models require more memory; use adequate `n_ctx` and consider GPU offloading\n- **Media Markers**: The system automatically handles `<__media__>` markers in prompts. When using structured message content, media items are automatically replaced with this marker\n- **Model Compatibility**: Ensure your model supports the media type you're trying to process\n\n## Tool Calling\n\n`llama.rn` has universal tool call support by using [minja](https://github.com/google/minja) (as Jinja template parser) and [chat.cpp](https://github.com/ggerganov/llama.cpp/blob/master/common/chat.cpp) in llama.cpp.\n\nExample:\n\n```js\nimport { initLlama } from '@bariscelik/llama.rn'\n\nconst context = await initLlama({\n  // ...params\n})\n\nconst { text, tool_calls } = await context.completion({\n  // ...params\n  jinja: true, // Enable Jinja template parser\n  tool_choice: 'auto',\n  tools: [\n    {\n      type: 'function',\n      function: {\n        name: 'ipython',\n        description:\n          'Runs code in an ipython interpreter and returns the result of the execution after 60 seconds.',\n        parameters: {\n          type: 'object',\n          properties: {\n            code: {\n              type: 'string',\n              description: 'The code to run in the ipython interpreter.',\n            },\n          },\n          required: ['code'],\n        },\n      },\n    },\n  ],\n  messages: [\n    {\n      role: 'system',\n      content: 'You are a helpful assistant that can answer questions and help with tasks.',\n    },\n    {\n      role: 'user',\n      content: 'Test',\n    },\n  ],\n})\nconsole.log('Result:', text)\n// If tool_calls is not empty, it means the model has called the tool\nif (tool_calls) console.log('Tool Calls:', tool_calls)\n```\n\nYou can check [chat.cpp](https://github.com/ggerganov/llama.cpp/blob/6eecde3cc8fda44da7794042e3668de4af3c32c6/common/chat.cpp#L7-L23) for models has native tool calling support, or it will fallback to `GENERIC` type tool call.\n\nThe generic tool call will be always JSON object as output, the output will be like `{\"response\": \"...\"}` when it not decided to use tool call.\n\n## Grammar Sampling\n\nGBNF (GGML BNF) is a format for defining [formal grammars](https://en.wikipedia.org/wiki/Formal_grammar) to constrain model outputs in `llama.cpp`. For example, you can use it to force the model to generate valid JSON, or speak only in emojis.\n\nYou can see [GBNF Guide](https://github.com/ggerganov/llama.cpp/tree/master/grammars) for more details.\n\n`llama.rn` provided a built-in function to convert JSON Schema to GBNF:\n\nExample gbnf grammar:\n```bnf\nroot   ::= object\nvalue  ::= object | array | string | number | (\"true\" | \"false\" | \"null\") ws\n\nobject ::=\n  \"{\" ws (\n            string \":\" ws value\n    (\",\" ws string \":\" ws value)*\n  )? \"}\" ws\n\narray  ::=\n  \"[\" ws (\n            value\n    (\",\" ws value)*\n  )? \"]\" ws\n\nstring ::=\n  \"\\\"\" (\n    [^\"\\\\\\x7F\\x00-\\x1F] |\n    \"\\\\\" ([\"\\\\bfnrt] | \"u\" [0-9a-fA-F]{4}) # escapes\n  )* \"\\\"\" ws\n\nnumber ::= (\"-\"? ([0-9] | [1-9] [0-9]{0,15})) (\".\" [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws\n\n# Optional space: by convention, applied in this grammar after literal chars when allowed\nws ::= | \" \" | \"\\n\" [ \\t]{0,20}\n```\n\n```js\nimport { initLlama } from '@bariscelik/llama.rn'\n\nconst gbnf = '...'\n\nconst context = await initLlama({\n  // ...params\n  grammar: gbnf,\n})\n\nconst { text } = await context.completion({\n  // ...params\n  messages: [\n    {\n      role: 'system',\n      content: 'You are a helpful assistant that can answer questions and help with tasks.',\n    },\n    {\n      role: 'user',\n      content: 'Test',\n    },\n  ],\n})\nconsole.log('Result:', text)\n```\n\nAlso, this is how `json_schema` works in `response_format` during completion, it converts the json_schema to gbnf grammar.\n\n## Session (State)\n\nThe session file is a binary file that contains the state of the context, it can saves time of prompt processing.\n\n```js\nconst context = await initLlama({ ...params })\n\n// After prompt processing or completion ...\n\n// Save the session\nawait context.saveSession('<path to save session>')\n\n// Load the session\nawait context.loadSession('<path to load session>')\n```\n\n### Notes\n\n- \\* Session is currently not supported save state from multimodal context, so it only stores the text chunk before the first media chunk.\n\n## Embedding\n\nThe embedding API is used to get the embedding of a text.\n\n```js\nconst context = await initLlama({\n  ...params,\n  embedding: true,\n})\n\nconst { embedding } = await context.embedding('Hello, world!')\n```\n\n- You can use model like [nomic-ai/nomic-embed-text-v1.5-GGUF](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF) for better embedding quality.\n- You can use DB like [op-sqlite](https://github.com/OP-Engineering/op-sqlite) with sqlite-vec support to store and search embeddings.\n\n## Rerank\n\nThe rerank API is used to rank documents based on their relevance to a query. This is particularly useful for improving search results and implementing retrieval-augmented generation (RAG) systems.\n\n```js\nconst context = await initLlama({\n  ...params,\n  embedding: true, // Required for reranking\n  pooling_type: 'rank', // Use rank pooling for rerank models\n})\n\n// Rerank documents based on relevance to query\nconst results = await context.rerank(\n  'What is artificial intelligence?', // query\n  [\n    'AI is a branch of computer science.',\n    'The weather is nice today.',\n    'Machine learning is a subset of AI.',\n    'I like pizza.',\n  ], // documents to rank\n  {\n    normalize: 1, // Optional: normalize scores (default: from model config)\n  }\n)\n\n// Results are automatically sorted by score (highest first)\nresults.forEach((result, index) => {\n  console.log(`Rank ${index + 1}:`, {\n    score: result.score,\n    document: result.document,\n    originalIndex: result.index,\n  })\n})\n```\n\n### Notes\n\n- **Model Requirements**: Reranking requires models with `RANK` pooling type (e.g., reranker models)\n- **Embedding Enabled**: The context must have `embedding: true` to use rerank functionality\n- **Automatic Sorting**: Results are returned sorted by relevance score in descending order\n- **Document Access**: Each result includes the original document text and its index in the input array\n- **Score Interpretation**: Higher scores indicate higher relevance to the query\n\n### Recommended Models\n\n- [jinaai - jina-reranker-v2-base-multilingual-GGUF](https://huggingface.co/gpustack/jina-reranker-v2-base-multilingual-GGUF)\n- [BAAI - bge-reranker-v2-m3-GGUF](https://huggingface.co/gpustack/bge-reranker-v2-m3-GGUF)\n- Other models with \"rerank\" or \"reranker\" in their name and GGUF format\n\n## Mock `llama.rn`\n\nWe have provided a mock version of `llama.rn` for testing purpose you can use on Jest:\n\n```js\njest.mock('llama.rn', () => require('llama.rn/jest/mock'))\n```\n\n## NOTE\n\niOS:\n\n- The [Extended Virtual Addressing](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_kernel_extended-virtual-addressing) and [Increased Memory Limit](https://developer.apple.com/documentation/bundleresources/entitlements/com.apple.developer.kernel.increased-memory-limit?language=objc) capabilities are recommended to enable on iOS project.\n- Metal:\n  - We have tested to know some devices is not able to use Metal (GPU) due to llama.cpp used SIMD-scoped operation, you can check if your device is supported in [Metal feature set tables](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf), Apple7 GPU will be the minimum requirement.\n  - It's also not supported in iOS simulator due to [this limitation](https://developer.apple.com/documentation/metal/developing_metal_apps_that_run_in_simulator#3241609), we used constant buffers more than 14.\n\nAndroid:\n\n- Currently only supported arm64-v8a / x86_64 platform, this means you can't initialize a context on another platforms. The 64-bit platform are recommended because it can allocate more memory for the model.\n- No integrated any GPU backend yet.\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## Apps using `llama.rn`\n\n- [BRICKS](https://bricks.tools): Our product for building interactive signage in simple way. We provide LLM functions as Generator LLM/Assistant.\n- [ChatterUI](https://github.com/Vali-98/ChatterUI): Simple frontend for LLMs built in react-native.\n- [PocketPal AI](https://github.com/a-ghorbani/pocketpal-ai): An app that brings language models directly to your phone.\n\n## Node.js binding\n\n- [llama.node](https://github.com/mybigday/llama.node): An another Node.js binding of `llama.cpp` but made API same as `llama.rn`.\n\n## License\n\nMIT\n\n---\n\nMade with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)\n\n---\n\n<p align=\"center\">\n  <a href=\"https://bricks.tools\">\n    <img width=\"90px\" src=\"https://avatars.githubusercontent.com/u/17320237?s=200&v=4\">\n  </a>\n  <p align=\"center\">\n    Built and maintained by <a href=\"https://bricks.tools\">BRICKS</a>.\n  </p>\n</p>\n","readmeFilename":"README.md"}