replicate / replicate-javascript

Node.js client for Replicate
https://replicate.com/docs/get-started/nodejs
Apache License 2.0
493 stars 203 forks source link

API not working on Expo SDK 51 project #303

Open Ahelsamahy opened 2 months ago

Ahelsamahy commented 2 months ago

Hi all,

I have an Expo application that I created from scratch npx create-expo-app@latest ./ --template and added a function to touch LLama model with this.

import Replicate from 'replicate';

export async function getStreamOutput() {
    const replicate = new Replicate({
        auth: process.env.EXPO_PUBLIC_REPLICATE_API,
    });

    const input = {
        prompt: "Tina has one brother and one sister. How many sisters do Tina's siblings have?",
        max_tokens: 1024,
    };

    try {
        // Run the model and return the result without streaming
        const output = await replicate.run('meta/meta-llama-3.1-405b-instruct', { input });
        return output.join("");  // Combine the output into a single string
    } catch (error) {
        console.error('Error getting prediction:', error);
        throw error;
    }
}

I get error

ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

in the terminal and my ios emulator shows property error from 'TransformStream' doesn't exist

image

and the same goes when i try with android emulator.

My Expo SDK is 51

mattt commented 1 month ago

Hi @Ahelsamahy. Sorry for the late response. Can you try adding the web-streams-polyfill package dependency and let me know if that resolves your error?

Ahelsamahy commented 1 month ago

Hi @mattt. I did try to install the package npm i web-streams-polyfill and I got the same error.

This is my package.json

{
  "name": "test",
  "version": "1.0.0",
  "main": "expo/AppEntry.js",
  "module": "expo/main.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@expo/env": "^0.3.0",
    "esm": "^3.2.25",
    "expo": "~51.0.28",
    "expo-status-bar": "~1.12.1",
    "react": "18.2.0",
    "react-native": "0.74.5",
    "react-native-dotenv": "^3.4.11",
    "replicate": "^0.32.1",
    "web-streams-polyfill": "^4.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true,
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}
aron commented 2 weeks ago

@Ahelsamahy did you import it? From the docs I think you need:

import "web-streams-polyfill/polyfill";

https://www.npmjs.com/package/web-streams-polyfill