{"id":15305473,"url":"https://github.com/alenvelocity/gpt-functions","last_synced_at":"2025-04-15T00:31:26.987Z","repository":{"id":152068780,"uuid":"625281627","full_name":"AlenVelocity/gpt-functions","owner":"AlenVelocity","description":"Convert prompts into working Javascript Functions. Never CTRL+V again","archived":false,"fork":false,"pushed_at":"2023-04-09T12:17:30.000Z","size":84,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T18:57:38.634Z","etag":null,"topics":["ai","gpt","gpt4","no-code","openai"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gpt-functions","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlenVelocity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"AlenVelocity"}},"created_at":"2023-04-08T16:17:44.000Z","updated_at":"2023-08-17T16:09:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec113455-8d37-47a4-bde7-3115d441f419","html_url":"https://github.com/AlenVelocity/gpt-functions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlenVelocity%2Fgpt-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlenVelocity%2Fgpt-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlenVelocity%2Fgpt-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlenVelocity%2Fgpt-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlenVelocity","download_url":"https://codeload.github.com/AlenVelocity/gpt-functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984248,"owners_count":21193713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","gpt","gpt4","no-code","openai"],"created_at":"2024-10-01T08:00:38.987Z","updated_at":"2025-04-15T00:31:26.723Z","avatar_url":"https://github.com/AlenVelocity.png","language":"TypeScript","funding_links":["https://github.com/sponsors/AlenVelocity"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=center\u003e\n\n# GPTFunctions\n\n### **Convert raw text into actual Javascript Functions**\n\n\n[![NPM](https://img.shields.io/npm/l/gpt-functions?style=flat-square\u0026label=License)](https://github.com/AlenVelocity/gpt-functions/blob/master/LICENSE) [![CodeFactor](https://img.shields.io/codefactor/grade/github/AlenVelocity/gpt-functions?style=flat-square\u0026label=Code%20Quality)](https://www.codefactor.io/repository/github/AlenVelocity/gpt-functions) [![NPM](https://img.shields.io/npm/dw/gpt-functions?style=flat-square\u0026label=Downloads)](https://npmjs.com/package/gpt-functions)\n\n\u003c/div\u003e\n\n## Installation\n\n```shell\nnpm install gpt-functions\n```\n\n## Usage\n\n### Initialiaze the GPT Functions class\n\n```js\nimport { GPTFunctions } from 'gpt-functions'\n\nconst API_KEY = 'your-openai-api-key-here'\nconst gpt = new GPTFunctions(API_KEY)\n```\n\n### **.createFunction()**\n\n#### Example Usage\n\n```js\nconst celsiusToFahrenheit = await gpt.createFunction('convert the given temperature from Celsius to Fahrenheit')\n\nconsole.log(celsiusToFahrenheit(25))\nconsole.log(celsiusToFahrenheit(10))\n```\n**Output**\n```js\n77\n50\n```\n\n#### Using the Options Object (Recommended way)\n```js\nconst permutations = await gpt.createFunction({\n    func: '(array) =\u003e array',\n    desc: 'Return all permutations of the passed array'\n})\n\nconsole.log(permutations([1,2,3]))\n```\n\n**Output**\n```js\n[\n  [ 1, 2, 3 ],\n  [ 1, 3, 2 ],\n  [ 2, 1, 3 ],\n  [ 2, 3, 1 ],\n  [ 3, 1, 2 ],\n  [ 3, 2, 1 ]\n]\n```\n\n**⚠️ WARNING ⚠️**\n\u003e NEVER PASS RAW USER INPUT WITHOUT VALIDATING IT FIRST. GPTFUNCTIONS USES THE JS FUNCTION CONSTRUCTOR, WHICH CAN EXECUTE ARBITRARY CODE. AN ATTACKER COULD EXPLOIT THIS TO RUN MALICIOUS CODE ON YOUR SYSTEM. ALWAYS VALIDATE USER INPUT AND SANITIZE IT BEFORE PASSING IT\n\n.createFunction() is a method that takes a string as the functio description or an object with the following properties as its parameter:\n\n    func: a string that represents the type of the fucntion\n    desc: a string that describes what the code does\n    model: the name of the OpenAI model you want to use to execute the code\n    evaulate: a function evaluates the string to a an actual function `Default: Function Constructor`\n\nThe createFunction() method returns a function that can be called with arguments to execute the code provided in the `func` property.\n\nNote that the createFunction() function does not execute the code immediately, but instead returns a function that can be used to execute the code later\n\n### **GPTFunctions.prototype.getResult()**\n\n```js\nconst result = await gpt.getResult({\n    func: '(array, array) =\u003e array',\n    args: [['a', 'b', 'c'], ['x', 'y', 'z']],\n    desc: 'Creates an array of arrays, grouping the elements of each input array based on their index.'\n})\n\nconsole.log(result)\n```\n\n**Output**\n```js\n[ [ 'a', 'x' ], [ 'b', 'y' ], [ 'c', 'z' ] ]\n```\n\nGPTFunctions.prototype.getResult() is a function that takes an object with the following properties as its parameter:\n\n- `func`: a string that represents the code you want to execute\n- `args`: an array of arrays containing the arguments to pass to the func.\n- `desc`: a string that describes what the code does.\n- `model`: the name of the OpenAI model you want to use to execute the code.\n- `postProcess`: a function to parse the API response\n\nThe `getResult()` method returns a Promise that resolves to the result of executing the code.\n\n## Contribution and Acknowledgments\n\nIf you find any issues or have any suggestions for improvement, please feel free to open an issue or a pull request.\n\n- [OpenAI API](openai.com)\n- [Torantulino/AI_Functions](https://github.com/Torantulino/AI-Functions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falenvelocity%2Fgpt-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falenvelocity%2Fgpt-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falenvelocity%2Fgpt-functions/lists"}