diff --git a/package-lock.json b/package-lock.json index c78b18f..05dbd02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "exponential-backoff": "^3.1.0", "fuse.js": "^6.6.2", "immer": "^9.0.19", - "openai": "^3.2.1", + "openai": "^4.6.1", "postcss": "^8.4.20", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -1211,26 +1211,6 @@ "node": ">= 14" } }, - "node_modules/@octokit/request/node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", - "dev": true, - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/@octokit/rest": { "version": "19.0.5", "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-19.0.5.tgz", @@ -1721,10 +1701,16 @@ "node_modules/@types/node": { "version": "20.2.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.3.tgz", - "integrity": "sha512-pg9d0yC4rVNWQzX8U7xb4olIOFuuVL9za3bzMT2pu2SU0SNEi66i2qrvhE2qt0HvkhuCaWJu7pLNOt/Pj8BIrw==", - "dev": true, - "optional": true, - "peer": true + "integrity": "sha512-pg9d0yC4rVNWQzX8U7xb4olIOFuuVL9za3bzMT2pu2SU0SNEi66i2qrvhE2qt0HvkhuCaWJu7pLNOt/Pj8BIrw==" + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -1831,6 +1817,17 @@ "node": ">=12" } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -1906,6 +1903,17 @@ "node": ">= 6.0.0" } }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -2094,14 +2102,6 @@ "node": ">=4" } }, - "node_modules/axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", - "dependencies": { - "follow-redirects": "^1.14.8" - } - }, "node_modules/bail": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/bail/-/bail-2.0.2.tgz", @@ -3341,6 +3341,14 @@ "@types/estree": "^1.0.0" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -3474,25 +3482,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -3506,6 +3495,23 @@ "node": ">= 6" } }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==" + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, "node_modules/fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -4070,6 +4076,14 @@ "node": ">=10.17.0" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "dependencies": { + "ms": "^2.0.0" + } + }, "node_modules/ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -6099,6 +6113,24 @@ "tslib": "^2.0.3" } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, "node_modules/node-emoji": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", @@ -6108,6 +6140,25 @@ "lodash": "^4.17.21" } }, + "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-releases": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", @@ -8814,12 +8865,36 @@ } }, "node_modules/openai": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz", - "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==", + "version": "4.62.0", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.62.0.tgz", + "integrity": "sha512-cPSsarEXoJENNwYMx/Xh/wuvnyYf8lPSR4zDVSnRvbcMHmKkDIzXhUVvPPfuI4M4T83x25gVnlW7huWEGKG+SA==", "dependencies": { - "axios": "^0.26.0", - "form-data": "^4.0.0" + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, + "node_modules/openai/node_modules/@types/node": { + "version": "18.19.50", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.50.tgz", + "integrity": "sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg==", + "dependencies": { + "undici-types": "~5.26.4" } }, "node_modules/p-each-series": { @@ -10452,8 +10527,7 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/traverse": { "version": "0.6.7", @@ -10578,6 +10652,11 @@ "node": ">=0.8.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/unified": { "version": "10.1.2", "resolved": "https://registry.npmjs.org/unified/-/unified-10.1.2.tgz", @@ -10960,17 +11039,23 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "engines": { + "node": ">= 14" + } + }, "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==", - "dev": true + "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==", - "dev": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -11956,17 +12041,6 @@ "is-plain-object": "^5.0.0", "node-fetch": "^2.6.7", "universal-user-agent": "^6.0.0" - }, - "dependencies": { - "node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", - "dev": true, - "requires": { - "whatwg-url": "^5.0.0" - } - } } }, "@octokit/request-error": { @@ -12319,10 +12393,16 @@ "@types/node": { "version": "20.2.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.3.tgz", - "integrity": "sha512-pg9d0yC4rVNWQzX8U7xb4olIOFuuVL9za3bzMT2pu2SU0SNEi66i2qrvhE2qt0HvkhuCaWJu7pLNOt/Pj8BIrw==", - "dev": true, - "optional": true, - "peer": true + "integrity": "sha512-pg9d0yC4rVNWQzX8U7xb4olIOFuuVL9za3bzMT2pu2SU0SNEi66i2qrvhE2qt0HvkhuCaWJu7pLNOt/Pj8BIrw==" + }, + "@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "requires": { + "@types/node": "*", + "form-data": "^4.0.0" + } }, "@types/normalize-package-data": { "version": "2.4.1", @@ -12419,6 +12499,14 @@ "@swc/core": "^1.3.35" } }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "requires": { + "event-target-shim": "^5.0.0" + } + }, "accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -12473,6 +12561,14 @@ "debug": "4" } }, + "agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "requires": { + "humanize-ms": "^1.2.1" + } + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -12605,14 +12701,6 @@ "integrity": "sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg==", "dev": true }, - "axios": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", - "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", - "requires": { - "follow-redirects": "^1.14.8" - } - }, "bail": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/bail/-/bail-2.0.2.tgz", @@ -13501,6 +13589,11 @@ "@types/estree": "^1.0.0" } }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, "eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -13601,11 +13694,6 @@ "semver-regex": "^3.1.2" } }, - "follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" - }, "form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -13616,6 +13704,20 @@ "mime-types": "^2.1.12" } }, + "form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==" + }, + "formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "requires": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + } + }, "fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -14026,6 +14128,14 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "requires": { + "ms": "^2.0.0" + } + }, "ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -15424,6 +15534,11 @@ "tslib": "^2.0.3" } }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, "node-emoji": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", @@ -15433,6 +15548,14 @@ "lodash": "^4.17.21" } }, + "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==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, "node-releases": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", @@ -17322,12 +17445,27 @@ } }, "openai": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/openai/-/openai-3.2.1.tgz", - "integrity": "sha512-762C9BNlJPbjjlWZi4WYK9iM2tAVAv0uUp1UmI34vb0CN5T2mjB/qM6RYBmNKMh/dN9fC+bxqPwWJZUTWW052A==", + "version": "4.62.0", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.62.0.tgz", + "integrity": "sha512-cPSsarEXoJENNwYMx/Xh/wuvnyYf8lPSR4zDVSnRvbcMHmKkDIzXhUVvPPfuI4M4T83x25gVnlW7huWEGKG+SA==", "requires": { - "axios": "^0.26.0", - "form-data": "^4.0.0" + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "dependencies": { + "@types/node": { + "version": "18.19.50", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.50.tgz", + "integrity": "sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg==", + "requires": { + "undici-types": "~5.26.4" + } + } } }, "p-each-series": { @@ -18523,8 +18661,7 @@ "tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "traverse": { "version": "0.6.7", @@ -18597,6 +18734,11 @@ "dev": true, "optional": true }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "unified": { "version": "10.1.2", "resolved": "https://registry.npmjs.org/unified/-/unified-10.1.2.tgz", @@ -18855,17 +18997,20 @@ "integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==", "dev": true }, + "web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==" + }, "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==", - "dev": true + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, "requires": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" diff --git a/package.json b/package.json index a5bc9eb..cb41d2c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "exponential-backoff": "^3.1.0", "fuse.js": "^6.6.2", "immer": "^9.0.19", - "openai": "^3.2.1", + "openai": "^4.6.1", "postcss": "^8.4.20", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/lib/logseq.ts b/src/lib/logseq.ts index da52a0a..ba3b5e5 100644 --- a/src/lib/logseq.ts +++ b/src/lib/logseq.ts @@ -56,12 +56,13 @@ export async function getPageContentFromBlock(b: BlockEntity): Promise { export async function saveDalleImage(imageURL: string): Promise { const s = logseq.Assets.makeSandboxStorage(); const imageName = `dalle-${Date.now()}.png`; - const response = await fetch(imageURL); const responseArrayBuffer: any = await response.arrayBuffer(); await s.setItem(imageName, responseArrayBuffer); - const imageFileName = `![](assets/storages/logseq-plugin-gpt3-openai/${imageName})`; + const pluginId = logseq.baseInfo.id || 'logseq-plugin-gpt3-openai'; + + const imageFileName = `![](assets/storages/${pluginId}/${imageName})`; return imageFileName; } diff --git a/src/lib/openai.ts b/src/lib/openai.ts index 4e04edb..32d4cce 100644 --- a/src/lib/openai.ts +++ b/src/lib/openai.ts @@ -1,20 +1,20 @@ -import { - ChatCompletionRequestMessage, - Configuration, - CreateChatCompletionResponse, CreateCompletionResponse, - CreateImageRequestSizeEnum, - OpenAIApi -} from "openai"; +import OpenAI from "openai"; import "@logseq/libs"; import { backOff } from "exponential-backoff"; -export type DalleImageSize = 256 | 512 | 1024; +export type DalleImageSize = '256' | '256x256' | '512' | '512x512' | '1024' | '1024x1024' | '1024x1792' | '1792x1024'; +export type DalleModel = 'dall-e-2' | 'dall-e-3'; +export type DalleQuality = 'standard' | 'hd'; +export type DalleStyle = 'natural' | 'vivid'; export interface OpenAIOptions { apiKey: string; completionEngine?: string; temperature?: number; maxTokens?: number; dalleImageSize?: DalleImageSize; + dalleModel?: DalleModel; + dalleQuality?: DalleQuality; + dalleStyle?: DalleStyle; chatPrompt?: string; completionEndpoint?: string; } @@ -24,7 +24,10 @@ const OpenAIDefaults = (apiKey: string): OpenAIOptions => ({ completionEngine: "gpt-3.5-turbo", temperature: 1.0, maxTokens: 1000, - dalleImageSize: 1024, + dalleImageSize: '1024', + dalleModel: 'dall-e-3', + dalleQuality: 'standard', + dalleStyle: 'vivid' }); const retryOptions = { @@ -92,25 +95,34 @@ export async function dallE( ): Promise { const options = { ...OpenAIDefaults(openAiOptions.apiKey), ...openAiOptions }; - const configuration = new Configuration({ + const openai = new OpenAI({ apiKey: options.apiKey, - basePath: options.completionEndpoint + baseURL: options.completionEndpoint, + dangerouslyAllowBrowser: true }); - const openai = new OpenAIApi(configuration); - const imageSizeRequest: CreateImageRequestSizeEnum = - `${options.dalleImageSize}x${options.dalleImageSize}` as CreateImageRequestSizeEnum; + // TODO : fix this typing loop + // @ts-ignore + const imageSizeRequest: OpenAI.ImageGenerateParams["size"] = options.dalleImageSize ? + options.dalleImageSize!.includes('x') + ? options.dalleImageSize + : `${options.dalleImageSize}x${options.dalleImageSize}` : '256x256'; + + const imageParameters: OpenAI.ImageGenerateParams = { + prompt, + n: 1, + size: imageSizeRequest, + model: options.dalleModel, + quality: options.dalleQuality, + style: options.dalleStyle + }; const response = await backOff( () => - openai.createImage({ - prompt, - n: 1, - size: imageSizeRequest, - }), + openai.images.generate(imageParameters), retryOptions ); - return response.data.data[0].url; + return response.data[0].url; } export async function openAI( @@ -120,22 +132,20 @@ export async function openAI( const options = { ...OpenAIDefaults(openAiOptions.apiKey), ...openAiOptions }; const engine = options.completionEngine!; - const configuration = new Configuration({ - basePath: options.completionEndpoint, + const openai = new OpenAI({ apiKey: options.apiKey, + baseURL: options.completionEndpoint }); - - const openai = new OpenAIApi(configuration); try { if (engine.startsWith("gpt-3.5") || engine.startsWith("gpt-4")) { - const inputMessages:ChatCompletionRequestMessage[] = [{ role: "user", content: input }]; + const inputMessages:OpenAI.Chat.CreateChatCompletionRequestMessage[] = [{ role: "user", content: input }]; if (openAiOptions.chatPrompt && openAiOptions.chatPrompt.length > 0) { inputMessages.unshift({ role: "system", content: openAiOptions.chatPrompt }); } const response = await backOff( () => - openai.createChatCompletion({ + openai.chat.completions.create({ messages: inputMessages, temperature: options.temperature, max_tokens: options.maxTokens, @@ -146,7 +156,7 @@ export async function openAI( }), retryOptions ); - const choices = response.data.choices; + const choices = response.choices; if ( choices && choices[0] && @@ -160,7 +170,7 @@ export async function openAI( } } else { const response = await backOff(() => - openai.createCompletion({ + openai.completions.create({ prompt: input, temperature: options.temperature, max_tokens: options.maxTokens, @@ -171,7 +181,7 @@ export async function openAI( }), retryOptions ); - const choices = response.data.choices; + const choices = response.choices; if ( choices && choices[0] && @@ -204,7 +214,7 @@ export async function openAIWithStream( try { if (engine.startsWith("gpt-3.5") || engine.startsWith("gpt-4")) { - const inputMessages: ChatCompletionRequestMessage[] = [{ role: "user", content: input }]; + const inputMessages: OpenAI.Chat.CreateChatCompletionRequestMessage[] = [{ role: "user", content: input }]; if (openAiOptions.chatPrompt && openAiOptions.chatPrompt.length > 0) { inputMessages.unshift({ role: "system", content: openAiOptions.chatPrompt }); } @@ -263,7 +273,7 @@ export async function openAIWithStream( }), retryOptions ); - const choices = (response as CreateChatCompletionResponse)?.choices; + const choices = (response as OpenAI.Chat.Completions.ChatCompletion)?.choices; if ( choices && choices[0] && @@ -331,7 +341,7 @@ export async function openAIWithStream( }), retryOptions ); - const choices = (response as CreateCompletionResponse)?.choices; + const choices = (response as OpenAI.Completion)?.choices; if ( choices && choices[0] && diff --git a/src/lib/rawCommands.ts b/src/lib/rawCommands.ts index 62a16b7..dd8f5b4 100644 --- a/src/lib/rawCommands.ts +++ b/src/lib/rawCommands.ts @@ -52,13 +52,18 @@ function validateSettings(settings: OpenAIOptions) { } if ( - settings.dalleImageSize !== 256 && - settings.dalleImageSize !== 512 && - settings.dalleImageSize !== 1024 + settings.dalleImageSize !== '256' && + settings.dalleImageSize !== '256x256' && + settings.dalleImageSize !== '512' && + settings.dalleImageSize !== '512x512' && + settings.dalleImageSize !== '1024' && + settings.dalleImageSize !== '1024x1024' && + settings.dalleImageSize !== '1024x1792' && + settings.dalleImageSize !== '1792x1024' ) { console.error("DALL-E image size must be 256, 512, or 1024."); logseq.App.showMsg("DALL-E image size must be 256, 512, or 1024.", "error"); - throw new Error("DALL-E image size must be 256, 512, or 1024."); + throw new Error("DALL-E image size must be 256, 512, 1024, 1024x1792, or 179x1024"); } } diff --git a/src/lib/settings.ts b/src/lib/settings.ts index dbe283d..086f0a7 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -62,11 +62,32 @@ export const settingsSchema: SettingSchemaDesc[] = [ }, { key: "dalleImageSize", - type: "number", + type: "string", default: 1024, title: "DALL-E Image Size", description: - "Size of the image to generate. Can be 256, 512, or 1024. Smaller images are faster to generate.", + "Size of the image to generate. Can be 256, 512, or 1024 for dall-e-2; Must be one of 1024x1024 , 1792x1024 , or 1024x1792 for dall-e-3 models.", + }, + { + key: "dalleModel", + type: "string", + default: "dall-e-3", + title: "DALL-E Model", + description: "The DALL-E model to use. Can be dall-e-2 or dall-e-3." + }, + { + key: "dalleStyle", + type: "string", + default: "vivid", + title: "Style", + description: "The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images." + }, + { + key: "dalleQuality", + type: "string", + default: "standard", + title: "Quality", + description: "The quality of the image that will be generated. ‘hd’ creates images with finer details and greater consistency across the image. Defaults to ‘standard’." }, { key: "shortcutBlock", @@ -94,9 +115,10 @@ export function getOpenaiSettings(): PluginOptions { const injectPrefix = unescapeNewlines(logseq.settings!["injectPrefix"]); const temperature = Number.parseFloat(logseq.settings!["openAITemperature"]); const maxTokens = Number.parseInt(logseq.settings!["openAIMaxTokens"]); - const dalleImageSize = Number.parseInt( - logseq.settings!["dalleImageSize"] - ) as DalleImageSize; + const dalleImageSize = logseq.settings!["dalleImageSize"] as DalleImageSize; + const dalleModel = logseq.settings!["dalleModel"]; + const dalleStyle = logseq.settings!["dalleStyle"]; + const dalleQuality = logseq.settings!["dalleQuality"]; const chatPrompt = logseq.settings!["chatPrompt"]; const completionEndpoint = logseq.settings!["chatCompletionEndpoint"]; return { @@ -105,6 +127,9 @@ export function getOpenaiSettings(): PluginOptions { temperature, maxTokens, dalleImageSize, + dalleModel, + dalleQuality, + dalleStyle, injectPrefix, chatPrompt, completionEndpoint,