Skip to main content

clarifai-nodejs / Exports / App

Class: App

App is a class that provides access to Clarifai API endpoints related to App information.

Hierarchy

  • Lister

    App

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new App(config): App

Initializes an App object.

Example

import { App } from "clarifai-nodejs";

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

Parameters

NameTypeDescription
configAppConfigThe configuration object for the App.

Returns

App

Overrides

Lister.constructor

Defined in

client/app.ts:98

Properties

appInfo

Private appInfo: App

Defined in

client/app.ts:83

Methods

createDataset

createDataset(«destructured»): Promise<AsObject>

Creates a dataset for the app.

Example

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

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

const dataset = await app.createDataset({
datasetId: "dog-image-collection",
});

// Dataset is created, now let's build an image input that uses the new dataset id
const inputProto = Input.getInputFromUrl({
datasetId: dataset.id,
inputId: "dog-tiff",
imageUrl: "https://samples.clarifai.com/dog.tiff",
labels: ["dog"],
geoInfo: {
latitude: 40,
longitude: -30,
},
metadata: { Breed: "Saint Bernard" },
});

const input = new Input({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

// upload the input by using instance of the Input class
// this input will be stored under the newly created dataset
const inputJobId = await input.uploadInputs({
inputs: [inputProto],
});

console.log(inputJobId); // job id of the input upload

Parameters

NameType
«destructured»Object
› datasetIdstring
› params?CreateDatasetParam

Returns

Promise<AsObject>

A Dataset object for the specified dataset ID.

Defined in

client/app.ts:420


createModel

createModel(«destructured»): Promise<AsObject>

Creates a model for the app.

Example

import { Model, App } from "clarifai-nodejs";
import {
ModelVersion,
OutputInfo,
} from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import { Struct } from "google-protobuf/google/protobuf/struct_pb";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

// Creating a new image crop model
const newModelObject = await app.createModel({
modelId: "margin-100-image-cropper",
params: {
modelTypeId: "image-crop",
description: "Custom crop model with 100px margin",
},
});

// Initializing the newly created model
const model = new Model({
modelId: newModelObject.id,
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

// Creating a GRPC compatible outputInfo object with custom margin parameters
const outputInfo = new OutputInfo().setParams(
Struct.fromJavaScript({ margin: 1.5 }),
);
// GRPC compatible ModelVersion object with previously created output info config
const modelVersion = new ModelVersion()
.setDescription("Setting output info margin parameters to 1.5")
.setOutputInfo(outputInfo);

// Creating a new version of the model with previously created output info config
const modelObjectWithVersion = await model.createVersion(modelVersion);

console.log(modelObjectWithVersion);

Parameters

NameType
«destructured»Object
› modelIdstring
› params?CreateModelParam

Returns

Promise<AsObject>

A Model object for the specified model ID.

Defined in

client/app.ts:462


createModule

createModule(«destructured»): Promise<AsObject>

Creates a module for the app.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

const module = await app.createModule({
moduleId: "new-module",
description: "New module",
});

console.log(module);

Parameters

NameType
«destructured»Object
› descriptionstring
› moduleIdstring

Returns

Promise<AsObject>

A Module object for the specified module ID.

Defined in

client/app.ts:501


createWorkflow

createWorkflow(«destructured»): Promise<AsObject>

Creates a workflow for the app.

Example

import { App } from "clarifai-nodejs";
import path from "path";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const workflowFile = path.resolve(__dirname, "workflow/moderation.yml");
const workflow = await app.createWorkflow({ configFilePath: workflowFile });
console.log(workflow);

/**
* Workflow config file in the path `workflow/moderation.yml`:
*/
/*
workflow:
id: test-mbmn
nodes:
- id: detector
model:
modelId: face-detection
modelVersionId: 45fb9a671625463fa646c3523a3087d5
- id: cropper
model:
modelId: margin-110-image-crop
modelVersionId: b9987421b40a46649566826ef9325303
nodeInputs:
- nodeId: detector
- id: face-sentiment
model:
modelId: face-sentiment-recognition
modelVersionId: a5d7776f0c064a41b48c3ce039049f65
nodeInputs:
- nodeId: cropper
- id: moderation
model:
modelId: moderation-recognition
modelVersionId: 7cde8e92896340b0998b8260d47f1502
*/

Parameters

NameTypeDefault value
«destructured»Objectundefined
› configFilePathstringundefined
› display?booleantrue
› generateNewId?booleanfalse

Returns

Promise<AsObject>

A Workflow object for the specified workflow config.

Defined in

client/app.ts:537


dataset

dataset(dataset_id): Promise<undefined | AsObject>

Returns a Dataset object for the existing dataset ID.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const dataset = await app.dataset({
datasetId: "dataset-id",
});
console.log(dataset);

Parameters

NameTypeDescription
dataset_idObjectThe dataset ID for the dataset to interact with.
dataset_id.datasetIdstring-

Returns

Promise<undefined | AsObject>

A Dataset object for the existing dataset ID.

Defined in

client/app.ts:727


deleteDataset

deleteDataset(datasetId): Promise<void>

Deletes a dataset for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

await app.deleteDataset({ datasetId: "dataset-id" });

Parameters

NameTypeDescription
datasetIdObjectThe dataset ID for the app to delete.
datasetId.datasetIdstring-

Returns

Promise<void>

Defined in

client/app.ts:754


deleteModel

deleteModel(modelId): Promise<void>

Deletes a model for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

await app.deleteModel({ modelId: "modelId" });

Parameters

NameTypeDescription
modelIdObjectThe model ID for the model to delete.
modelId.modelIdstring-

Returns

Promise<void>

Defined in

client/app.ts:777


deleteModule

deleteModule(moduleId): Promise<void>

Deletes a module for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

await app.deleteModule({ moduleId: "moduleId" });

Parameters

NameTypeDescription
moduleIdObjectThe module ID for the module to delete.
moduleId.moduleIdstring-

Returns

Promise<void>

Defined in

client/app.ts:823


deleteWorkflow

deleteWorkflow(workflowId): Promise<void>

Deletes a workflow for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

await app.deleteWorkflow({ workflowId: "workflowId" });

Parameters

NameTypeDescription
workflowIdObjectThe workflow ID for the workflow to delete.
workflowId.workflowIdstring-

Returns

Promise<void>

Defined in

client/app.ts:800


listConcepts

listConcepts(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all the concepts for the app.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listConcepts().next();
const concepts = list.value;
console.log(concepts);

Parameters

NameType
«destructured»Object
› pageNo?number
› perPage?number

Returns

AsyncGenerator<AsObject[], void, unknown>

Yields

Concepts in the app.

Defined in

client/app.ts:382


listDataSets

listDataSets(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all the datasets for the app.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listDataSets().next();
const datasets = list.value;
console.log(datasets);

Parameters

NameType
«destructured»Object
› pageNo?number
› params?ListDatasetsParam
› perPage?number

Returns

AsyncGenerator<AsObject[], void, unknown>

Yields

Dataset - Dataset objects for the datasets in the app.

Remarks

Defaults to 16 per page

Defined in

client/app.ts:131


listInstalledModuleVersions

listInstalledModuleVersions(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all installed module versions in the app.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listInstalledModuleVersions().next();
const moduleVersions = list.value;
console.log(moduleVersions);

Parameters

NameType
«destructured»Object
› pageNo?number
› params?ListInstalledModuleVersionsParam
› perPage?number

Returns

AsyncGenerator<AsObject[], void, unknown>

Yields

Module - Module objects for the installed module versions in the app.

Remarks

Defaults to 16 per page

Defined in

client/app.ts:337


listModels

listModels(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all the available models for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listModels().next();
const models = list.value;
console.log(models);

Parameters

NameTypeDefault value
«destructured»Object{}
› onlyInApp?booleantrue
› pageNo?numberundefined
› params?ListModelsParam{}
› perPage?numberundefined

Returns

AsyncGenerator<AsObject[], void, unknown>

Remarks

Defaults to 16 per page

Defined in

client/app.ts:175


listModules

listModules(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all the available modules for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listModules().next();
const modules = list.value;
console.log(modules);

Parameters

NameType
«destructured»Object
› onlyInApp?boolean
› pageNo?number
› params?ListModulesParam
› perPage?number

Returns

AsyncGenerator<AsObject[], void, unknown>

Yields

Module - Module objects for the modules in the app.

Remarks

Defaults to 16 per page

Defined in

client/app.ts:286


listTrainableModelTypes

listTrainableModelTypes(): string[]

Returns

string[]

Defined in

client/app.ts:406


listWorkflows

listWorkflows(«destructured»?): AsyncGenerator<AsObject[], void, unknown>

Lists all the available workflows for the user.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const list = await app.listWorkflows().next();
const workflows = list.value;
console.log(workflows);

Parameters

NameTypeDefault value
«destructured»Object{}
› onlyInApp?booleantrue
› pageNo?numberundefined
› params?ListWorkflowsParam{}
› perPage?numberundefined

Returns

AsyncGenerator<AsObject[], void, unknown>

Yields

Workflow - Workflow objects for the workflows in the app.

Remarks

Defaults to 16 per page

Defined in

client/app.ts:233


model

model(«destructured»): Promise<undefined | AsObject>

Returns a Model object for the existing model ID.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
const model = await app.model({
modelId: "custom-crop-model",
modelVersionId: "0.0.1",
});
console.log(model);

Parameters

NameType
«destructured»Object
› modelIdstring
› modelVersionId?string

Returns

Promise<undefined | AsObject>

A model object for the specified model ID.

Defined in

client/app.ts:666


workflow

workflow(workflowId): Promise<undefined | AsObject>

Returns a Workflow object for the existing workflow ID.

Example

import { App } from "clarifai-nodejs";

const app = new App({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

const workflow = await app.workflow({ workflowId: "workflowId" });
console.log(workflow);

Parameters

NameTypeDescription
workflowIdObjectThe workflow ID for a existing workflow.
workflowId.workflowIdstring-

Returns

Promise<undefined | AsObject>

A workflow object for the specified workflow ID.

Defined in

client/app.ts:699