Node.js API Reference
Clarifai Node.js API Reference
This is the API Reference documentation extracted from the source code.
App
App is a class that provides access to Clarifai API endpoints related to App information.
This is its hierarchy:
-
Lister↳
App
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
| Name | Type | Description |
|---|---|---|
config | AppConfig | The configuration object for the App. |
Returns
App
Overrides
Lister.constructor
Defined in
Properties
appInfo
• Private appInfo: App
Defined in
info
• info: AsObject
Defined in
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
| Name | Type |
|---|---|
«destructured» | Object |
› datasetId | string |
› params? | CreateDatasetParam |
Returns
Promise<AsObject>
A Dataset object for the specified dataset ID.
Defined in
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.js";
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
| Name | Type |
|---|---|
«destructured» | Object |
› modelId | string |
› params? | CreateModelParam |
Returns
Promise<AsObject>
A Model object for the specified model ID.
Defined in
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
| Name | Type |
|---|---|
«destructured» | Object |
› description | string |
› moduleId | string |
Returns
Promise<AsObject>
A Module object for the specified module ID.
Defined in
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
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› configFilePath | string | undefined |
› display? | boolean | true |
› generateNewId? | boolean | false |
Returns
Promise<AsObject>
A Workflow object for the specified workflow config.
Defined in
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
| Name | Type | Description |
|---|---|---|
dataset_id | Object | The dataset ID for the dataset to interact with. |
dataset_id.datasetId | string | - |
Returns
Promise<undefined | AsObject>
A Dataset object for the existing dataset ID.
Defined in
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
| Name | Type | Description |
|---|---|---|
datasetId | Object | The dataset ID for the app to delete. |
datasetId.datasetId | string | - |
Returns
Promise<void>
Defined in
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
| Name | Type | Description |
|---|---|---|
modelId | Object | The model ID for the model to delete. |
modelId.modelId | string | - |
Returns
Promise<void>
Defined in
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
| Name | Type | Description |
|---|---|---|
moduleId | Object | The module ID for the module to delete. |
moduleId.moduleId | string | - |
Returns
Promise<void>
Defined in
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
| Name | Type | Description |
|---|---|---|
workflowId | Object | The workflow ID for the workflow to delete. |
workflowId.workflowId | string | - |
Returns
Promise<void>
Defined in
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
| Name | Type |
|---|---|
«destructured» | Object |
› pageNo? | number |
› perPage? | number |
Returns
AsyncGenerator<AsObject[], void, unknown>
Yields
Concepts in the app.
Defined in
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
| Name | Type |
|---|---|
«destructured» | Object |
› pageNo? | number |
› params? | ListDatasetsParam |
› perPage? | number |
Returns
AsyncGenerator<AsObject[], void, unknown>
Yields
Dataset - Dataset objects for the datasets in the app.
Notes
Defaults to 16 per page
Defined in
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
| Name | Type |
|---|---|
«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.
Notes
Defaults to 16 per page
Defined in
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
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | {} |
› onlyInApp? | boolean | true |
› pageNo? | number | undefined |
› params? | ListModelsParam | {} |
› perPage? | number | undefined |
Returns
AsyncGenerator<AsObject[], void, unknown>
Notes
Defaults to 16 per page
Defined in
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
| Name | Type |
|---|---|
«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.
Notes
Defaults to 16 per page
Defined in
listTrainableModelTypes
▸ listTrainableModelTypes(): string[]
Returns
string[]
Defined in
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
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | {} |
› onlyInApp? | boolean | true |
› pageNo? | number | undefined |
› params? | ListWorkflowsParam | {} |
› perPage? | number | undefined |
Returns
AsyncGenerator<AsObject[], void, unknown>
Yields
Workflow - Workflow objects for the workflows in the app.
Notes
Defaults to 16 per page
Defined in
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
| Name | Type |
|---|---|
«destructured» | Object |
› modelId | string |
› modelUserAppId? | Object |
› modelUserAppId.appId | string |
› modelUserAppId.userId | string |
› modelVersionId? | string |
Returns
Promise<undefined | AsObject>
A model object for the specified model ID.
Defined in
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
| Name | Type | Description |
|---|---|---|
workflowId | Object | The workflow ID for a existing workflow. |
workflowId.workflowId | string | - |
Returns
Promise<undefined | AsObject>
A workflow object for the specified workflow ID.
Defined in
Dataset
Dataset is a class that provides access to Clarifai API endpoints related to Dataset information.
This is its hierarchy:
-
Lister↳
Dataset
Constructor
• new Dataset(«destructured»): Dataset
Parameters
| Name | Type |
|---|---|
«destructured» | DatasetConfig |
Returns
Dataset
Overrides
Lister.constructor
Defined in
Properties
STUB
• Protected STUB: V2Stub
Inherited from
Lister.STUB
Defined in
authHelper
• Protected authHelper: ClarifaiAuthHelper
Inherited from
Lister.authHelper
Defined in
base
• Protected base: string
Inherited from
Lister.base
Defined in
batchSize
• Private batchSize: number = 128
Defined in
defaultPageSize
• defaultPageSize: number
Inherited from
Lister.defaultPageSize
Defined in
info
• Private info: Dataset
Defined in
input
• Private input: Input
Defined in
metadata
• Protected metadata: [string, string][]
Inherited from
Lister.metadata
Defined in
pat
• Protected pat: string
Inherited from
Lister.pat
Defined in
rootCertificatesPath
• Protected rootCertificatesPath: string
Inherited from
Lister.rootCertificatesPath
Defined in
userAppId
• Protected userAppId: UserAppIDSet
Inherited from
Lister.userAppId
Defined in
Methods
convertStringToTimestamp
▸ convertStringToTimestamp(dateStr): Timestamp
Converts a string to a Timestamp object.
Parameters
| Name | Type | Description |
|---|---|---|
dateStr | string | The string to convert. |
Returns
Timestamp
A Timestamp object representing the given date string.
Inherited from
Lister.convertStringToTimestamp
Defined in
createVersion
▸ createVersion(«destructured»): Promise<AsObject>
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› description | string |
› id | string |
› metadata? | Record<string, JavaScriptValue> |
Returns
Promise<AsObject>
Defined in
deleteVersion
▸ deleteVersion(versionId): Promise<void>
Parameters
| Name | Type |
|---|---|
versionId | string |
Returns
Promise<void>
Defined in
grpcRequest
▸ grpcRequest<TRequest, TResponseObject, TResponse>(endpoint, requestData): Promise<TResponse>
Makes a gRPC request to the API.
Type parameters
| Name | Type |
|---|---|
TRequest | extends Message |
TResponseObject | extends Object |
TResponse | extends Object |
Parameters
| Name | Type |
|---|---|
endpoint | (request: TRequest, metadata: Metadata, options: Partial<CallOptions>) => Promise<TResponse> |
requestData | TRequest |
Returns
Promise<TResponse>
A Promise resolving to the result of the gRPC method call.
Inherited from
Lister.grpcRequest
Defined in
listPagesData
▸ listPagesData<TRequest, TResponseObject, TResponse>(endpoint, requestData, pageNo?, perPage?): Promise<TResponse>
Type parameters
| Name | Type |
|---|---|
TRequest | extends Message |
TResponseObject | extends Object |
TResponse | extends Object |
Parameters
| Name | Type | Default value |
|---|---|---|
endpoint | (request: TRequest, metadata: Metadata, options: Partial<CallOptions>) => Promise<TResponse> | undefined |
requestData | TRequest | undefined |
pageNo | number | 1 |
perPage | number | undefined |
Returns
Promise<TResponse>
Inherited from
Lister.listPagesData
Defined in
listPagesGenerator
▸ listPagesGenerator<TRequest, TResponseObject, TResponse>(endpoint, requestData, pageNo?, perPage?): AsyncGenerator<TResponse, void, unknown>
Type parameters
| Name | Type |
|---|---|
TRequest | extends Message |
TResponseObject | extends Object |
TResponse | extends Object |
Parameters
| Name | Type | Default value |
|---|---|---|
endpoint | (request: TRequest, metadata: Metadata, options: Partial<CallOptions>) => Promise<TResponse> | undefined |
requestData | TRequest | undefined |
pageNo | number | 1 |
perPage | number | undefined |
Returns
AsyncGenerator<TResponse, void, unknown>
Inherited from
Lister.listPagesGenerator
Defined in
listVersions
▸ listVersions(pageNo?, perPage?): AsyncGenerator<AsObject[], void, unknown>
Parameters
| Name | Type |
|---|---|
pageNo? | number |
perPage? | number |
Returns
AsyncGenerator<AsObject[], void, unknown>
Defined in
uploadFromCSV
▸ uploadFromCSV(«destructured»): Promise<void>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› batchSize? | number | 128 |
› csvPath | string | undefined |
› csvType | "url" | "raw" | "file" | undefined |
› inputType? | "image" | "text" | "video" | "audio" | "text" |
› labels? | boolean | true |
› uploadProgressEmitter? | InputBulkUpload | undefined |
Returns
Promise<void>
Defined in
uploadFromFolder
▸ uploadFromFolder(«destructured»): Promise<void>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› batchSize? | number | undefined |
› folderPath | string | undefined |
› inputType | "image" | "text" | undefined |
› labels? | boolean | false |
› uploadProgressEmitter? | InputBulkUpload | undefined |
Returns
Promise<void>
Defined in
Input
Input is a class that provides access to Clarifai API endpoints related to Input information.
This is its hierarchy:
-
Lister↳
Input
Constructor
• new Input(params): Input
Initializes an input object.
Example
import { Input } from "clarifai-nodejs";
export const input = new Input({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
Parameters
| Name | Type | Description |
|---|---|---|
params | Object | The parameters for the Input object. |
params.authConfig? | AuthConfig | - |
Returns
Input
Overrides
Lister.constructor
Defined in
Properties
numOfWorkers
• Private numOfWorkers: number
Defined in
Methods
bulkUpload
▸ bulkUpload(«destructured»): Promise<void>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› batchSize? | number | 128 |
› inputs | Input[] | undefined |
› uploadProgressEmitter? | InputBulkUpload | undefined |
Returns
Promise<void>
Defined in
deleteFailedInputs
▸ deleteFailedInputs(«destructured»): Promise<Input[]>
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› inputs | Input[] |
Returns
Promise<Input[]>
Defined in
patchInputs
▸ patchInputs(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› action? | string | "merge" |
› inputs | Input[] | undefined |
Returns
Promise<string>
Defined in
retryUploads
▸ retryUploads(«destructured»): Promise<void>
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› failedInputs | Input[] |
Returns
Promise<void>
Defined in
uploadAnnotations
▸ uploadAnnotations(«destructured»): Promise<Annotation[]>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› batchAnnot | Annotation[] | undefined |
› showLog? | boolean | true |
Returns
Promise<Annotation[]>
Defined in
uploadBatch
▸ uploadBatch(«destructured»): Promise<Input[]>
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› inputs | Input[] |
Returns
Promise<Input[]>
Defined in
uploadFromBytes
▸ uploadFromBytes(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioBytes? | null | Uint8Array | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageBytes? | null | Uint8Array | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textBytes? | null | Uint8Array | null |
› videoBytes? | null | Uint8Array | null |
Returns
Promise<string>
Defined in
uploadFromFile
▸ uploadFromFile(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioFile? | null | string | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageFile? | null | string | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textFile? | null | string | null |
› videoFile? | null | string | null |
Returns
Promise<string>
Defined in
uploadFromUrl
▸ uploadFromUrl(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioUrl? | null | string | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageUrl? | null | string | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textUrl? | null | string | null |
› videoUrl? | null | string | null |
Returns
Promise<string>
Defined in
uploadInputs
▸ uploadInputs(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› inputs | Input[] | undefined |
› showLog? | boolean | true |
Returns
Promise<string>
Defined in
uploadText
▸ uploadText(«destructured»): Promise<string>
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› datasetId? | null | string | null |
› inputId | string | undefined |
› rawText | string | undefined |
Returns
Promise<string>
Defined in
waitForInputs
▸ waitForInputs(«destructured»): Promise<boolean>
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› inputJobId | string |
Returns
Promise<boolean>
Defined in
getBboxProto
▸ getBboxProto(«destructured»): Annotation
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› bbox | number[] |
› inputId | string |
› label | string |
Returns
Annotation
Defined in
getImageInputsFromFolder
▸ getImageInputsFromFolder(«destructured»): Input[]
Upload image inputs from folder.
Example
import { Input, Model } from "clarifai-nodejs";
import path from "path";
// Generate a new GRPC compatible Input object from buffer
const imageInputs = Input.getImageInputsFromFolder({
// Ensure the directory contains a list of images
folderPath: path.resolve(__dirname, "path/to/imageFolder"),
});
// The input can now be used as an input for a model prediction methods
const model = new Model({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
modelId: "multimodal-clip-embed",
});
const prediction = await model.predict({
inputs: imageInputs,
});
console.log(prediction);
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› datasetId? | null | string | null |
› folderPath | string | undefined |
› labels? | boolean | false |
Returns
Input[]
Defined in
getInputFromBytes
▸ getInputFromBytes(«destructured»): Input
Creates an input proto from bytes.
Example
import { Input, Model } from "clarifai-nodejs";
import * as fs from "fs";
const imageBuffer = fs.readFileSync("path/to/image.jpg");
// Generate a new GRPC compatible Input object from buffer
const imageInput = Input.getInputFromBytes({
inputId: "demo",
imageBytes: imageBuffer,
});
// The input can now be used as an input for a model prediction methods
const model = new Model({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
modelId: "multimodal-clip-embed",
});
const prediction = await model.predict({
inputs: [imageInput],
});
console.log(prediction);
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioBytes? | null | Uint8Array | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageBytes? | null | Uint8Array | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textBytes? | null | Uint8Array | null |
› videoBytes? | null | Uint8Array | null |
Returns
Input
An Input object for the specified input ID.
Defined in
getInputFromFile
▸ getInputFromFile(«destructured»): Input
Create input proto from files.
Example
import { Input, Model } from "clarifai-nodejs";
import path from "path";
// Generate a new GRPC compatible Input object from buffer
const imageInput = Input.getInputFromFile({
inputId: "demo",
imageFile: path.resolve(__dirname, "path/to/image.jpg"),
});
// The input can now be used as an input for a model prediction methods
const model = new Model({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
modelId: "multimodal-clip-embed",
});
const prediction = await model.predict({
inputs: [imageInput],
});
console.log(prediction);
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioFile? | null | string | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageFile? | null | string | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textFile? | null | string | null |
› videoFile? | null | string | null |
Returns
Input
- An Input object for the specified input ID.
Defined in
getInputFromUrl
▸ getInputFromUrl(«destructured»): Input
Upload input from URL.
Example
import { Input, Model } from "clarifai-nodejs";
// Generate a new GRPC compatible Input object from buffer
const imageInput = Input.getInputFromUrl({
inputId: "demo",
imageUrl: "https://samples.clarifai.com/dog2.jpeg",
});
// The input can now be used as an input for a model prediction methods
const model = new Model({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
modelId: "multimodal-clip-embed",
});
const prediction = await model.predict({
inputs: [imageInput],
});
console.log(prediction);
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioUrl? | null | string | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imageUrl? | null | string | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textUrl? | null | string | null |
› videoUrl? | null | string | null |
Returns
Input
- Job ID for the upload request.
Defined in
getInputsFromCsv
▸ getInputsFromCsv(«destructured»): Promise<Input[]>
Create Input proto from CSV File. Supported columns are: 'inputid', 'input', 'concepts', 'metadata', 'geopoints'
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› csvPath | string | undefined |
› csvType | "url" | "raw" | "file" | "raw" |
› datasetId? | null | string | null |
› inputType | "image" | "text" | "video" | "audio" | "text" |
› labels | boolean | true |
Returns
Promise<Input[]>
- An array of Input objects for the specified input ID.
Defined in
getMaskProto
▸ getMaskProto(«destructured»): Annotation
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› inputId | string |
› label | string |
› polygons | Polygon[] |
Returns
Annotation
Defined in
getMultimodalInput
▸ getMultimodalInput(«destructured»): Input
Create input proto for text and image from bytes or url
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› datasetId? | null | string | null |
› imageBytes? | null | Uint8Array | null |
› imageUrl? | null | string | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› rawText? | null | string | null |
› textBytes? | null | Uint8Array | null |
Returns
Input
- An Input object for the specified input ID.
Defined in
getProto
▸ getProto(«destructured»): Input
Create input proto for image data type.
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› audioPb? | null | { base64: string } | null |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› imagePb? | null | { base64: string ; url?: undefined } | { base64?: undefined ; url: string } | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› textPb? | null | { raw: string } | null |
› videoPb? | null | { base64: string } | null |
Returns
Input
- An Input object for the specified input ID.
Defined in
getTextInput
▸ getTextInput(«destructured»): Input
Create input proto for text data type from raw text.
Example
import { Input, Model } from "clarifai-nodejs";
// Generate a new GRPC compatible Input object from buffer
const textInput = Input.getTextInput({
inputId: "demo",
rawText: "Sample text for input generation",
});
// The input can now be used as an input for a model prediction methods
const model = new Model({
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
modelId: "multimodal-clip-embed",
});
const prediction = await model.predict({
inputs: [textInput],
});
console.log(prediction);
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› datasetId? | null | string | null |
› geoInfo? | null | AsObject | null |
› inputId | string | undefined |
› labels? | null | string[] | null |
› metadata? | null | Record<string, JavaScriptValue> | null |
› rawText | string | undefined |
Returns
Input
- An Input object for the specified input ID.
Defined in
getTextInputsFromFolder
▸ getTextInputsFromFolder(«destructured»): Input[]
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | undefined |
› datasetId | null | string | null |
› folderPath | string | undefined |
› labels | boolean | false |
Returns
Input[]
Defined in
Model
Model is a class that provides access to Clarifai API endpoints related to Model information.
This is its hierarchy:
-
Lister↳
Model
Constructor
• new Model(config): Model
Initializes a Model object.
Example
import { Model } from "clarifai-nodejs";
export const model = new Model({
modelId: "face-detection",
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
Parameters
| Name | Type |
|---|---|
config | ModelConfig |
Returns
Model
Overrides
Lister.constructor
Defined in
Properties
appId
• Private appId: string
Defined in
id
• Private id: string
Defined in
modelInfo
• modelInfo: Model
Defined in
modelUserAppId
• Private modelUserAppId: undefined | UserAppIDSet
Defined in
modelVersion
• Private modelVersion: undefined | { id: string }
Defined in
runner
• Private runner: undefined | RunnerSelector
Defined in
trainingParams
• Private trainingParams: Record<string, unknown>
Defined in
Methods
availableMethods
▸ availableMethods(): Promise<string[]>
Returns
Promise<string[]>
Defined in
constructRequestWithMethodSignature
▸ constructRequestWithMethodSignature(request, config): Promise<PostModelOutputsRequest>
Parameters
| Name | Type |
|---|---|
request | PostModelOutputsRequest |
config | TextModelPredictConfig |
Returns
Promise<PostModelOutputsRequest>
Defined in
createVersion
▸ createVersion(modelVersion): Promise<undefined | AsObject>
Creates a model version for the Model.
Example
import { Model } from "clarifai-nodejs";
import {
ModelVersion,
OutputInfo,
} from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import { Struct } from "google-protobuf/google/protobuf/struct_pb.js";
export const model = new Model({
modelId: "margin-100-image-cropper",
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
| Name | Type |
|---|---|
modelVersion | ModelVersion |
Returns
Promise<undefined | AsObject>
Defined in
deleteVersion
▸ deleteVersion(versionId): Promise<void>
Deletes a model version for the Model.
Example
import { Model } from "clarifai-nodejs";
export const model = new Model({
modelId: "face-detection",
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});
model.deleteVersion("version_id");
Parameters
| Name | Type | Description |
|---|---|---|
versionId | string | The version ID to delete. |
Returns
Promise<void>
Defined in
generate
▸ generate(«destructured»): AsyncGenerator<AsObject[], any, unknown>
Parameters
| Name | Type |
|---|---|
«destructured» | TextModelPredictConfig |
Returns
AsyncGenerator<AsObject[], any, unknown>
Defined in