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

oneai

v0.8.4

Published

Make your app understand language. Summarize conversations, categorize articles, and more.

Downloads

1,867

Readme

Logo

Natural Language Processing API

API Key Build Coverage Status Version Downloads License Try on RunKit Discord

One AI provides natural language processing for Node.js. Some use cases include:

  • Summarize conversations and articles
  • Detect sentiments and emotions
  • Detect topics and classify content

Alt text

Example of summarizing a Zoom meeting:

const conversation = [
   { speaker: "Mario", utterance: "We need to increase our coin collection rate" },
   { speaker: "Luigi", utterance: "Agreed, Mario, let's invest in more power-ups" },
   // boring meeting...
];

const pipeline = new oneai.Pipeline(
   oneai.skills.summarize(),
);

pipeline.run(conversation);

// Output: Luigi and Mario agreed to fix the plumbing at 9am on Friday.

See the full documentation here.

Getting started

Installation

npm install oneai

Authentication

You will need a valid API key for all requests. Register and create a key for your project in One AI Studio. As a security measure we only show the key once, so make sure to keep it somewhere safe.

Example

import OneAI from 'oneai';

oneai = new OneAI('<YOUR-API-KEY>');

const pipeline = new oneai.Pipeline(
    oneai.skills.names(),
    oneai.skills.summarize({ min_length: 20 }),
    oneai.skills.highlights()
);
const output = await pipeline.run('analyze this text');
console.log(output);

Pipeline API

The pipeline API enables analyzing and transforming text using various skills. A skill is a package of trained NLP models, available via API, which accept text from various language sources as input and respond with processed texts and extracted metadata. Chaining skills together creates a pipeline.

OneAI Studio

The best way to create a pipeline is to use our studio where you can craft a pipeline using an easy graphical interface and then paste the generated code back into your repository.

Basic Example

Let's say you're interested in extracting keywords from the text.

const pipeline = new oneai.Pipeline(
    oneai.skills.keywords(),
);
const output = await pipeline.run('analyze this text');
console.log(output);

Multi Skills request

Let's say you're interested in extracting keywords and emotions from the text.

const pipeline = new oneai.Pipeline(
    oneai.skills.keywords(),
    oneai.skills.emotions(),
);
const output = await pipeline.run('analyze this text');
console.log(output);

Analyzer Skills vs Generator Skills

Skills can do either text analysis, and then their output are labels and spans (labels location in the analyzed text), or they can be generator skills, in which case they transform the input text into an output text.

Here's an example for a pipeline that combines both type of skills. It will extract keywords and emotions from the text, and then summarize it.

const pipeline = new oneai.Pipeline(
    oneai.skills.keywords(),
    oneai.skills.emotions(),
    oneai.skills.summarize(),
);
const output = await pipeline.run('analyze this text');
console.log(output);

Order is Important

When the pipeline is invoked, it is invoked with an original text you submit. If a generator skill is ran, then all following skills will use its generated text rather then the original text. In this example, for instance, we change the order of the pipeline from the previous example, and the results will be different. Instead of extracting keywords and emotions from the original text, keywords and emotions will be extracted from the generated summary.

const pipeline = new oneai.Pipeline(
    oneai.skills.summarize(),
    oneai.skills.keywords(),
    oneai.skills.emotions(),
);
const output = await pipeline.run('analyze this text');
console.log(output);

Configuring Skills

Many skills are configurable as you can find out in the docs. Let's use the exact same example, this time however, we'll limit the summary length to 50 words.

const pipeline = new oneai.Pipeline(
    oneai.skills.summarize({max_length: 50}),
    oneai.skills.keywords(),
    oneai.skills.emotions(),
);
const output = await pipeline.run('analyze this text');
console.log(output);

Output

The structure of the output is dynamic, and corresponds to the Skills used, whether they are generators or analyzers, and their order in the pipeline. Each output object contains the input text (which can be the original input or text produced by generator Skills), and a list of labels detected by analyzer Skills, that contain the extracted data.

Let's say we run this code

const text = "The Hitchhiker's Guide to the Galaxy is a science fiction comedy radio series written by Douglas Adams ";
const pipeline = new oneai.Pipeline(
    oneai.skills.names(),
    oneai.skills.summarize({ min_length: 20 }),
    oneai.skills.names(),
);
const output = await pipeline.run(text);
console.log(output);

In plain English, we extract names from the text, then summarize it, and then extract names from the summary. Here's what the reponse would look like (the important thing to notice, whenever a generator skill runs, summarize in this case, all following skills responses will be embedded within the generator result as it changes the text the skill processes:

{
   "text":"The Hitchhiker's Guide to the Galaxy is a science fiction comedy radio series written by Douglas Adams ",
   "names":[ // This array will contain the names detected in the original text
      {
         "type":"name", // label type
         "name":"WORK_OF_ART", // label class
         "value":"The Hitchhiker's Guide to the Galaxy", // label value
         "output_spans":[ // label spans (where the name was detected in the text)
            {
               "section":0,
               "start":0,
               "end":36
            }
         ],
      },
      ...
   ],
   "summary":{
      // this actual summary
      "text":"The Hitchhiker's Guide to the Galaxy is a science fiction comedy",
      // the names detected in the summary
      "names":[
         {
            "type":"name",
            "name":"WORK_OF_ART",
            "value":"The Hitchhiker's Guide to the Galaxy",
            "output_spans":[
               {
                  "section":0,
                  "start":0,
                  "end":36
               }
            ],
         },
         ...
      ]
   }
}

File Uploads

Our API supports the following file extensions:

  • .txt- text content
  • .json- conversations in the One AI conversation format
  • .srt- analyze captions as conversations
  • .wav, .mp3- audio files to be transcribed & analyzed
  • .jpg- detect text in pictures via OCR Upload a file via the Pipeline.runFile method, i.e
const filePath = './example.txt';
const pipeline = new oneai.Pipeline(...);
const output = await pipeline.runFile(filePath);

Support

Feel free to submit issues in this repo, contact us at [email protected], or chat with us on Discord