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

Top level await #36

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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