aicommits
aicommits copied to clipboard
refactor: use custom OpenAI "fetch"
Problems
- The
openai
had a hanging socket that was preventingaicommits
from exiting immediately: https://github.com/Nutlope/aicommits/pull/102 - The
openai
package was pretty bulky
Before
Tarball size
73.8 kB
File Size Gzip Brotli
dist/cli.mjs 294.7 kB 70.2 kB 60.7 kB
README.md 2.8 kB 1.4 kB 1.1 kB
package.json 1.3 kB 648 B 573 B
LICENSE 1.1 kB 641 B 485 B
299.8 kB 72.8 kB 62.9 kB
Changes
- I played around with
got
,node-fetch
, andundici
, but unfortunately, they were all quite heavy for our simple usage. I ended up writing my own post function that's hard-coded to the OpenAI API. Huge package size improvement. - We also keep the
openai
package as a dev dependency so we get the benefits of types
After
Tarball size
29.2 kB
File Size Gzip Brotli
dist/cli.mjs 78.7 kB 26.4 kB 23.2 kB
README.md 2.8 kB 1.4 kB 1.1 kB
package.json 1.4 kB 668 B 592 B
LICENSE 1.1 kB 641 B 485 B
83.9 kB 29.0 kB 25.4 kB
Will run some tests on this to make sure this works to catch:
- [x] Unreachable OpenAI server (e.g. no internet or blocked)
- [ ] ~Windows exist~