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

arrays-ai

v2.1.1

Published

Arrays-ai is a library that enables processing of data arrays in JavaScript using natural language instructions. Instead of just processing data, the library interprets the natural language instructions provided by the user and generates the necessary ope

Downloads

2

Readme

Arrays-AI

License: MIT

TypeScript

JavaScript

The "arrays-ai" library provides a way to manipulate arrays of objects in JavaScript using artificial intelligence. It allows performing operations such as filtering, aggregaton, sorting, and removing elements from the array, interpreting commands in natural language. The library uses the OpenAI API to process the commands and apply the corresponding operations on the array.

Installation

To install the library, you can use NPM:

npm install arrays-ai

You can also download the source code from the GitHub repository and use it directly in your project.

Usage

To use the library in your project, you must first import it:

import * as dotenv from "dotenv";
dotenv.config({ path: './.env' });
import { ArraysAi, Languages, Configuration } from '../dist/index';

// Get the OPEN AI API KEY from the .env file
dotenv.config();
let APIKEY = process.env.OPENAI_API_KEY;
if(APIKEY == undefined) throw new Error("APIKEY not found in .env file");

// Configure with the OPEN AI API KEY
let config : Configuration = new Configuration({
  apiKey: APIKEY
});

// configure the arraysai object
const arraysai : ArraysAi<any> = new ArraysAi();
arraysai.Configure(config);

// Set the arrays to be used in the questions
let arrays = [collection_1, collection_2, ...];
arraysai.SetData(arrays);

// Language used in the verbose answers by default use English
arraysai.SetLanguage(Languages.ENGLISH);

After that, you can manipulate an array of objects using the "Ask()" function. This function takes as parameters the array to manipulate and a query string that indicates the operation to perform and a boolean value in case you whant a verbose response. For example:

arraysai.Ask("How many records have a null age in the first array???", true)
.then(answer => 
  {
      console.log(answer); // There are two records in the first array that have a null age.
    }
  );

The "Ask()" function uses OpenAI's artificial intelligence to interpret the query and perform the corresponding manipulation on the array. The result is returned through a string for verbose answers or any for simple questions.

TypeScript Support

The "arrays-ai" library is fully compatible with TypeScript. Starting from version 1.1.1, the library includes TypeScript declaration files (.d.ts) that allow for type checking at compile time and better editor support.

To use the library in your TypeScript project, simply install the package via NPM:

npm install arrays-ai

Documentation

The "arrays-ai" library has the following API:

| Method | Description | | --- | --- | | Configure(OpenAiConfig: Configuration, OutputLanguage?: BuilInLanguage): void | Configures the OpenAI API and the output language (optional). | | SetLanguage(Language: Languages): void | Sets the language used in the generated responses. | | SetData(Data: Array<Array>): void | Sets the data for the table. | | GetData(): Array<Array> | Gets the data from the table. | | GetColumns(): Array | Gets the column information of the table. | | SetTokenNumber(Tokens: number): void | Sets the maximum number of tokens for response generation. | | SetTemperature(Temperature: number): void | Sets the temperature for response generation. |

The Ask(Question?: string, Verbose?: boolean): Promise<string | any> method is used to ask a question about the table data and retrieve the generated response from the OpenAI API.

  • Question (optional): A string representing the question you want to ask about the table data.
  • Verbose (optional): A boolean value indicating whether you want a detailed response or not. If set to true, the method will return a verbose response.

The method sends the provided question as a prompt to the OpenAI API, which generates a response based on the configured model and parameters. The generated response contains the answer or result based on the question asked.

If the Verbose parameter is set to true, the method will also generate a verbose response that includes the original question and the answer for better understanding.

The method returns a Promise that resolves to either a string or any data type depending on the response received from the API. The return value contains the generated response or the result of the question asked.

Please note that you need to configure the OpenAI API and set the table data using the Configure and SetData methods before calling the Ask method.

Enumeration: Languages

| Value | Description | | --- | --- | | ENGLISH | Represents the English language. | | SPANISH | Represents the Spanish language. |

Contributing

If you want to contribute to the project, you can do the following:

  • Report bugs or suggest improvements using the GitHub issues system.
  • Propose new features or improve documentation using pull requests.

License

This project is distributed under the MIT license. See the LICENSE file for more details.

If you find useful, consider supporting the project by making a donation via PayPal:

Support in Paypal ♥️