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

enable ollama-js use in an environment without whatwg #125

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

BruceMacD
Copy link
Collaborator

  • use dynamic import to allow setting fetch without whatwg-fetch being present

When trying to vendor ollama-js into a basic JavaScript project I hit an issue that this import of whatwg-fetch not being simple to resolve. This change allows for setting the fetch library used by Ollama in an environment where whatwg-fetch is not present.

Example:

async function initOllama() {
  try {
    const ollamaModule = await import('/public/vendor/ollama/dist/browser.mjs');
    // Create an instance of Ollama with a custom fetch implementation
    const ollama = new ollamaModule.Ollama({
      fetch: window.fetch
    });
    return ollama;
  } catch (error) {
    console.error('Error initializing Ollama:', error);
    throw error;
  }
}

- use dynamic import to allow setting fetch without whatwg-fetch being present
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

Successfully merging this pull request may close these issues.

1 participant