Input Nodes
Connect your models together
The outputs from one model can be used as inputs for another model. This allows you to link together the models in a graph. Linking models helps you build sophisticated AI solutions that can zero-in on a specific use case.
Supported Input and Output Types
To view your available models, just open your application in the Portal and click the Model Mode icon on the left-hand side of the screen. From there, just click the Create a Custom Model button on the top right-hand corner of the screen.
Different models accept different types of inputs and return different types of outputs. They are named after the fields in the Data object of our API. This object uses inputs, annotations, models, and workflows.
Some examples include:
Inputs
- Concepts
- Embeddings
- Image
- Image or video
- Regions
Outputs
- Concepts
- Clusters
- Regions
The Building Blocks
You can create workflows out of any Clarifai Models or custom models that you have created for your app. The inputs and outputs supported by your custom models will depend on the inputs and outputs supported by the Clarifai Models, or model templates that you have used to build them.
The initialization code used in the following examples is outlined in detail on the client installation page.
Sample Workflow With Multiple Connected Nodes
The following is an example of how to build a workflow with multiple connected nodes. Note that model IDs and model version IDs from the public clarifai/main
application are fixed, so they are already hard-coded in the code examples below. It is possible to use other public model or model version IDs.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# workflow we want to build. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to build your own workflow with multiple connected nodes
# Note that we've also added as comments the values of most of these variables against their names in the code below
WORKFLOW_ID = 'auto-annotation-workflow-id'
NODE_ID_1 = 'general-embed'
MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581'
MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104'
NODE_ID_2 = 'general-concept'
MODEL_ID_2 = 'aaa03c23b3724a16a56b629203edc62c'
MODEL_VERSION_ID_2 = 'aa7f35c01e0642fda5cf400f543e7c40'
NODE_ID_3 = 'general-cluster'
MODEL_ID_3 = 'cccbe437d6e54e2bb911c6aa292fb072'
MODEL_VERSION_ID_3 = 'cc2074cff6dc4c02b6f4e1b8606dcb54'
NODE_ID_4 = 'mapper'
SYNONYM_MODEL_ID = 'YOUR_SYNONYM_MODEL_ID'
SYNONYM_MODEL_VERSION_ID = 'YOUR_SYNONYM_MODEL_VERSION_ID'
NODE_ID_5 = 'greater-than'
GREATER_THAN_MODEL_ID = 'YOUR_GREATER_THAN_MODEL_ID'
GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID'
NODE_ID_6 = 'less-than'
LESS_THAN_MODEL_ID = 'YOUR_LESS_THAN_MODEL_ID'
LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_MODEL_VERSION_ID'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
post_workflows_response = stub.PostWorkflows(
service_pb2.PostWorkflowsRequest(
user_app_id=userDataObject,
workflows=[
resources_pb2.Workflow(
id=WORKFLOW_ID, # auto-annotation-workflow-id
nodes=[
resources_pb2.WorkflowNode(
id=NODE_ID_1, # general-embed
model=resources_pb2.Model(
id=MODEL_ID_1, # bbb5f41425b8468d9b7a554ff10f8581
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_1 # bb186755eda04f9cbb6fe32e816be104
)
)
),
resources_pb2.WorkflowNode(
id=NODE_ID_2, # general-concept
model=resources_pb2.Model(
id=MODEL_ID_2, # aaa03c23b3724a16a56b629203edc62c
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_2 # aa7f35c01e0642fda5cf400f543e7c40
)
)
),
resources_pb2.WorkflowNode(
id=NODE_ID_3, # general-cluster
model=resources_pb2.Model(
id=MODEL_ID_3, # cccbe437d6e54e2bb911c6aa292fb072
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_3 # cc2074cff6dc4c02b6f4e1b8606dcb54
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_1) # general-embed
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_4, # mapper
model=resources_pb2.Model(
id=SYNONYM_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=SYNONYM_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_2) # general-concept
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_5, # greater-than
model=resources_pb2.Model(
id=GREATER_THAN_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=GREATER_THAN_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_4) # mapper
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_6, # less-than
model=resources_pb2.Model(
id=LESS_THAN_MODEL_ID,
model_version=resources_pb2.ModelVersion(
id=LESS_THAN_MODEL_VERSION_ID
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_4) # mapper
]
),
]
)
]
),
metadata=metadata
)
if post_workflows_response.status.code != status_code_pb2.SUCCESS:
print(post_workflows_response.status)
raise Exception("Post workflows failed, status: " + post_workflows_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to build. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to build your own workflow with multiple connected nodes
const WORKFLOW_ID = 'auto-annotation-workflow-id';
const NODE_ID_1 = 'general-embed';
const GENERAL_EMBED_MODEL_ID = 'YOUR_GENERAL_EMBED_MODEL_ID';
const GENERAL_EMBED_MODEL_VERSION_ID = 'YOUR_GENERAL_EMBED_MODEL_VERSION_ID';
const NODE_ID_2 = 'general-concept';
const GENERAL_CONCEPT_MODEL_ID = 'YOUR_GENERAL_CONCEPT_MODEL_ID';
const GENERAL_CONCEPT_MODEL_VERSION_ID = 'YOUR_GENERAL_CONCEPT_MODEL_VERSION_ID';
const NODE_ID_3 = 'general-cluster';
const GENERAL_CLUSTER_MODEL_ID = 'YOUR_GENERAL_CLUSTER_MODEL_ID';
const GENERAL_CLUSTER_MODEL_VERSION_ID = 'YOUR_GENERAL_CLUSTER_MODEL_VERSION_ID';
const NODE_ID_4 = 'mapper';
const SYNONYM_MODEL_ID = 'synonym-model-id';
const MAPPER_MODEL_VERSION_ID = 'YOUR_MAPPER_MODEL_VERSION_ID';
const NODE_ID_5 = 'greater-than';
const GREATER_THAN_MODEL_ID = 'YOUR_GREATER_THAN_MODEL_ID';
const GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID';
const NODE_ID_6 = 'less-than';
const LESS_THAN_MODEL_ID = 'YOUR_LESS_THAN_MODEL_ID';
const LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_MODEL_VERSION_ID';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"workflows": [
{
"id": WORKFLOW_ID,
"nodes": [
{
"id": NODE_ID_1,
"model": {
"id": GENERAL_EMBED_MODEL_ID,
"model_version": {
"id": GENERAL_EMBED_MODEL_VERSION_ID
}
}
},
{
"id": NODE_ID_2,
"model": {
"id": GENERAL_CONCEPT_MODEL_ID,
"model_version": {
"id": GENERAL_CONCEPT_MODEL_VERSION_ID
}
}
},
{
"id": NODE_ID_3,
"model": {
"id": GENERAL_CLUSTER_MODEL_ID,
"model_version": {
"id": GENERAL_CLUSTER_MODEL_VERSION_ID
}
}
},
{
"id": NODE_ID_4,
"model": {
"id": SYNONYM_MODEL_ID,
"model_version": {
"id": MAPPER_MODEL_VERSION_ID
}
},
"node_inputs": [
{
"node_id": NODE_ID_2 // general-concept
}
]
},
{
"id": NODE_ID_5,
"model": {
"id": GREATER_THAN_MODEL_ID,
"model_version": {
"id": GREATER_THAN_MODEL_VERSION_ID
}
},
"node_inputs": [
{
"node_id": NODE_ID_4 // mapper
}
]
},
{
"id": NODE_ID_6,
"model": {
"id": LESS_THAN_MODEL_ID,
"model_version": {
"id": LESS_THAN_MODEL_VERSION_ID
}
},
"node_inputs": [
{
"node_id": NODE_ID_4 // mapper
}
]
}
]
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch(`https://api.clarifai.com/v2/workflows`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to build. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to build your own workflow with multiple connected nodes
const WORKFLOW_ID = 'auto-annotation-workflow-id';
const NODE_ID_1 = 'general-embed';
const GENERAL_EMBED_MODEL_ID = 'bbb5f41425b8468d9b7a554ff10f8581';
const GENERAL_EMBED_MODEL_VERSION_ID = 'bb186755eda04f9cbb6fe32e816be104';
const NODE_ID_2 = 'general-concept';
const GENERAL_CONCEPT_MODEL_ID = 'aaa03c23b3724a16a56b629203edc62c';
const GENERAL_CONCEPT_MODEL_VERSION_ID = 'aa7f35c01e0642fda5cf400f543e7c40';
const NODE_ID_3 = 'general-cluster';
const GENERAL_CLUSTER_MODEL_ID = 'cccbe437d6e54e2bb911c6aa292fb072';
const GENERAL_CLUSTER_MODEL_VERSION_ID = 'cc2074cff6dc4c02b6f4e1b8606dcb54';
const NODE_ID_4 = 'mapper';
const SYNONYM_MODEL_ID = 'synonym-model-id';
const SYNONYM_MODEL_VERSION_ID = 'YOUR_SYNONYM_MODEL_VERSION_ID';
const NODE_ID_5 = 'greater-than';
const GREATER_THAN_MODEL_ID = 'greater-than-model-id';
const GREATER_THAN_MODEL_VERSION_ID = 'YOUR_GREATER_THAN_MODEL_VERSION_ID';
const NODE_ID_6 = 'less-than';
const LESS_THAN_MODEL_ID = 'less-than-model-id';
const LESS_THAN_MODEL_VERSION_ID = 'YOUR_LESS_THAN_MODEL_VERSION_ID';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostWorkflows(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
workflows: [
{
id: WORKFLOW_ID,
nodes: [
{
id: NODE_ID_1,
model: {
id: GENERAL_EMBED_MODEL_ID,
model_version: {
id: GENERAL_EMBED_MODEL_VERSION_ID
}
}
},
{
id: NODE_ID_2,
model: {
id: GENERAL_CONCEPT_MODEL_ID,
model_version: {
id: GENERAL_CONCEPT_MODEL_VERSION_ID
}
}
},
{
id: NODE_ID_3,
model: {
id: GENERAL_CLUSTER_MODEL_ID,
model_version: {
id: GENERAL_CLUSTER_MODEL_VERSION_ID
}
}
},
{
id: NODE_ID_4,
model: {
id: SYNONYM_MODEL_ID,
model_version: {
id: SYNONYM_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_2 // general-concept
}
]
},
{
id: NODE_ID_5,
model: {
id: GREATER_THAN_MODEL_ID,
model_version: {
id: GREATER_THAN_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_4 // mapper
}
]
},
{
id: NODE_ID_6,
model: {
id: LESS_THAN_MODEL_ID,
model_version: {
id: LESS_THAN_MODEL_VERSION_ID
}
},
node_inputs: [
{
node_id: NODE_ID_4 // mapper
}
]
}
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post workflows failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to build. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to build your own workflow with multiple connected nodes
static final String WORKFLOW_ID = "auto-annotation-workflow-id";
static final String NODE_ID_1 = "general-embed";
static final String GENERAL_EMBED_MODEL_ID = "bbb5f41425b8468d9b7a554ff10f8581";
static final String GENERAL_EMBED_MODEL_VERSION_ID = "bb186755eda04f9cbb6fe32e816be104";
static final String NODE_ID_2 = "general-concept";
static final String GENERAL_CONCEPT_MODEL_ID = "aaa03c23b3724a16a56b629203edc62c";
static final String GENERAL_CONCEPT_MODEL_VERSION_ID = "aa7f35c01e0642fda5cf400f543e7c40";
static final String NODE_ID_3 = "general-cluster";
static final String GENERAL_CLUSTER_MODEL_ID = "cccbe437d6e54e2bb911c6aa292fb072";
static final String GENERAL_CLUSTER_MODEL_VERSION_ID = "cc2074cff6dc4c02b6f4e1b8606dcb54";
static final String NODE_ID_4 = "mapper";
static final String SYNONYM_MODEL_ID = "synonym-model-id";
static final String SYNONYM_MODEL_VERSION_ID = "YOUR_SYNONYM_MODEL_VERSION_ID";
static final String NODE_ID_5 = "greater-than";
static final String GREATER_THAN_MODEL_ID = "greater-than-model-id";
static final String GREATER_THAN_MODEL_VERSION_ID = "YOUR_GREATER_THAN_MODEL_VERSION_ID";
static final String NODE_ID_6 = "less-than";
static final String LESS_THAN_MODEL_ID = "less-than-model-id";
static final String LESS_THAN_MODEL_VERSION_ID = "YOUR_LESS_THAN_MODEL_VERSION_ID";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiWorkflowResponse postWorkflowsResponse = stub.postWorkflows(
PostWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addWorkflows(
Workflow.newBuilder()
.setId(WORKFLOW_ID)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_1)
.setModel(
Model.newBuilder()
.setId(GENERAL_EMBED_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(GENERAL_EMBED_MODEL_VERSION_ID)
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_2)
.setModel(
Model.newBuilder()
.setId(GENERAL_CONCEPT_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(GENERAL_CONCEPT_MODEL_VERSION_ID)
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_3)
.setModel(
Model.newBuilder()
.setId(GENERAL_CLUSTER_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(GENERAL_CLUSTER_MODEL_VERSION_ID)
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_4)
.setModel(
Model.newBuilder()
.setId(SYNONYM_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(SYNONYM_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_2))
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_5)
.setModel(
Model.newBuilder()
.setId(GREATER_THAN_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(GREATER_THAN_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_4))
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_6)
.setModel(
Model.newBuilder()
.setId(LESS_THAN_MODEL_ID)
.setModelVersion(
ModelVersion.newBuilder()
.setId(LESS_THAN_MODEL_VERSION_ID)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_4))
)
)
.build()
);
if (postWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflows failed, status: " + postWorkflowsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// workflow we want to build. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
# Change these to build your own workflow with multiple connected nodes
# Note that we've also added as comments the values of most of these variables against their names in the code below
$WORKFLOW_ID = "auto-annotation-workflow-id";
$NODE_ID_1 = "general-embed";
$MODEL_ID_1 = "bbb5f41425b8468d9b7a554ff10f8581";
$MODEL_VERSION_ID_1 = "bb186755eda04f9cbb6fe32e816be104";
$NODE_ID_2 = "general-concept";
$MODEL_ID_2 = "aaa03c23b3724a16a56b629203edc62c";
$MODEL_VERSION_ID_2 = "aa7f35c01e0642fda5cf400f543e7c40";
$NODE_ID_3 = "general-cluster";
$MODEL_ID_3 = "cccbe437d6e54e2bb911c6aa292fb072";
$MODEL_VERSION_ID_3 = "cc2074cff6dc4c02b6f4e1b8606dcb54";
$NODE_ID_4 = "mapper";
$SYNONYM_MODEL_ID = "YOUR_SYNONYM_MODEL_ID";
$SYNONYM_MODEL_VERSION_ID = "YOUR_SYNONYM_MODEL_VERSION_ID";
$NODE_ID_5 = "greater-than";
$GREATER_THAN_MODEL_ID = "YOUR_GREATER_THAN_MODEL_ID";
$GREATER_THAN_MODEL_VERSION_ID = "YOUR_GREATER_THAN_MODEL_VERSION_ID";
$NODE_ID_6 = "less-than";
$LESS_THAN_MODEL_ID = "YOUR_LESS_THAN_MODEL_ID";
$LESS_THAN_MODEL_VERSION_ID = "YOUR_LESS_THAN_MODEL_VERSION_ID";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostWorkflowsRequest;
use Clarifai\Api\Workflow;
use Clarifai\Api\WorkflowNode;
use Clarifai\Api\NodeInput;
use Clarifai\Api\Model;
use Clarifai\Api\ModelVersion;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostWorkflows(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostWorkflowsRequest([
"user_app_id" => $userDataObject,
"workflows" => [
new Workflow([
"id" => $WORKFLOW_ID, // auto-annotation-workflow-id
"nodes" => [
new WorkflowNode([
"id" => $NODE_ID_1, // general-embed
"model" => new Model([
"id" => $MODEL_ID_1, // bbb5f41425b8468d9b7a554ff10f8581
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_1 // bb186755eda04f9cbb6fe32e816be104
])
])
]),
new WorkflowNode([
"id" => $NODE_ID_2, // general-concept
"model" => new Model([
"id" => $MODEL_ID_2, // aaa03c23b3724a16a56b629203edc62c
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_2 // aa7f35c01e0642fda5cf400f543e7c40
])
])
]),
new WorkflowNode([
"id" => $NODE_ID_3, // general-cluster
"model" => new Model([
"id" => $MODEL_ID_3, // cccbe437d6e54e2bb911c6aa292fb072
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_3 // cc2074cff6dc4c02b6f4e1b8606dcb54
])
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_1 // general-embed
])
]
]),
new WorkflowNode([
"id" => $NODE_ID_4, // mapper
"model" => new Model([
"id" => $SYNONYM_MODEL_ID,
"model_version" => new ModelVersion([
"id" => $SYNONYM_MODEL_VERSION_ID
])
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_2 // general-concept
])
]
]),
new WorkflowNode([
"id" => $NODE_ID_5, // greater-than
"model" => new Model([
"id" => $GREATER_THAN_MODEL_ID,
"model_version" => new ModelVersion([
"id" => $GREATER_THAN_MODEL_VERSION_ID
])
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_4 // mapper
])
]
]),
new WorkflowNode([
"id" => $NODE_ID_6, // less-than
"model" => new Model([
"id" => $LESS_THAN_MODEL_ID,
"model_version" => new ModelVersion([
"id" => $LESS_THAN_MODEL_VERSION_ID
])
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_4 // mapper
])
]
])
]
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"workflows": [
{
"id": "auto-annotation-workflow-id",
"nodes": [
{
"id": "general-embed",
"model": {
"id": "YOUR_GENERAL_EMBED_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_EMBED_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "general-concept",
"model": {
"id": "YOUR_GENERAL_CONCEPT_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_CONCEPT_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "general-cluster",
"model": {
"id": "YOUR_GENERAL_CLUSTER_MODEL_ID_HERE",
"model_version": {
"id": "YOUR_GENERAL_CLUSTER_MODEL_VERSION_ID_HERE"
}
}
},
{
"id": "mapper",
"model": {
"id": "synonym-model-id",
"model_version": {
"id": "YOUR_MAPPER_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "general-concept"
}
]
},
{
"id": "greater-than",
"model": {
"id": "greater-than-model-id",
"model_version": {
"id": "YOUR_GREATER_THAN_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "mapper"
}
]
},
{
"id": "less-than",
"model": {
"id": "less-than-model-id",
"model_version": {
"id": "YOUR_LESS_THAN_MODEL_VERSION_ID_HERE"
}
},
"node_inputs": [
{
"node_id": "mapper"
}
]
}
]
}
]
}'
Suppressing the Output From Nodes
It is possible to turn the outputs from given nodes in your workflow on and off with the suppress_output
endpoint. This can be helpful when you want to hide outputs for expensive return values like image crops or embedding.
By default, this endpoint will be set to false, meaning that we do not suppress any model's output.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, and the details of the
# nodes to suppress their outputs. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to suppress the outputs of your own nodes
WORKFLOW_ID = 'predict-cluster-only'
NODE_ID_1 = 'general-embed'
MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581'
MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104'
NODE_ID_2 = 'general-cluster'
MODEL_ID_2 = 'cccbe437d6e54e2bb911c6aa292fb072'
MODEL_VERSION_ID_2 = 'cc2074cff6dc4c02b6f4e1b8606dcb54'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
post_workflows_response = stub.PostWorkflows(
service_pb2.PostWorkflowsRequest(
user_app_id=userDataObject,
workflows=[
resources_pb2.Workflow(
id=WORKFLOW_ID,
nodes=[
resources_pb2.WorkflowNode(
id=NODE_ID_1,
model=resources_pb2.Model(
id=MODEL_ID_1,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_1
)
),
suppress_output = True
),
resources_pb2.WorkflowNode(
id=NODE_ID_2,
model=resources_pb2.Model(
id=MODEL_ID_2,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_2
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_1)
]
),
]
)
]
),
metadata=metadata
)
if post_workflows_response.status.code != status_code_pb2.SUCCESS:
print(post_workflows_response.status)
raise Exception("Post workflows failed, status: " + post_workflows_response.status.description)
<!--index.html file-->
<script>
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// nodes to suppress their outputs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to suppress the outputs of your own nodes
const WORKFLOW_ID = 'predict-cluster-only';
const NODE_ID_1 = 'general-embed';
const MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581';
const MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104';
const NODE_ID_2 = 'general-cluster';
const MODEL_ID_2 = 'cccbe437d6e54e2bb911c6aa292fb072';
const MODEL_VERSION_ID_2 = 'cc2074cff6dc4c02b6f4e1b8606dcb54';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"workflows": [
{
"id": WORKFLOW_ID,
"nodes": [
{
"id": NODE_ID_1,
"model": {
"id": MODEL_ID_1,
"model_version": {
"id": MODEL_VERSION_ID_1
}
},
"suppress_output": true
},
{
"id": NODE_ID_2,
"node_inputs": [
{
"node_id": NODE_ID_1
}
],
"model": {
"id": MODEL_ID_2,
"model_version": {
"id": MODEL_VERSION_ID_2
}
}
}
]
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch(`https://api.clarifai.com/v2/workflows`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// nodes to suppress their outputs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to suppress the outputs of your own nodes
const WORKFLOW_ID = 'predict-cluster-only';
const NODE_ID_1 = 'general-embed';
const MODEL_ID_1 = 'bbb5f41425b8468d9b7a554ff10f8581';
const MODEL_VERSION_ID_1 = 'bb186755eda04f9cbb6fe32e816be104';
const NODE_ID_2 = 'general-cluster';
const MODEL_ID_2 = 'cccbe437d6e54e2bb911c6aa292fb072';
const MODEL_VERSION_ID_2 = 'cc2074cff6dc4c02b6f4e1b8606dcb54';
const NODE_ID_3 = 'mapper';
/////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
/////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostWorkflows(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
workflows: [
{
id: WORKFLOW_ID,
nodes: [
{
id: NODE_ID_1,
model: {
id: MODEL_ID_1,
model_version: {
id: MODEL_VERSION_ID_1
}
},
suppress_output: true
},
{
id: NODE_ID_2,
model: {
id: MODEL_ID_2,
model_version: {
id: MODEL_VERSION_ID_2
}
},
node_inputs: [
{
node_id: NODE_ID_3
}
]
},
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.log(response.status);
throw new Error("Post workflows failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// nodes to suppress their outputs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to suppress the outputs of your own nodes
static final String WORKFLOW_ID = "auto-annotation-workflow-id";
static final String NODE_ID_1 = "general-embed";
static final String MODEL_ID_1 = "bbb5f41425b8468d9b7a554ff10f8581";
static final String MODEL_VERSION_ID_1 = "bb186755eda04f9cbb6fe32e816be104";
static final String NODE_ID_2 = "general-cluster";
static final String MODEL_ID_2 = "cccbe437d6e54e2bb911c6aa292fb072";
static final String MODEL_VERSION_ID_2 = "cc2074cff6dc4c02b6f4e1b8606dcb54";
static final String NODE_ID_3 = "general-cluster";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiWorkflowResponse postWorkflowsResponse = stub.postWorkflows(
PostWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addWorkflows(
Workflow.newBuilder()
.setId(WORKFLOW_ID)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_1)
.setModel(
Model.newBuilder()
.setId(MODEL_ID_1)
.setModelVersion(
ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID_1)
)
)
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_2)
.setModel(
Model.newBuilder()
.setId(MODEL_ID_2)
.setModelVersion(
ModelVersion.newBuilder()
.setId(MODEL_VERSION_ID_2)
)
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_3))
)
)
.build()
);
if (postWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflows failed, status: " + postWorkflowsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the details of the
// nodes to suppress their outputs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to suppress the outputs of your own nodes
$WORKFLOW_ID = "predict-cluster-only";
$NODE_ID_1 = "general-embed";
$MODEL_ID_1 = "bbb5f41425b8468d9b7a554ff10f8581";
$MODEL_VERSION_ID_1 = "bb186755eda04f9cbb6fe32e816be104";
$NODE_ID_2 = "general-cluster";
$MODEL_ID_2 = "cccbe437d6e54e2bb911c6aa292fb072";
$MODEL_VERSION_ID_2 = "cc2074cff6dc4c02b6f4e1b8606dcb54";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostWorkflowsRequest;
use Clarifai\Api\Workflow;
use Clarifai\Api\WorkflowNode;
use Clarifai\Api\NodeInput;
use Clarifai\Api\Model;
use Clarifai\Api\ModelVersion;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostWorkflows(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostWorkflowsRequest([
"user_app_id" => $userDataObject,
"workflows" => [
new Workflow([
"id" => $WORKFLOW_ID,
"nodes" => [
new WorkflowNode([
"id" => $NODE_ID_1,
"model" => new Model([
"id" => $MODEL_ID_1,
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_1
])
]),
"suppress_output" => true
]),
new WorkflowNode([
"id" => $NODE_ID_2,
"model" => new Model([
"id" => $MODEL_ID_2,
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_2
])
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_1
])
]
])
]
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"workflows": [
{
"id": "predict-cluster-only",
"nodes": [
{
"id": "general-embed",
"model": {
"id": "bbb5f41425b8468d9b7a554ff10f8581",
"model_version": {
"id": "bb186755eda04f9cbb6fe32e816be104"
}
},
"suppress_output": true
},
{
"id": "general-cluster",
"node_inputs": [
{
"node_id": "general-embed"
}
],
"model": {
"id": "cccbe437d6e54e2bb911c6aa292fb072",
"model_version": {
"id": "cc2074cff6dc4c02b6f4e1b8606dcb54"
}
}
}
]
}
]
}'