groq / groq-typescript

The official Node.js / Typescript library for the Groq API
Apache License 2.0
145 stars 17 forks source link

Error Unknown request URL when using with React Native #18

Closed younes-ammari closed 3 months ago

younes-ammari commented 5 months ago

I'm trying to use Groq in my React Native application I installed the latest groq-sdk but i keep getting this error when i used groq-sdk

[Error: 404 {"error":{"message":"Unknown request URL: POST /openai/v1/chat/completions/. Please check the URL for typos, or see the docs at https://console.groq.com/docs/","type":"invalid_request_error","code":"unknown_url"}}]

here is my code:

import Groq from 'groq-sdk';
const groq = new Groq({
  apiKey: GROQ_API_KEY,
});
async function main() {
    try {
      const chatCompletion = await groq.chat.completions.create({
        messages: [{ role: 'user', content: 'Explain the importance of low latency LLMs' }],
        model: 'mixtral-8x7b-32768',
      });

      console.log(chatCompletion.choices[0].message.content);
    }

    catch (error) {
      console.error(error);
    }
  }
gradenr commented 5 months ago

There is an extra / in your URL. I'm not sure how that happened. What version of the sdk are you using?

rattrayalex commented 4 months ago

React Native adds that extra / in, and is accordingly not officially supported (as documented in the README). Things should work with a polyfill like this one: https://github.com/acostalima/react-native-polyfill-globals (however, file uploads still won't work).

hozen-groq commented 4 months ago

@younes-ammari Were you able to resolve this issue with the above? 👀