Giter Club home page Giter Club logo

oneai-node's Introduction

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

oneai-node's People

Contributors

dantannor avatar dependabot[bot] avatar michgur avatar ornakash avatar shaharsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

oneai-node's Issues

TypeError: OneAI is not a constructor

file:///D:/programming/projects/actives/javascript/video-maker/robots/text.js:10
const oneai = new OneAI(apiKeys.oneai)
              ^

TypeError: OneAI is not a constructor
    at file:///D:/programming/projects/actives/javascript/video-maker/robots/text.js:10:15
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.12.1
import OneAI from "oneai";

const oneai = new OneAI(apiKeys.oneai)
const pipeline = new oneai.Pipeline(oneai.skills.keywords())
const output = pipeline.run("Hi I'm Michael Jackson and I like doing the moonwalk dance move.")

console.log(output)

htmlArticle output is missing from OutputFields object

Hi there, we've been using the htmlArticle skill but currently using untyped access to it in the output object since it doesn't appear to be part of the type signature.

Just wanted to point it out in case you were planning on adding more to the output signatures in the future.

Enjoying the service so far, thanks!

"TypeError: oneai.Conversation is not a constructor"

Hi,

I just tried your sample in node.js to transcribe audio (https://docs.oneai.com/docs/transcribe-audio).
I got the following error:

const conversation = new oneai.Conversation(
^
TypeError: oneai.Conversation is not a constructor
at Object. (/home/laurent/dev/edu/oneai/hello.js:7:22)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
at node:internal/main/run_main_module:23:47

I installed your last npm published and I use node js v19.3.0.

Thanks for your help.

"Failed to transcribe audio"

Hi,
I just tried to run the asynchronous pipeline sample snipet (https://docs.oneai.com/docs/asynchronous-pipelines).
And I get the 40012 error code :

{"result":{"status_code":40012,"message":"Failed to transcribe audio","details":null,"request_id":"6855d38a-588e-414c-8ba0-02649471c997"},"task_id":"6855d38a-588e-414c-8ba0-02649471c997","status":"FAILED","completion_time":"2023-01-08T19:48:22.043000","creation_time":"2023-01-08T19:48:19.043000"}

I tried with 3 different files/formats and each time the same result.

Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.