Skip to content

Commit

Permalink
docs: updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Apr 1, 2024
1 parent b1567c3 commit 821fb54
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
![Clarifai logo](https://www.clarifai.com/hubfs/Clarifai-logo-dark.svg)
<h1 align="center">
<a href="https://www.clarifai.com/"><img alt="Clarifai" title="Clarifai" src="https://upload.wikimedia.org/wikipedia/commons/b/bc/Clarifai_Logo_FC_Web.png"></a>
</h1>

<h2 align="center">
Clarifai Node.js SDK</a>
</h2>

[![npm](https://img.shields.io/npm/v/clarifai-nodejs)](https://www.npmjs.com/package/clarifai-nodejs)
[![Build](https://github.com/Clarifai/clarifai-nodejs/actions/workflows/build.yml/badge.svg)](https://github.com/Clarifai/clarifai-nodejs/actions/workflows/build.yml)
[![Discord](https://img.shields.io/discord/1145701543228735582)](https://discord.com/invite/26upV8Y4Nd)

> This library is currently in beta, any improvements & feedback welcome!
> This library is currently in Developer preview, any improvements & feedback welcome!
# Clarifai Node.js SDK

Expand Down Expand Up @@ -38,6 +44,78 @@ module.exports = nextConfig

## Usage

### Using Models

Using the celebrity face recognition model to predict the celebrity in a given picture. For list of all available models visit [our models page](https://clarifai.com/explore/models).

```ts
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](https://docs.clarifai.com/portal-guide/workflows/) to analyze sentiment of a given image. For list of all available workflows visit [our workflows page](https://clarifai.com/explore/workflows)

```ts
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 [our portal](https://docs.clarifai.com/clarifai-basics/applications/create-an-application/).

```ts
import { User } from "clarifai-nodejs";

Expand Down Expand Up @@ -68,3 +146,5 @@ For full usage details, checkout our [API Reference docs](https://docs.clarifai.
This library doesn't use semantic versioning. The first two version numbers (`X.Y` out of `X.Y.Z`) follow the API (backend) versioning, and whenever the API gets updated, this library follows it.

The third version number (`Z` out of `X.Y.Z`) is used by this library for any independent releases of library-specific improvements and bug fixes.

The developer preview versions of the SDK will follow `0.0.V` format where `V` simply a bump from previous developer preview version update

0 comments on commit 821fb54

Please sign in to comment.