Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oneai-stage

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oneai-stage

NLP-as-a-service

  • 0.1.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NLP-as-a-service

One AI Node.js SDK

OneAI is a NLP as a service platform. Our API enables language comprehension in context, transforming texts from any source into structured data to use in code.

This SDK provides safe and convenient access to OneAI's API from a node.js environment.

Documentation

See the One AI documentation

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 OneAI 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.api_key = '<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- audio files to be transcribed & analyzed
  • .jpg- detect text in pictures via OCR Upload a file via the oneai.File class, i.e
const input = new oneai.File('./example.txt');
const pipeline = new oneai.Pipeline(...);
const output = await pipeline.run(input);

Support

Feel free to submit issues in this repo, contact us at devrel@oneai.com, or chat with us on Discord

FAQs

Package last updated on 08 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc