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

clarifai-nodejs

v0.0.3

Published

The official Clarifai Node.js SDK

Downloads

77

Readme

npm Build Discord

This library is currently in developer preview, any improvements & feedback welcome!

Clarifai Node.js SDK

This is the official Node.js client for interacting with our powerful API. The Clarifai Node.js SDK offers a comprehensive set of tools to integrate Clarifai's AI platform to leverage computer vision capabilities like classification, detection, segmentation and natural language capabilities like classification, summarisation, generation, Q&A, etc into your applications. With just a few lines of code, you can leverage cutting-edge artificial intelligence to unlock valuable insights from visual and textual content.

Website | Schedule Demo | Signup for a Free Account | API Docs | Clarifai Community | Node.js SDK Docs | Examples | Discord

Give the repo a star ⭐

Installation

npm install clarifai-nodejs

Next.js Server Components

To use Clarifai Node.js in Next.js App Directory with server components, you will need to add clarifai-nodejs-grpc package (which is one of the primary dependency of Clarifai Node.js SDK) to the serverComponentsExternalPackages config of next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ['clarifai-nodejs-grpc'],
  },
}

module.exports = nextConfig

Usage

Clarifai uses Personal Access Tokens(PATs) to validate requests. You can create and manage PATs under your Clarifai account security settings.

  • 🔗 Create PAT: Log into Portal → Profile Icon → Security Settings → Create Personal Access Token → Set the scopes → Confirm

Export your PAT as an environment variable. Then, import and initialize the API Client.

Set PAT as environment variable through terminal:

export CLARIFAI_PAT={your personal access token}

or use dotenv to load environment variables via a .env file

Using Models

Using the celebrity face recognition model to predict the celebrity in a given picture. For list of all available models visit clarifai models page.

import { Input, Model } from "clarifai-nodejs";

const input = Input.getInputFromUrl({
  inputId: "test-image",
  imageUrl:
    "https://samples.clarifai.com/celebrity.jpeg",
});

const model = new Model({
  authConfig: {
    pat: process.env.CLARIFAI_PAT!,
    userId: process.env.CLARIFAI_USER_ID!,
    appId: process.env.CLARIFAI_APP_ID!
  },
  modelId: "celebrity-face-recognition",
});

model
  .predict({
    inputs: [input],
  })
  .then((response) => {
    const result = response?.[0].data?.conceptsList[0].name ?? "unrecognized";
    console.log(result);
  })
  .catch(console.error);

Using Workflows

Using a custom workflow built on clarifai.com to analyze sentiment of a given image. For list of all available workflows visit clarifai workflows page

import { Input, Workflow } from "clarifai-nodejs";

const input = Input.getInputFromUrl({
  inputId: "test-image",
  imageUrl:
    "https://samples.clarifai.com/celebrity.jpeg",
});

const workflow = new Workflow({
  authConfig: {
    pat: process.env.CLARIFAI_PAT!,
    userId: process.env.CLARIFAI_USER_ID!,
    appId: process.env.CLARIFAI_APP_ID!
  },
  workflowId: "workflow-238a93",
});

workflow
  .predict({
    inputs: [input],
  })
  .then((response) => {
    const result =
      response.resultsList[0].outputsList[0].data?.regionsList[0].data
        ?.conceptsList[0].name ?? "unrecognized";
    console.log(result);
  })
  .catch(console.error);

Listing available apps in an user account

On Clarifai, apps act as a central repository for models, datasets, inputs and other resources and information. Checkout how to create apps on clarifai portal.

import { User } from "clarifai-nodejs";

export const user = new User({
  pat: process.env.CLARIFAI_PAT!,
  userId: process.env.CLARIFAI_USER_ID!,
  appId: process.env.CLARIFAI_APP_ID!,
});

const list = await user
  .listApps({
    pageNo: 1,
    perPage: 20,
    params: {
      sortAscending: true,
    },
  })
  .next();

const apps = list.value;
console.log(apps);

For full usage details, checkout our API Reference docs