diff --git a/package-lock.json b/package-lock.json index fa398bf..f05f5ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "@platformatic/mistral-client", "version": "0.0.1", "license": "Apache-2.0", - "dependencies": { - "node-fetch": "^2.6.7" - }, "devDependencies": { "eslint": "^8.55.0", "eslint-config-google": "^0.14.0", @@ -2278,20 +2275,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -3535,25 +3518,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -4285,11 +4249,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -4391,20 +4350,6 @@ "makeerror": "1.0.12" } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 47988ab..357c936 100644 --- a/package.json +++ b/package.json @@ -11,20 +11,19 @@ "test": "node --experimental-vm-modules node_modules/.bin/jest" }, "jest": { - "testPathIgnorePatterns": ["examples"] + "testPathIgnorePatterns": [ + "examples" + ] }, "repository": { "type": "git", "url": "https://github.com/platformatic/mistral-client" }, "types": "src/client.d.ts", - "dependencies": { - "node-fetch": "^2.6.7" - }, "devDependencies": { "eslint": "^8.55.0", "eslint-config-google": "^0.14.0", - "prettier": "2.8.8", - "jest": "^29.7.0" + "jest": "^29.7.0", + "prettier": "2.8.8" } } diff --git a/src/client.js b/src/client.js index 10def72..58d52c4 100644 --- a/src/client.js +++ b/src/client.js @@ -1,26 +1,7 @@ -let isNode = false; - const VERSION = '0.0.3'; const RETRY_STATUS_CODES = [429, 500, 502, 503, 504]; const ENDPOINT = 'https://api.mistral.ai'; -/** - * 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(); - /** * MistralAPIError * @return {MistralAPIError} @@ -94,28 +75,7 @@ class MistralClient { if (response.ok) { if (request?.stream) { - if (isNode) { - return response.body; - } else { - const reader = response.body.getReader(); - // Chrome does not support async iterators yet, so polyfill it - const asyncIterator = async function* () { - try { - while (true) { - // Read from the stream - const {done, value} = await reader.read(); - // Exit if we're done - if (done) return; - // Else yield the chunk - yield value; - } - } finally { - reader.releaseLock(); - } - }; - - return asyncIterator(); - } + return response.body; } return await response.json(); } else if (RETRY_STATUS_CODES.includes(response.status)) {