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
- createVersion
- deleteVersion
- getParamInfo
- getParams
- listTrainingTemplates
- listVersions
- loadInfo
- overrideModelVersion
- predict
- predictByBytes
- predictByFilepath
- predictByUrl
- updateParams
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
Name | Type |
---|---|
«destructured» | { authConfig? : AuthConfig ; modelId? : undefined ; modelVersion? : { id : string } ; url : ClarifaiUrl } | { authConfig? : AuthConfig ; modelId : string ; modelVersion? : { id : string } ; url? : undefined } |
Returns
Overrides
Lister.constructor
Defined in
Properties
appId
• Private
appId: string
Defined in
id
• Private
id: string
Defined in
modelInfo
• Private
modelInfo: Model
Defined in
modelVersion
• Private
modelVersion: undefined
| { id
: string
}
Defined in
trainingParams
• Private
trainingParams: Record
<string
, unknown
>
Defined in
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
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
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
Name | Type |
---|---|
param | string |
Returns
Promise
<Record
<string
, any
>>
Defined in
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
Name | Type | Default value | Description |
---|---|---|---|
template | null | string | null | The training template to use for the model type. |
saveTo | string | "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
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
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
Name | Type |
---|---|
«destructured» | Object |
› pageNo? | number |
› perPage? | number |
Returns
AsyncGenerator
<AsObject
[], void
, void
>
Remarks
Defaults to 16 per page if pageNo is not specified
Defined in
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
overrideModelVersion
▸ overrideModelVersion(«destructured»
): void
Overrides the model version.
Parameters
Name | Type |
---|---|
«destructured» | Object |
› inferenceParams? | Record <string , JavaScriptValue > |
› outputConfig? | OutputConfig |
Returns
void
Defined in
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
Name | Type |
---|---|
«destructured» | Object |
› inferenceParams? | Record <string , JavaScriptValue > |
› inputs | Input [] |
› outputConfig? | OutputConfig |
Returns
Promise
<AsObject
[]>
- A promise that resolves to the model prediction.
Defined in
predictByBytes
▸ predictByBytes(«destructured»
): Promise
<AsObject
[]>
Predicts the model based on the given inputs. Inputs can be provided as a Buffer.
Parameters
Name | Type |
---|---|
«destructured» | Object |
› inferenceParams? | Record <string , JavaScriptValue > |
› inputBytes | Buffer |
› inputType | "image" | "text" | "video" | "audio" |
› outputConfig? | OutputConfig |
Returns
Promise
<AsObject
[]>
- A promise that resolves to the model prediction.
Defined in
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
Name | Type |
---|---|
«destructured» | Object |
› filepath | string |
› inferenceParams? | Record <string , JavaScriptValue > |
› inputType | "image" | "text" | "video" | "audio" |
› outputConfig? | OutputConfig |
Returns
Promise
<AsObject
[]>
- A promise that resolves to the model prediction.
Defined in
predictByUrl
▸ predictByUrl(«destructured»
): Promise
<AsObject
[]>
Predicts the model based on the given inputs. Inputs can be provided as a URL.
Parameters
Name | Type |
---|---|
«destructured» | Object |
› inferenceParams? | Record <string , JavaScriptValue > |
› inputType | "image" | "text" | "video" | "audio" |
› outputConfig? | OutputConfig |
› url | string |
Returns
Promise
<AsObject
[]>
- A promise that resolves to the model prediction.
Defined in
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
Name | Type | Description |
---|---|---|
modelParams | Record <string , unknown > | The model params to update. |
Returns
void