npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-llm-mediapipe

v0.5.0

Published

Run an LLM on iOS & Android devices using React Native

Downloads

69

Readme

react-native-llm-mediapipe

react-native-llm-mediapipe enables developers to run large language models (LLMs) on iOS and Android devices using React Native. This package allows you to write JavaScript or TypeScript to handle LLM inference directly on mobile platforms.

Features

  • Run LLM Inference: Perform natural language processing tasks directly on mobile devices.
  • React Native Integration: Seamlessly integrates with your existing React Native projects.
  • JavaScript/TypeScript Support: Use familiar technologies to control LLM functionality.

Installation

To get started with react-native-llm-mediapipe, install the package using npm or yarn:

npm install react-native-llm-mediapipe

or

yarn add react-native-llm-mediapipe

Requirements

Before using this package, you must download or build the LLM model files necessary for its operation. Ensure these model files are properly configured and accessible by your mobile application. Some instructions can be found on the MediaPipe page. Or, see below for running a script that will download and convert the model files, automating the process

Building Models

As of 4/22/2024, MediaPipe supports four models for use on-device: Gemma 2B, Falcon 1B, StableLM 3B, and Phi-2. To download and convert the models, follow the instructions above or clone this (react-native-llm-mediapipe) repo, and follow the instructions here.

Usage

The primary functionality of this package is accessed through the useLlmInference() hook. This hook provides a generateResponse function, which you can use to process text prompts. Here is a basic example of how to use it in a React Native app:

import React, { useState } from 'react';
import { View, TextInput, Button, Text } from 'react-native';
import { useLlmInference } from 'react-native-llm-mediapipe';

const App = () => {
  const [prompt, setPrompt] = useState('');
  const { generateResponse } = useLlmInference();

  const handleGeneratePress = async () => {
    const response = await generateResponse(prompt);
    alert(response); // Display the LLM's response
  };

  return (
    <View style={{ padding: 20 }}>
      <TextInput
        style={{
          height: 40,
          borderColor: 'gray',
          borderWidth: 1,
          marginBottom: 10,
        }}
        onChangeText={setPrompt}
        value={prompt}
        placeholder="Enter your prompt here"
      />
      <Button title="Generate Response" onPress={handleGeneratePress} />
    </View>
  );
};

export default App;

In addition, you can access partial results by supplying a callback to generateResponse()

   const response = await llmInference.generateResponse(
      prompt,
      (partial) => {
        setPartialResponse((prev) => prev + partial));
      }
    );

Contributing

Contributions are very welcome! If you would like to improve react-native-llm-mediapipe, please feel free to fork the repository, make changes, and submit a pull request. You can also open an issue if you find bugs or have feature requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, feature requests, or any other inquiries, please open an issue on the GitHub project page.