Skip to main content

Model

clarifai-nodejs / Exports / Model

Class: Model

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

Hierarchy

  • Lister

    Model

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Model(«destructured»): 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

NameType
«destructured»{ authConfig?: AuthConfig ; modelId?: undefined ; modelVersion?: { id: string } ; url: ClarifaiUrl } | { authConfig?: AuthConfig ; modelId: string ; modelVersion?: { id: string } ; url?: undefined }

Returns

Model

Overrides

Lister.constructor

Defined in

client/model.ts:66

Properties

appId

Private appId: string

Defined in

client/model.ts:47


id

Private id: string

Defined in

client/model.ts:48


modelInfo

Private modelInfo: Model

Defined in

client/model.ts:50


modelVersion

Private modelVersion: undefined | { id: string }

Defined in

client/model.ts:49


trainingParams

Private trainingParams: Record\<string, unknown>

Defined in

client/model.ts:51

Methods

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";

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

NameType
modelVersionModelVersion

Returns

Promise\<undefined | AsObject>

Defined in

client/model.ts:395


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

NameTypeDescription
versionIdstringThe version ID to delete.

Returns

Promise\<void>

Defined in

client/model.ts:370


getParamInfo

getParamInfo(param): Promise\<Record\<string, any>>

Returns the param info 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.getParamInfo("template");

Parameters

NameType
paramstring

Returns

Promise\<Record\<string, any>>

Defined in

client/model.ts:308


getParams

getParams(template?, saveTo?): Promise\<Record\<string, any>>

Returns the model params for the model type as object & also writes to a yaml file

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!,
},
});

const modelParams = await model.getParams("face-detection", "params.yml");
console.log(modelParams);

Parameters

NameTypeDefault valueDescription
templatenull | stringnullThe training template to use for the model type.
saveTostring"params.yaml"The file path to save the yaml file.

Returns

Promise\<Record\<string, any>>

  • A promise that resolves to the model params for the model type.

Defined in

client/model.ts:204


listTrainingTemplates

listTrainingTemplates(): Promise\<string[]>

Lists all the training templates for the model type.

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!,
},
});

const trainingTemplates = await model.listTrainingTemplates();
console.log(trainingTemplates);

Returns

Promise\<string[]>

  • A promise that resolves to a list of training templates for the model type.

Defined in

client/model.ts:163


listVersions

listVersions(«destructured»?): AsyncGenerator\<AsObject[], void, void>

Lists all the versions 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!,
},
});

const versions = await model.listVersions().next();
console.log(versions);

Parameters

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

Returns

AsyncGenerator\<AsObject[], void, void>

Remarks

Defaults to 16 per page if pageNo is not specified

Defined in

client/model.ts:433


loadInfo

loadInfo(): Promise\<void>

Loads the current model info. Usually called internally by other methods, to ensure the model info is loaded with latest data.

Returns

Promise\<void>

Defined in

client/model.ts:124


overrideModelVersion

overrideModelVersion(«destructured»): void

Overrides the model version.

Parameters

NameType
«destructured»Object
› inferenceParams?Record\<string, JavaScriptValue>
› outputConfig?OutputConfig

Returns

void

Defined in

client/model.ts:697


predict

predict(«destructured»): Promise\<AsObject[]>

Predicts the model based on the given inputs. Use the Input module to create the input objects.

Example

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

export const model = new Model({
modelId: "multimodal-clip-embed",
authConfig: {
pat: process.env.CLARIFAI_PAT!,
userId: process.env.CLARIFAI_USER_ID!,
appId: process.env.CLARIFAI_APP_ID!,
},
});

const input = Input.getInputFromBytes({
inputId: "intro-text",
textBytes: Buffer.from("Hi my name is Jim."),
});

const textPrediction = await model.predict({
inputs: [input],
});

console.log(textPrediction);

const imageInput = Input.getInputFromUrl({
inputId: "test-image",
imageUrl:
"https://goldenglobes.com/wp-content/uploads/2023/10/17-tomcruiseag.jpg",
});

const imagePrediction = await model.predict({
inputs: [imageInput],
});

console.log(imagePrediction);

Parameters

NameType
«destructured»Object
› inferenceParams?Record\<string, JavaScriptValue>
› inputsInput[]
› outputConfig?OutputConfig

Returns

Promise\<AsObject[]>

  • A promise that resolves to the model prediction.

Defined in

client/model.ts:480


predictByBytes

predictByBytes(«destructured»): Promise\<AsObject[]>

Predicts the model based on the given inputs. Inputs can be provided as a Buffer.

Parameters

NameType
«destructured»Object
› inferenceParams?Record\<string, JavaScriptValue>
› inputBytesBuffer
› inputType"image" | "text" | "video" | "audio"
› outputConfig?OutputConfig

Returns

Promise\<AsObject[]>

  • A promise that resolves to the model prediction.

Defined in

client/model.ts:638


predictByFilepath

predictByFilepath(«destructured»): Promise\<AsObject[]>

Predicts the model based on the given inputs. Inputs can be provided as a filepath which can be read.

Parameters

NameType
«destructured»Object
› filepathstring
› inferenceParams?Record\<string, JavaScriptValue>
› inputType"image" | "text" | "video" | "audio"
› outputConfig?OutputConfig

Returns

Promise\<AsObject[]>

  • A promise that resolves to the model prediction.

Defined in

client/model.ts:604


predictByUrl

predictByUrl(«destructured»): Promise\<AsObject[]>

Predicts the model based on the given inputs. Inputs can be provided as a URL.

Parameters

NameType
«destructured»Object
› inferenceParams?Record\<string, JavaScriptValue>
› inputType"image" | "text" | "video" | "audio"
› outputConfig?OutputConfig
› urlstring

Returns

Promise\<AsObject[]>

  • A promise that resolves to the model prediction.

Defined in

client/model.ts:562


updateParams

updateParams(modelParams): void

Updates the model params 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.updateParams({
batchSize: 8,
datasetVersion: "version_id",
});

Parameters

NameTypeDescription
modelParamsRecord\<string, unknown>The model params to update.

Returns

void

Defined in

client/model.ts:277