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
- createDataset
- createModel
- createModule
- createWorkflow
- dataset
- deleteDataset
- deleteModel
- deleteModule
- deleteWorkflow
- listConcepts
- listDataSets
- listInstalledModuleVersions
- listModels
- listModules
- listTrainableModelTypes
- listWorkflows
- model
- workflow
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
Name | Type | Description |
---|---|---|
config | AppConfig | The configuration object for the App. |
Returns
Overrides
Lister.constructor
Defined in
Properties
appInfo
• Private
appInfo: App
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";
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 |