npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gpt-functions

v0.0.4

Published

Never code again

Downloads

4

Readme

GPTFunctions

Convert Raw text into actual Javascript Functions

Installation

npm install gpt-functions

Usage

Initialiaze the GPT Functions class

import { GPTFunctions } from 'gpt-functions'

const API_KEY = 'your-openai-api-key-here'
const gpt = new GPTFunctions(API_KEY)

.createFunction()

Example Usage

const celsiusToFahrenheit = await gpt.createFunction('convert the given temperature from Celsius to Fahrenheit')

console.log(celsiusToFahrenheit(25))
console.log(celsiusToFahrenheit(10))

Output

77
50

Using the Options Object (Recommended way)

const permutations = await gpt.createFunction({
    func: '(array) => array',
    desc: 'Return all permutations of the passed array'
})

console.log(permutations([1,2,3]))

Output

[
  [ 1, 2, 3 ],
  [ 1, 3, 2 ],
  [ 2, 1, 3 ],
  [ 2, 3, 1 ],
  [ 3, 1, 2 ],
  [ 3, 2, 1 ]
]

⚠️ WARNING ⚠️

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

.createFunction() is a method that takes a string as the functio description or an object with the following properties as its parameter:

func: a string that represents the type of the fucntion
desc: a string that describes what the code does
model: the name of the OpenAI model you want to use to execute the code
evaulate: a function evaluates the string to a an actual function `Default: Function Constructor`

The createFunction() method returns a function that can be called with arguments to execute the code provided in the func property.

Note that the createFunction() function does not execute the code immediately, but instead returns a function that can be used to execute the code later

GPTFunctions.prototype.getResult()

const result = await gpt.getResult({
    func: '(array, array) => array',
    args: [['a', 'b', 'c'], ['x', 'y', 'z']],
    desc: 'Creates an array of arrays, grouping the elements of each input array based on their index.'
})

console.log(result)

Output

[ [ 'a', 'x' ], [ 'b', 'y' ], [ 'c', 'z' ] ]

GPTFunctions.prototype.getResult() is a function that takes an object with the following properties as its parameter:

  • func: a string that represents the code you want to execute
  • args: an array of arrays containing the arguments to pass to the func.
  • desc: a string that describes what the code does.
  • model: the name of the OpenAI model you want to use to execute the code.
  • postProcess: a function to parse the API response

The getResult() method returns a Promise that resolves to the result of executing the code.

Contribution and Acknowledgments

If you find any issues or have any suggestions for improvement, please feel free to open an issue or a pull request.

This project was made possible thanks to the OpenAI API