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-openai-supabase

v1.0.2

Published

A ChatGPT React Native app to integrate it with Supabase Edge Function to call OpenAI APIs.

Downloads

138

Readme

react-native-openai-supabase

Create Your AI Chat Mobile App in 1 day

This repo is a fork from react-native-openai. Several changes are made to the original repo below.

  • API calls to openai were directly called from react-native app in the original repo, which forced the app to include openai API key and it was unsecure. This forked version calls supabase edge function instead and it forwards api calls to API endpoints at Openai.
  • Login logic in UI was changed to call Supabase auth.
  • You can create your custom prompt and instruct AI how it should behave at initial_system_prompt in packages/rn-openai-lib/src/app/config.ts.

The app is only tested on Android Playstore.

Sample App Demo

Clone this repo

$ git clone https://github.com/hiroshitashir/react-native-openai-supabase.git

Set up Supabase Edge Function

  • Check supabase docs for setting up edge function at Supabase8

  • The definition of the edge function can be found at packages/rn-openai-lib/supabase/functions/openai.

  • The edge function above uses Upstash's Redis for rate limiting api calls. Check Upstash doc for setting up.

  • Under packages/rn-openai-lib/supabase/functions/openai, you have to create .env file and it should contain four environment variables below.

    OPENAI_API_KEY=<Openai's api key>
    UPSTASH_REDIS_REST_URL="<Upstash's redit rest api url>"
    UPSTASH_REDIS_REST_TOKEN="<Upstash token for rest apis>"
    SUPABASE_SERVICE_KEY="<service key for supabase>"
  • Inside packages/rn-openai-lib/lib/supabase.ts, specify supabaseUrl and supabaseAnonKey. Check doc for details.

    const supabaseUrl = '<supabase project url>';
    const supabaseAnonKey = '<supabase key>';
  • For configuring which edge function to call from this react native app, specifiy the edge function name inside createChatComplete method in packages/rn-openai-lib/src/api/index.ts below.

    export async function createChatComplete({
      messages,
      appType,
    }: CreateChatCompleteParams): Promise<CreateChatCompleteResponse> {
      const { data, error } = await supabase.functions.invoke<ChatCompletion>(
        '<your supabase edge function name>',
        {
          body: { query: JSON.stringify(messages), appType: appType },
        }
      );

Create App

  • App examples can be found at /apps.
  1. First, create entries in APP_TYPE and configs inside packages/rn-openai-lib/src/app/config.ts.
  2. Then, copy a directory under /apps.
  3. In apps//app/index.ts, pass your APP_TYPE. to configureApp.
  4. In apps//app.config.js, adjust string 'ai-your app name-assistant' and 'com.aiassistant.your app name'.

Set Up RevenueCat

Start App

  • From apps/<your app name> directory, run yarn to install libraries.

    $ yarn

  • To start, run the expo command below. Check doc for details.

    $ npx expo start

Build & Deploy App

  • The app uses Expo's EAS. Check doc for more details. Build the app with the command below.

    eas build --profile production --platform android --clear-cache

  • Submit your app by running the command below.

    eas submit --platform android

  • Follow doc for more details.

Disclaimer

This is not an official ChatGPT library. It's an effort to make it easier to integrate ChatGPT with React Native applications. As such, please treat it as experimental and use it with caution in production :wink:.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Credits

License

MIT

If you found this project interesting, please consider following me on twitter