diff --git a/src/client.js b/src/client.js index c8239da..e8e9bd2 100644 --- a/src/client.js +++ b/src/client.js @@ -1,9 +1,21 @@ let isNode = false; -if (typeof window === 'undefined' || typeof globalThis.fetch !== 'undefined') { - globalThis.fetch = (await import('node-fetch')).default; - isNode = true; + +/** + * Initialize fetch + * @return {Promise} + */ +async function initializeFetch() { + if (typeof window === 'undefined' || + typeof globalThis.fetch === 'undefined') { + const nodeFetch = await import('node-fetch'); + fetch = nodeFetch.default; + isNode = true; + } else { + fetch = globalThis.fetch; + } } +initializeFetch(); const RETRY_STATUS_CODES = [429, 500, 502, 503, 504]; const ENDPOINT = 'https://api.mistral.ai';