From c16a4edc442e6f912a42f005efa0b196849537c7 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Mon, 12 Aug 2024 21:34:28 -0700 Subject: [PATCH] Revert "enable ollama-js use in an environment without whatwg (#125)" This reverts commit f73dae5ecdc41c7143901abc58ed254e1ced67d2. --- src/browser.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/browser.ts b/src/browser.ts index c66d530..40ba369 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,5 +1,6 @@ import * as utils from './utils.js' import { AbortableAsyncIterator, parseJSON, post } from './utils.js' +import 'whatwg-fetch' import type { ChatRequest, @@ -38,24 +39,9 @@ export class Ollama { this.config.host = utils.formatHost(config?.host ?? 'http://127.0.0.1:11434') } - this.fetch = config?.fetch || this.getFetch(); - } - - private getFetch(): Fetch { - if (typeof window !== 'undefined' && window.fetch) { - return window.fetch.bind(window); - } - - if (typeof global !== 'undefined' && global.fetch) { - return global.fetch; - } - - try { - // Use dynamic import for Node.js environments - return require('node-fetch'); - } catch (error) { - console.error('Failed to import node-fetch:', error); - throw new Error('Fetch is not available. Please provide a fetch implementation in the config.'); + this.fetch = fetch + if (config?.fetch != null) { + this.fetch = config.fetch } }