{"_id":"@andrewtaylor/util-ai","_rev":"3-abc2b1ac8eb3af247cb9868ea7655118","name":"@andrewtaylor/util-ai","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@andrewtaylor/util-ai","version":"1.0.0","author":{"url":"https://www.andrewt.net/","name":"Andrew Taylor","email":"andrew@andrewt.net"},"license":"ISC","_id":"@andrewtaylor/util-ai@1.0.0","maintainers":[{"name":"andrewtaylor","email":"andrew@andrewt.net"}],"homepage":"https://github.com/andrew-t/util-ai","dist":{"shasum":"c1f1174387aa947782a95c52a784f3487ea14af7","tarball":"https://registry.npmjs.org/@andrewtaylor/util-ai/-/util-ai-1.0.0.tgz","fileCount":3,"integrity":"sha512-F87pCwQ+kUdeqDewKH8GOaoDZeaOJuYzfSbJNYMhd5z3RHaBZ99q76UPRMxXB0Opcs7BSsOrVu36eXR5Q4a2eQ==","signatures":[{"sig":"MEUCIGet+SbH31IdcwCKrEehe83pQMsKIvntL4HCFOHiyNcNAiEA0z6pfLRtDSPK93legRBNJ6wzaAROsZf8QUYJwGdTeHw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":5369},"main":"index.js","gitHead":"460f4817e3339bf25abd7c6ea3ccb3d380c65e84","scripts":{"test":"jest"},"_npmUser":{"name":"andrewtaylor","email":"andrew@andrewt.net"},"_npmVersion":"10.9.2","description":"Are you tired of packages like [lodash](https://lodash.com/) and all their missing functions? Are you sick of having to import dozens of helper libraries to get everything you need? Are you done with having to remember whether a particular function is cal","directories":{},"_nodeVersion":"22.14.0","dependencies":{"openai":"^4.89.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0"},"_npmOperationalInternal":{"tmp":"tmp/util-ai_1.0.0_1743345307597_0.02323432085670074","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@andrewtaylor/util-ai","version":"1.0.1","author":{"url":"https://www.andrewt.net/","name":"Andrew Taylor","email":"andrew@andrewt.net"},"license":"ISC","_id":"@andrewtaylor/util-ai@1.0.1","maintainers":[{"name":"andrewtaylor","email":"andrew@andrewt.net"}],"homepage":"https://github.com/andrew-t/util-ai","dist":{"shasum":"685445e86fa3c1f950e52a9b4223a11089d94ecd","tarball":"https://registry.npmjs.org/@andrewtaylor/util-ai/-/util-ai-1.0.1.tgz","fileCount":3,"integrity":"sha512-xfx7RW2i6PpK6CDDL6F8+MmBCIYmF5UH82+NZSYpGrRq+P+Rlv0W6H+4c5mzrqC/LVSVs+B0ar3afPIJ+GT4+A==","signatures":[{"sig":"MEYCIQCvGMWqkH5NXJYf2+VQqY6R88a3JcftVQROh6ACL82oHQIhAInmAmV+a4xdDcHF2zgaVjQ/zTy7LjAtUbArQDlPCXkt","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":5364},"main":"index.js","gitHead":"60e9dbb761eead3770c903be4820e0d209074449","scripts":{"test":"jest"},"_npmUser":{"name":"andrewtaylor","email":"andrew@andrewt.net"},"_npmVersion":"10.9.2","description":"Are you tired of packages like [lodash](https://lodash.com/) and all their missing functions? Are you sick of having to import dozens of helper libraries to get everything you need? Are you done with having to remember whether a particular function is cal","directories":{},"_nodeVersion":"22.14.0","dependencies":{"openai":"^4.89.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0"},"_npmOperationalInternal":{"tmp":"tmp/util-ai_1.0.1_1743359889366_0.30487661370628105","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@andrewtaylor/util-ai","version":"1.0.2","main":"index.js","scripts":{"test":"jest"},"author":{"name":"Andrew Taylor","email":"andrew@andrewt.net","url":"https://www.andrewt.net/"},"homepage":"https://github.com/andrew-t/util-ai","license":"ISC","description":"Are you tired of packages like [lodash](https://lodash.com/) and all their missing functions? Are you sick of having to import dozens of helper libraries to get everything you need? Are you done with having to remember whether a particular function is cal","devDependencies":{"jest":"^29.7.0"},"dependencies":{"openai":"^4.89.0"},"_id":"@andrewtaylor/util-ai@1.0.2","gitHead":"b6c6f36828bdd3218e1bf1c5b23d077718c753a5","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-h1VmEoLdqG7VLP7g2Ht02XDfVkqyDO653XUuSZ0IQSiG9eIdOGlnos+k/xuin1H5fsZzGvk7FeuZ7/3d2zmp7w==","shasum":"864403e9b19e4143f0757ef1ca355bd272610d42","tarball":"https://registry.npmjs.org/@andrewtaylor/util-ai/-/util-ai-1.0.2.tgz","fileCount":3,"unpackedSize":5371,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDlAc3DO8MJJz7neGcwrwfdxHGLjv4R9qz1W255ill0WgIgI3W0h3MWSsDr0BdaxxuPwbxXK3tdznLpHEWe1gmIISg="}]},"_npmUser":{"name":"andrewtaylor","email":"andrew@andrewt.net"},"directories":{},"maintainers":[{"name":"andrewtaylor","email":"andrew@andrewt.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/util-ai_1.0.2_1743362596448_0.5550478234000871"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-30T14:35:07.516Z","modified":"2025-03-30T19:23:16.807Z","1.0.0":"2025-03-30T14:35:07.791Z","1.0.1":"2025-03-30T18:38:09.538Z","1.0.2":"2025-03-30T19:23:16.627Z"},"author":{"name":"Andrew Taylor","email":"andrew@andrewt.net","url":"https://www.andrewt.net/"},"license":"ISC","homepage":"https://github.com/andrew-t/util-ai","description":"Are you tired of packages like [lodash](https://lodash.com/) and all their missing functions? Are you sick of having to import dozens of helper libraries to get everything you need? Are you done with having to remember whether a particular function is cal","maintainers":[{"name":"andrewtaylor","email":"andrew@andrewt.net"}],"readme":"# util-ai\n\nAre you tired of packages like [lodash](https://lodash.com/) and all their missing functions? Are you sick of having to import dozens of helper libraries to get everything you need? Are you done with having to remember whether a particular function is called `includes` or `contains`? `util-ai` is a new package based on the pioneering work of the team at [is-even-ai](https://github.com/Calvin-LL/is-even-ai) that uses the power of AI to do anything, and of Javascript to _let you_ do anything, to make one package that contains literally every function imaginable (as long as the input and output of that function can be serialised into text for ChatGPT).\n\nTry the example code:\n\n```js\nconst AiUtil = require(\"util-ai\");\nconst aiUtil = AiUtil({ apiKey: \"YOUR_OPENAI_API_KEY\" });\n\nconsole.log(\"7 is prime?\",\n    await aiUtil.isPrime(7));\n\nconsole.log(\"Lowest common multiple of 7, 12 and 5\",\n    await aiUtil.lowestCommonMultiple(7, 12, 5));\n\nconsole.log(\"9 is one below a number divisible by three?\",\n    await aiUtil.isOneBelowANumberDivisibleByThree(9));\n\nconsole.log(\"CRAWL is allowed in Wordle?\",\n    await aiUtil.isAllowedInWordle(\"CRAWL\"));\n```\n\n# How does this work?\n\nIt probably doesn't, AI is garbage! You'll get wrong answers, more slowly than with real code, and at huge expense both to yourself and the planet! In any case I haven't tested this code because I don't have an OpenAI API key, and refuse to pay for one.\n\n# How is this _supposed_ to work?\n\nIn Javascript, `Obj.methodName` is the same as `Obj[\"methodName\"]`, using the regular string indexer. Also, Javascript allows you to make a \"proxy\" object, which can run any behaviour you like when the string indexer is called. So if we define an object like this:\n\n```js\nconst aiUtil = new Proxy({}, {\n    get(target, name, receiver) {\n        return name + \" AI\";\n    }\n});\n```\n\nthen we can index it however we want and that code will run.\n\n```js\nconsole.log(aiUtil[\"test\"]); // -> \"test AI\"\nconsole.log(aiUtil.secondTest); // -> \"secondTest AI\"\n```\n\nIf we return a function, we can run that function like a normal method:\n\n```js\nconst aiUtil = new Proxy({}, {\n    get(target, name, receiver) {\n        return () => name + \" AI\";\n    }\n});\n\nconst value = aiUtil.test();\n\nconsole.log(value); // -> \"test AI\"\n```\n\nNow all we need to do is have the returned function call ChatGPT, and we can effectively use any function we want!\n\n```js\nconst aiUtil = new Proxy({}, {\n    get(target, name, receiver) {\n        return async (...args) => {\n            const response = await callChatGpt(\n                `Toolbox is a helpful Javascript utility library,\n                which contains many useful functions.\n                What value would you expect the code\n                Toolbox.${name}(${args.map(JSON.stringify).join(\", \")})\n                to return?\n                \n                Answer in valid JSON, do not return anything that is not valid JSON.\n                Assume the function ${name} exists, is being used correctly,\n                and does not throw an error.`\n            );\n            return JSON.parse(response);\n        };\n    }\n});\n\nconst value = await aiUtil.isPrime(7);\n\nconsole.log(value); // true\n```\n","readmeFilename":"README.md"}