Skip to content

Commit

Permalink
Merge pull request #133 from ollama/revert-125-brucemacd/what-wg-dynamic
Browse files Browse the repository at this point in the history
Revert "enable ollama-js use in an environment without whatwg"
  • Loading branch information
jmorganca authored Aug 13, 2024
2 parents 8607c28 + c16a4ed commit c03ea59
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as utils from './utils.js'
import { AbortableAsyncIterator, parseJSON, post } from './utils.js'
import 'whatwg-fetch'

import type {
ChatRequest,
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit c03ea59

Please sign in to comment.