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;
}
}
When trying to vendor
ollama-js
into a basic JavaScript project I hit an issue that this import ofwhatwg-fetch
not being simple to resolve. This change allows for setting the fetch library used by Ollama in an environment wherewhatwg-fetch
is not present.Example: