Git Product home page Git Product logo

react-native-ai's Introduction

Ceasefire Now

React Native AI

Full stack framework for building cross-platform mobile AI apps supporting LLM real-time / streaming text and chat UIs, image services and natural language to images with multiple models, and image processing.

React Native AI

Check out the video tutorial here

Features

  • LLM support for OpenAI ChatGPT, Anthropic Claude, Cohere, Cohere Web, Gemini, and Mistral
  • An array of image models provided by Fal.ai
  • Real-time / streaming responses from all providers
  • OpenAI Assistants including code interpreter and retrieval
  • Server proxy to easily enable authentication and authorization with auth provider of choice.
  • Theming (comes out of the box with 5 themes) - easily add additional themes with just a few lines of code.
  • Image processing with ByteScale

React Native AI Preview

Usage

Generate a new project by running:

npx rn-ai

Next, either configure your environment variables with the CLI, or do so later.

Running the app

Change into the app directory and run:

npm start

Running the server

Change into the server directory and run:

npm run dev

Theming

To add a new theme, open app/src/theme.ts and add a new theme with the following configuration:

const christmas = {
  // extend an existing theme or start from scratch
  ...lightTheme,
  name: 'Christmas',
  label: 'christmas',
  tintColor: '#ff0000',
  textColor: '#378b29',
  tabBarActiveTintColor: '#378b29',
  tabBarInactiveTintColor: '#ff0000',
  placeholderTextColor: '#378b29',
}

At the bottom of the file, export the new theme:

export {
  lightTheme, darkTheme, hackerNews, miami, vercel, christmas
}

React Native AI Themes

Configuring LLM Models

Here is how to add new or remove existing LLM models.

In the app

You can add or configure a model by updating MODELS in constants.ts.

For removing models, just remove the models you do not want to support.

For adding models, once the model definition is added to the MODELS array, you should update src/screens/chat.tsx to support the new model:

  1. Create local state to hold new model data
  2. Update chat() function to handle new model type
  3. Create generateModelReponse function to call new model
  4. Update getChatType in utils.ts to configure the LLM type that will correspond with your server path.
  5. Render new model in UI
{
  chatType.label.includes('newModel') && (
    <FlatList
      data={newModelReponse.messages}
      renderItem={renderItem}
      scrollEnabled={false}
    />
  )
}

On the server

Create a new file in the server/src/chat folder that corresponds to the model type you created in the mobile app. You can probably copy and re-use a lot of the streaming code from the other existing paths to get you started.

Next, update server/src/chat/chatRouter to use the new route.

Configuring Image Models

Here is how to add new or remove existing Image models.

In the app

You can add or configure a model by updating IMAGE_MODELS in constants.ts.

For removing models, just remove the models you do not want to support.

For adding models, once the model definition is add to the IMAGE_MODELS array, you should update src/screens/images.tsx to support the new model.

Main consideration is input. Does the model take text, image, or both as inputs?

The app is configured to handle both, but you must update the generate function to pass the values to the API accordingly.

On the server

Fal.ai

In server/src/images/fal, update the handler function to take into account the new model.

Other API providers

Create a new file in server/src/images/modelName, update the handler function to handle the new API call.

Next, update server/src/images/imagesRouter to use the new route.

react-native-ai's People

Contributors

akkikumar72 avatar catalinmiron avatar dabit3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-ai's Issues

Breaking the git linkage

When I used npx rn-ai to create a test app and attempt to upload it to my Github, which means it has been linked to your repo.

I could fix it manually and upload it, but it's a little stressful and you might as well fix it.

Thanks.

Type error on server console. (No response on iOS client). Using gpt3.5 turbo)

Fresh install. iOS client not responding keeps spinning. Node version 18.17.1.

App console eventually shows " ERROR Connection error: The network connection was lost."

Server console output below:

[1] [nodemon] restarting due to changes...
[1] [nodemon] restarting due to changes...
[1] [nodemon] restarting due to changes...
[1] [nodemon] starting `node dist/index.js`
[1] Server started on port 3050
[1] error:  TypeError: Cannot read properties of undefined (reading '0')
[1]     at /Users/.../rn-ai/server/dist/chat/gpt.js:73:46
[1]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Server Not Found Error on iPhone Expo Go

Server is running on port 3050.

Then on my iPhone, I bring up the app by going to the camera and then scanning the QR code.

The chat interface loads.

Attempting to chat produces the following error:


Logs for your project will appear below. Press Ctrl+C to exit.
iOS Bundling complete 4477ms
 LOG  about to open listener...
 ERROR  Connection error: Could not connect to the server.

TypeError: Cannot read property 'backgroundColor' of undefined


This error is located at:
in MainComponent (created by Main)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by Main)
in Main (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in RCTView (created by View)
in View (at CustomActionSheet.tsx:91)
in RCTView (created by View)
in View (at CustomActionSheet.tsx:99)
in CustomActionSheet (at ActionSheetProvider.tsx:49)
in ActionSheetProvider (created by App)
in RNGestureHandlerRootView (created by GestureHandlerRootView)
in GestureHandlerRootView (created by App)
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes

The same template was working a few days ago. Today when I started a new project with 'npx rn-ai' and started the expo server, I got the above error.

Web version error in Expo Go

Error below:


› Using Expo Go
› Press s │ switch to development build

› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web

› Press j │ open debugger
› Press r │ reload app
› Press m │ toggle menu
› Press o │ open project code in your editor

› Press ? │ show all commands

› Open in the web browser...
› Press ? │ show all commands
(node:88282) [DEP_WEBPACK_DEV_SERVER_CONSTRUCTOR] DeprecationWarning: Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:88282) [DEP_WEBPACK_DEV_SERVER_LISTEN] DeprecationWarning: 'listen' is deprecated. Please use the async 'start' or 'startCallback' method.
ERROR in ./node_modules/react-native/Libraries/LogBox/LogBox.js:14
Module not found: Can't resolve '../Utilities/Platform'
  12 | import type {ExtendedExceptionData} from './Data/parseLogBoxLog';
  13 |
> 14 | import Platform from '../Utilities/Platform';
  15 | import RCTLog from '../Utilities/RCTLog';
  16 |
  17 | export type {LogData, ExtendedExceptionData, IgnorePattern};

ERROR in ./node_modules/@ronradtke/react-native-markdown-display/src/index.js 146:30
Module parse failed: Unexpected token (146:30)
File was processed with these loaders:
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
|     onLinkPress,
|     maxTopLevelChildren = null,
>     topLevelMaxExceededItem = <Text key="dotdotdot">...</Text>,
|     allowedImageHandlers = [
|       'data:image/png;base64',

web compiled with 2 errors

In the browser (Chrome) the following error is seen:

Uncaught Error: Module parse failed: Unexpected token (146:30)
File was processed with these loaders:
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
|     onLinkPress,
|     maxTopLevelChildren = null,
>     topLevelMaxExceededItem = <Text key="dotdotdot">...</Text>,
|     allowedImageHandlers = [
|       'data:image/png;base64',
    at ./node_modules/@ronradtke/react-native-markdown-display/src/index.js (logger.ts:47:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/screens/chat.tsx (assistant.tsx:791:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/screens/index.ts (images.tsx:608:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/main.tsx (context.tsx:21:1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.