Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from mistralai/top-level-await
Browse files Browse the repository at this point in the history
Top level await
  • Loading branch information
Bam4d authored Jan 15, 2024
2 parents 705dc12 + c691a4b commit 4cac6c5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -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<void>}
*/
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';
Expand Down

0 comments on commit 4cac6c5

Please sign in to comment.