Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using it for react-native throws [TypeError: Cannot read property 'toLowerCase' of undefined] #182

Open
BhavinPatel04 opened this issue Dec 21, 2024 · 0 comments

Comments

@BhavinPatel04
Copy link

BhavinPatel04 commented Dec 21, 2024

Usage

import ollama from 'ollama/dist/browser';
const response = await ollama.chat({
  model: 'llama3.2:1b',
  messages: [{
    role: 'user',
    content: 'Why is the sky blue?',
  }],
});

Issue

While using with react-native, it throws the below error

[TypeError: Cannot read property 'toLowerCase' of undefined]

RootCause

After debugging it seems the error is thrown in getPlatform() on line#95
This is because navigator.platform is deprecated.

Workaround

(In case someone is stuck here as well)

const fetchResponse = await fetch('http://localhost:11434/api/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'llama3.2:1b',
    messages: [{
      role: 'user',
      content: 'Why is the sky blue?',
    }],
    stream: false
  }),
});
const response = await fetchResponse.json();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant