Create, Get, Update, Delete
Manage your Mesh Workflows
Workflows is a useful Clarifai's feature that allows you to combine multiple models and carry out different operations. With workflows, you can create a powerful multimodal system that meets various use cases in a single API call — instead of relying only on one model.
You can use Clarifai's built-in models or your own custom models.
The initialization code used in the following examples is outlined in detail on the client installation page.
Create
In this example, we'll create a simple custom workflow that first extracts text from an image and then translates the extracted text to Spanish.
We'll connect the following two models to achieve our objective:
- The ocr-scene-english-paddleocr model, which detects and recognizes English texts in images;
- The text-translation-english-spanish model, which translates texts from English to Spanish.
We'll specify the IDs of the models and their versions — since a model can have several versions.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
########################################################################################
# In this section, we set the user authentication, app ID, and the details of the new
# custom workflow we want to create. 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 create your own custom workflow
WORKFLOW_ID = 'my-custom-workflow'
NODE_ID_1 = 'optical-character-recognizer'
MODEL_ID_1 = 'ocr-scene-english-paddleocr'
MODEL_VERSION_ID_1 = '40dbb2c9cde44a27af226782e7157006'
NODE_ID_2 = 'text-to-text'
MODEL_ID_2 = 'text-translation-english-spanish'
MODEL_VERSION_ID_2 = '643f30558de34013aff72b0e21f244f5'
##########################################################################
# 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
)
)
),
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 new
// custom workflow we want to create. 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 create your own custom workflow
const WORKFLOW_ID = 'my-custom-workflow';
const NODE_ID_1 = 'optical-character-recognizer';
const MODEL_ID_1 = 'ocr-scene-english-paddleocr';
const MODEL_VERSION_ID_1 = '40dbb2c9cde44a27af226782e7157006';
const NODE_ID_2 = 'text-to-text';
const MODEL_ID_2 = 'text-translation-english-spanish';
const MODEL_VERSION_ID_2 = '643f30558de34013aff72b0e21f244f5';
///////////////////////////////////////////////////////////////////////////////////
// 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
}
}
},
{
"id": NODE_ID_2,
"model": {
"id": MODEL_ID_2,
"model_version": {
"id": MODEL_VERSION_ID_2
}
},
"node_inputs": [
{
"node_id": NODE_ID_1
}
]
}
]
}]
});
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 new
// custom workflow we want to create. 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 create your own custom workflow
const WORKFLOW_ID = 'my-custom-workflow';
const NODE_ID_1 = 'optical-character-recognizer';
const MODEL_ID_1 = 'ocr-scene-english-paddleocr';
const MODEL_VERSION_ID_1 = '40dbb2c9cde44a27af226782e7157006';
const NODE_ID_2 = 'text-to-text';
const MODEL_ID_2 = 'text-translation-english-spanish';
const MODEL_VERSION_ID_2 = '643f30558de34013aff72b0e21f244f5';
/////////////////////////////////////////////////////////////////////////////
// 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
}
}
},
{
id: NODE_ID_2,
model: {
id: MODEL_ID_2,
model_version: {
id: MODEL_VERSION_ID_2
}
},
node_inputs: [
{
node_id: NODE_ID_1
}
]
}
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
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 new
// custom workflow we want to create. 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 create your own custom workflow
static final String WORKFLOW_ID = "my-custom-workflow";
static final String NODE_ID_1 = "optical-character-recognizer";
static final String MODEL_ID_1 = "ocr-scene-english-paddleocr";
static final String MODEL_VERSION_ID_1 = "40dbb2c9cde44a27af226782e7157006";
static final String NODE_ID_2 = "text-to-text";
static final String MODEL_ID_2 = "text-translation-english-spanish";
static final String MODEL_VERSION_ID_2 = "643f30558de34013aff72b0e21f244f5";
///////////////////////////////////////////////////////////////////////////////////
// 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_1))
)
).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 new
// custom workflow we want to create. 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 create your own custom workflow
$WORKFLOW_ID = "my-custom-workflow";
$NODE_ID_1 = "optical-character-recognizer";
$MODEL_ID_1 = "ocr-scene-english-paddleocr";
$MODEL_VERSION_ID_1 = "40dbb2c9cde44a27af226782e7157006";
$NODE_ID_2 = "text-to-text";
$MODEL_ID_2 = "text-translation-english-spanish";
$MODEL_VERSION_ID_2 = "643f30558de34013aff72b0e21f244f5";
///////////////////////////////////////////////////////////////////////////////////
// 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
])
])
]),
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 "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE" \
--data-raw '{
"workflows": [{
"id": "my-custom-workflow",
"nodes": [
{
"id": "optical-character-recognizer",
"model": {
"id": "ocr-scene-english-paddleocr",
"model_version": {
"id": "40dbb2c9cde44a27af226782e7157006"
}
}
},
{
"id": "text-to-text",
"model": {
"id": "text-translation-english-spanish",
"model_version": {
"id": "643f30558de34013aff72b0e21f244f5"
}
},
"node_inputs": [
{
"node_id": "optical-character-recognizer"
}
]
}
]
}]
}'
Workflow Predict
After creating the workflow, let's now use it to extract texts from this image and translate them into Spanish.
The response will contain the predictions each model in the workflow returns for the input.
If you want to make a predict call with an external workflow that is outside the scope of your app, you need to use a PAT while specifying the app_id
and the user_id
associated with the workflow you want to use.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#############################################################################
# In this section, we set the user authentication, app ID, workflow ID, and
# image URL. 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 make your own predictions
WORKFLOW_ID = 'my-custom-workflow'
IMAGE_URL = 'https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg'
##########################################################################
# 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_workflow_results_response = stub.PostWorkflowResults(
service_pb2.PostWorkflowResultsRequest(
user_app_id=userDataObject,
workflow_id=WORKFLOW_ID,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL
)
)
)
]
),
metadata=metadata
)
if post_workflow_results_response.status.code != status_code_pb2.SUCCESS:
print(post_workflow_results_response.status)
raise Exception("Post workflow results failed, status: " + post_workflow_results_response.status.description)
# We'll get one WorkflowResult for each input we used above. Because of one input, we have here one WorkflowResult
results = post_workflow_results_response.results[0]
# Each model we have in the workflow will produce its output
for output in results.outputs:
model = output.model
print("Output for the model: `%s`" % model.id)
i = 0
while(i < len(output.data.regions)):
print(output.data.regions[i].data.text.raw)
i += 1
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, workflow ID, and
// image URL. 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 make your own predictions
const WORKFLOW_ID = "my-custom-workflow";
const IMAGE_URL = "https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg";
///////////////////////////////////////////////////////////////////////////////////
// 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
},
"inputs": [
{
"data": {
"image": {
"url": IMAGE_URL
}
}
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch(`https://api.clarifai.com/v2/workflows/${WORKFLOW_ID}/results`, 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, workflow ID, and
// image URL. 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 make your own predictions
const WORKFLOW_ID = "my-custom-workflow";
const IMAGE_URL = "https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg";
/////////////////////////////////////////////////////////////////////////////
// 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.PostWorkflowResults(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID,
},
workflow_id: WORKFLOW_ID,
inputs: [{ data: { image: { url: IMAGE_URL } } }],
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Post workflow results failed, status: " + response.status.description
);
}
// We'll get one WorkflowResult for each input we used above. Because of one input, we have here
// one WorkflowResult
const results = response.results[0];
// Each model we have in the workflow will produce its output.
for (const output of results.outputs) {
const model = output.model;
console.log("Output for the model: `" + model.id + "`");
let i = 0;
while(i < output.data.regions.length){
console.log(output.data.regions[i].data.text.raw);
i += 1;
}
}
}
);
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, workflow ID, and
// image URL. 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 make your own predictions
static final String WORKFLOW_ID = "my-custom-workflow";
static final String IMAGE_URL = "https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg";
///////////////////////////////////////////////////////////////////////////////////
// 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));
PostWorkflowResultsResponse postWorkflowResultsResponse = stub.postWorkflowResults(
PostWorkflowResultsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setWorkflowId(WORKFLOW_ID)
.addInputs(
Input.newBuilder().setData(
Data.newBuilder().setImage(
Image.newBuilder().setUrl(IMAGE_URL)
)
)
)
.build()
);
if (postWorkflowResultsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post workflow results failed, status: " + postWorkflowResultsResponse.getStatus());
}
// We'll get one WorkflowResult for each input we used above. Because of one input, we have here
// one WorkflowResult
WorkflowResult results = postWorkflowResultsResponse.getResults(0);
// Each model we have in the workflow will produce its output
for (Output output: results.getOutputsList()) {
Model model = output.getModel();
System.out.println("Output for the model: `" + model.getId() + "`");
int i = 0;
while(i < output.getData().getRegionsCount()) {
String modelOutput = output.getData().getRegionsList().get(i).getData().getText().getRaw();
System.out.println(modelOutput);
i += 1;
}
}
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, workflow ID, and
// image URL. 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 make your own predictions
$WORKFLOW_ID = 'my-custom-workflow';
$IMAGE_URL = 'https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\Data;
use Clarifai\Api\Image;
use Clarifai\Api\Input;
use Clarifai\Api\PostWorkflowResultsRequest;
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->PostWorkflowResults(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostWorkflowResultsRequest([
'user_app_id' => $userDataObject,
'workflow_id' => $WORKFLOW_ID,
'inputs' => [
new Input([ // The Input object wraps the Data object in order to meet the API specification
'data' => new Data([ // The Data object is constructed around the Image object. It offers a container that has additional image independent
// metadata. In this particular use case, no other metadata is needed to be specified
'image' => new Image([ // In the Clarifai platform, an image is defined by a special Image object
'url' => $IMAGE_URL
])
])
])
]
]),
$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) {
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " .
$response->getStatus()->getDetails());
}
// We'll get one WorkflowResult for each input we used above. Because of one input, we have here one WorkflowResult
$results = $response->getResults()[0];
// Each model we have in the workflow will produce its output
foreach ($results->getOutputs() as $output) {
$model = $output->getModel();
echo "Output for the model: '" . $model->getId() . "'" . "`<br>";
$i = 0;
while ($i < count($output->getData()->getRegions())) {
echo $output->getData()->getRegions()[$i]->getData()->getText()->getRaw() . "`<br>";
$i++;
}
}
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows/YOUR_WORKFLOW_ID_HERE/results" \
-H "authorization: Key YOUR_PAT_HERE" \
-H "content-type: application/json" \
-d '{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/featured-models/ocr-woman-holding-sold-sign.jpg"
}
}
}
]
}'
Text Output Example
Output for the model: `ocr-scene-english-paddleocr`
SOLD
We can SELL YOURS too!
Output for the model: `text-translation-english-spanish`
VENDIDO
¡Nosotros también podemos venderla!
Get
Get all Workflows in an App
You can return all custom workflows in your app.
If you want to get a list of the workflows not within the scope of your app, you need to use your PAT while specifying the user_id
of their owner and the app_id
of the application that you’re accessing. For example, to get Clarifai's workflows in the main
app, you need to use your PAT while specifying Clarifai's user_id
as "clarifai" and app_id
as "main" in the request.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################
# In this section, we set the user authentication and app ID.
# 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'
##########################################################################
# 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
list_workflows_response = stub.ListWorkflows(
service_pb2.ListWorkflowsRequest(
user_app_id=userDataObject
),
metadata=metadata
)
if list_workflows_response.status.code != status_code_pb2.SUCCESS:
print(list_workflows_response.status)
raise Exception("List workflows failed, status: " + list_workflows_response.status.description)
for workflow in list_workflows_response.workflows:
print(f"The workflow {workflow.id} consists of these models:")
for workflow_node in workflow.nodes:
model = workflow_node.model
print(model.id)
print()
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: "GET",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT,
},
};
fetch(
`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/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 and app ID.
// 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";
/////////////////////////////////////////////////////////////////////////////
// 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.ListWorkflows(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"List workflows failed, status: " + response.status.description
);
}
for (const workflow of response.workflows) {
console.log("The workflow " + workflow.id + " consists of these models:");
for (const workflowNode of workflow.nodes) {
const model = workflowNode.model;
console.log(model.id);
}
console.log();
}
}
);
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 and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// 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 listWorkflowsResponse = stub.listWorkflows(
ListWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.build());
if (listWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List workflows failed, status: " + listWorkflowsResponse.getStatus());
}
for (Workflow workflow: listWorkflowsResponse.getWorkflowsList()) {
System.out.println("The workflow " + workflow.getId() + " consists of these models:");
for (WorkflowNode workflowNode: workflow.getNodesList()) {
Model model = workflowNode.getModel();
System.out.println(model.getId());
}
System.out.println();
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListWorkflowsRequest;
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
->ListWorkflows(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListWorkflowsRequest([
"user_app_id" => $userDataObject,
]),
$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) {
throw new Exception(
"Failure response: " .
$response->getStatus()->getDescription() .
" " .
$response->getStatus()->getDetails()
);
}
// Print details of each workflow
foreach ($response->getWorkflows() as $workflow) {
echo "The workflow " . $workflow->getId() . " consists of these models:\n";
foreach ($workflow->getNodes() as $workflowNode) {
$model = $workflowNode->getModel();
echo $model->getId();
}
echo "\n";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows/" \
-H "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE"
Get a Workflow by a Specific ID
You can return information about a specific workflow.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
############################################################################
# In this section, we set the user authentication, app ID, and workflow ID.
# 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 this to your own workflow ID
WORKFLOW_ID = 'my-custom-workflow'
##########################################################################
# 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
get_workflow_response = stub.GetWorkflow(
service_pb2.GetWorkflowRequest(
user_app_id=userDataObject,
workflow_id=WORKFLOW_ID
),
metadata=metadata
)
if get_workflow_response.status.code != status_code_pb2.SUCCESS:
print(get_workflow_response.status)
raise Exception("Get workflow failed, status: " + get_workflow_response.status.description)
workflow = get_workflow_response.workflow
print(f"The workflow consists of these models:")
for workflow_node in workflow.nodes:
model = workflow_node.model
print(model.id)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and workflow ID.
// 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 this to your own workflow ID
const WORKFLOW_ID = "my-custom-workflow";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: "GET",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT,
},
};
fetch(
`https://api.clarifai.com/v2/users/${USER_ID}/apps/${APP_ID}/workflows/${WORKFLOW_ID}`,
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 workflow ID.
// 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 this to your own workflow ID
const WORKFLOW_ID = "my-custom-workflow";
/////////////////////////////////////////////////////////////////////////////
// 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.GetWorkflow(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID,
},
workflow_id: WORKFLOW_ID,
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Get workflow failed, status: " + response.status.description
);
}
const workflow = response.workflow;
console.log("The workflow consists of these models:");
for (const workflowNode of workflow.nodes) {
const model = workflowNode.model;
console.log(model.id);
}
}
);
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 workflow ID.
// 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 this to your own workflow ID
static final String WORKFLOW_ID = "food-and-general";
///////////////////////////////////////////////////////////////////////////////////
// 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));
SingleWorkflowResponse getWorkflowResponse = stub.getWorkflow(
GetWorkflowRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setWorkflowId(WORKFLOW_ID)
.build()
);
if (getWorkflowResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get workflow failed, status: " + getWorkflowResponse.getStatus());
}
Workflow workflow = getWorkflowResponse.getWorkflow();
System.out.println("The workflow consists of these models:");
for (WorkflowNode workflowNode: workflow.getNodesList()) {
Model model = workflowNode.getModel();
System.out.println(model.getId());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and workflow ID.
// 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 this to your own workflow ID
$WORKFLOW_ID = "my-custom-workflow";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetWorkflowRequest;
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
->GetWorkflow(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetWorkflowRequest([
"user_app_id" => $userDataObject,
"workflow_id" => $WORKFLOW_ID,
]),
$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) {
throw new Exception(
"Failure response: " .
$response->getStatus()->getDescription() .
" " .
$response->getStatus()->getDetails()
);
}
$workflow = $response->getWorkflow();
echo "The workflow consists of these models:" . "\n";
foreach ($workflow->getNodes() as $workflowNode) {
$model = $workflowNode->getModel();
echo $model->getId() . "\n";
}
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows/YOUR_WORKFLOW_ID_HERE" \
-H "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE"
Update
Patch Workflow
You can change a workflow; that is, change the models of which the workflow consists.
The possible actions are overwrite
, merge
, and remove
.
- 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 update. 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 update your own workflow
WORKFLOW_ID = 'my-custom-workflow'
NODE_ID_1 = 'audio-to-text'
MODEL_ID_1 = 'asr-wav2vec2-base-960h-english'
MODEL_VERSION_ID_1 = 'f4deae70a473492a8e2f9b7bb1dbee85'
NODE_ID_2 = 'text-summarization'
MODEL_ID_2 = 'text-summarization-english-distilbart-cnn-12-6'
MODEL_VERSION_ID_2 = '8279cec2221a4b1d9db774470940aebd'
NODE_ID_3 = 'english-to-french'
MODEL_ID_3 = 'translation-english-to-french-text'
MODEL_VERSION_ID_3 = 'c65a4a51c2b646fca5f0e4bf1ff200d7'
##########################################################################
# 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
patch_workflows_response = stub.PatchWorkflows(
service_pb2.PatchWorkflowsRequest(
user_app_id=userDataObject,
action="overwrite",
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
)
)
),
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)
]
),
resources_pb2.WorkflowNode(
id=NODE_ID_3,
model=resources_pb2.Model(
id=MODEL_ID_3,
model_version=resources_pb2.ModelVersion(
id=MODEL_VERSION_ID_3
)
),
node_inputs=[
resources_pb2.NodeInput(node_id=NODE_ID_2)
]
),
]
)
]
),
metadata=metadata
)
if patch_workflows_response.status.code != status_code_pb2.SUCCESS:
print(patch_workflows_response.status)
raise Exception("Patch workflows failed, status: " + patch_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 update. 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 update your own workflow
const WORKFLOW_ID = "my-custom-workflow";
const NODE_ID_1 = "audio-to-text";
const MODEL_ID_1 = "asr-wav2vec2-base-960h-english";
const MODEL_VERSION_ID_1 = "f4deae70a473492a8e2f9b7bb1dbee85";
const NODE_ID_2 = "text-summarization";
const MODEL_ID_2 = "text-summarization-english-distilbart-cnn-12-6";
const MODEL_VERSION_ID_2 = "8279cec2221a4b1d9db774470940aebd";
const NODE_ID_3 = "english-to-french";
const MODEL_ID_3 = "translation-english-to-french-text";
const MODEL_VERSION_ID_3 = "c65a4a51c2b646fca5f0e4bf1ff200d7";
///////////////////////////////////////////////////////////////////////////////////
// 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
},
"action": "overwrite",
"workflows": [
{
"id": WORKFLOW_ID,
"nodes": [
{
"id": NODE_ID_1,
"model": {
"id": MODEL_ID_1,
"model_version": {
"id": MODEL_VERSION_ID_1
}
}
},
{
"id": NODE_ID_2,
"model": {
"id": MODEL_ID_2,
"model_version": {
"id": MODEL_VERSION_ID_2
}
},
"node_inputs": [
{
"node_id": NODE_ID_1
}
]
},
{
"id": NODE_ID_3,
"model": {
"id": MODEL_ID_3,
"model_version": {
"id": MODEL_VERSION_ID_3
}
},
"node_inputs": [
{
"node_id": NODE_ID_2
}
]
}
]
}
]
});
const requestOptions = {
method: "PATCH",
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 update. 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 update your own workflow
const WORKFLOW_ID = "my-custom-workflow";
const NODE_ID_1 = "audio-to-text";
const MODEL_ID_1 = "asr-wav2vec2-base-960h-english";
const MODEL_VERSION_ID_1 = "f4deae70a473492a8e2f9b7bb1dbee85";
const NODE_ID_2 = "text-summarization";
const MODEL_ID_2 = "text-summarization-english-distilbart-cnn-12-6";
const MODEL_VERSION_ID_2 = "8279cec2221a4b1d9db774470940aebd";
const NODE_ID_3 = "english-to-french";
const MODEL_ID_3 = "translation-english-to-french-text";
const MODEL_VERSION_ID_3 = "c65a4a51c2b646fca5f0e4bf1ff200d7";
/////////////////////////////////////////////////////////////////////////////
// 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.PatchWorkflows(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID,
},
action: "overwrite",
workflows: [
{
id: WORKFLOW_ID,
nodes: [
{
id: NODE_ID_1,
model: {
id: MODEL_ID_1,
model_version: {
id: MODEL_VERSION_ID_1,
}
}
},
{
id: NODE_ID_2,
model: {
id: MODEL_ID_2,
model_version: {
id: MODEL_VERSION_ID_2
}
},
node_inputs: [
{
node_id: NODE_ID_1
}
]
},
{
id: NODE_ID_3,
model: {
id: MODEL_ID_3,
model_version: {
id: MODEL_VERSION_ID_3
}
},
node_inputs: [
{
node_id: NODE_ID_2
}
]
}
]
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Patch 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 update. 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 update your own workflow
static final String WORKFLOW_ID = "my-custom-workflow";
static final String NODE_ID_1 = "audio-to-text";
static final String MODEL_ID_1 = "asr-wav2vec2-base-960h-english";
static final String MODEL_VERSION_ID_1 = "f4deae70a473492a8e2f9b7bb1dbee85";
static final String NODE_ID_2 = "text-summarization";
static final String MODEL_ID_2 = "text-summarization-english-distilbart-cnn-12-6";
static final String MODEL_VERSION_ID_2 = "8279cec2221a4b1d9db774470940aebd";
static final String NODE_ID_3 = "english-to-french";
static final String MODEL_ID_3 = "translation-english-to-french-text";
static final String MODEL_VERSION_ID_3 = "c65a4a51c2b646fca5f0e4bf1ff200d7";
///////////////////////////////////////////////////////////////////////////////////
// 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 patchWorkflowsResponse = stub.patchWorkflows(
PatchWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("overwrite")
.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_1))
)
.addNodes(
WorkflowNode.newBuilder()
.setId(NODE_ID_3)
.setModel(
Model.newBuilder()
.setId(MODEL_ID_3)
.setModelVersion(ModelVersion.newBuilder().setId(MODEL_VERSION_ID_3))
)
.addNodeInputs(NodeInput.newBuilder().setNodeId(NODE_ID_2))
)
).build()
);
if (patchWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch workflows failed, status: " + patchWorkflowsResponse.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 update. 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 update your own workflow
$WORKFLOW_ID = "my-custom-workflow";
$NODE_ID_1 = "audio-to-text";
$MODEL_ID_1 = "asr-wav2vec2-base-960h-english";
$MODEL_VERSION_ID_1 = "f4deae70a473492a8e2f9b7bb1dbee85";
$NODE_ID_2 = "text-summarization";
$MODEL_ID_2 = "text-summarization-english-distilbart-cnn-12-6";
$MODEL_VERSION_ID_2 = "8279cec2221a4b1d9db774470940aebd";
$NODE_ID_3 = "english-to-french";
$MODEL_ID_3 = "translation-english-to-french-text";
$MODEL_VERSION_ID_3 = "c65a4a51c2b646fca5f0e4bf1ff200d7";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchWorkflowsRequest;
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
->PatchWorkflows(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchWorkflowsRequest([
"user_app_id" => $userDataObject,
"action" => "overwrite",
"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,
]),
]),
]),
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,
]),
],
]),
new WorkflowNode([
"id" => $NODE_ID_3,
"model" => new Model([
"id" => $MODEL_ID_3,
"model_version" => new ModelVersion([
"id" => $MODEL_VERSION_ID_3,
]),
]),
"node_inputs" => [
new NodeInput([
"node_id" => $NODE_ID_2,
]),
],
]),
],
]),
],
]),
$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 PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows/" \
-H "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE" \
--data-raw '{
"action": "overwrite",
"workflows": [
{
"id": "my-custom-workflow",
"nodes": [
{
"id": "audio-to-text",
"model": {
"id": "asr-wav2vec2-base-960h-english",
"model_version": {
"id": "f4deae70a473492a8e2f9b7bb1dbee85"
}
}
},
{
"id": "text-summarization",
"model": {
"id": "text-summarization-english-distilbart-cnn-12-6",
"model_version": {
"id": "8279cec2221a4b1d9db774470940aebd"
}
},
"node_inputs": [
{
"node_id": "audio-to-text"
}
]
},
{
"id": "english-to-french",
"model": {
"id": "translation-english-to-french-text",
"model_version": {
"id": "c65a4a51c2b646fca5f0e4bf1ff200d7"
}
},
"node_inputs": [
{
"node_id": "text-summarization"
}
]
}
]
}
]
}'
Delete
Delete Workflow by ID
You can delete a specific workflow.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, and the ID of the
# workflow we want to delete. 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 this to delete your own workflow
WORKFLOW_ID = 'my-custom-workflow'
##########################################################################
# 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
delete_workflow_response = stub.DeleteWorkflow(
service_pb2.DeleteWorkflowRequest(
user_app_id=userDataObject,
workflow_id=WORKFLOW_ID
),
metadata=metadata
)
if delete_workflow_response.status.code != status_code_pb2.SUCCESS:
print(delete_workflow_response.status)
raise Exception("Delete workflow failed, status: " + delete_workflow_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// workflow we want to delete. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////
// 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 this to delete your own workflow
const WORKFLOW_ID = "my-custom-workflow";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: "DELETE",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT,
},
};
fetch(
`https://api.clarifai.com/v2/users/me/apps/${APP_ID}/workflows/${WORKFLOW_ID}`,
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 ID of the
// workflow we want to delete. 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 this to delete your own workflow
const WORKFLOW_ID = "my-custom-workflow";
/////////////////////////////////////////////////////////////////////////////
// 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.DeleteWorkflow(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID,
},
workflow_id: WORKFLOW_ID,
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Delete workflow 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.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// workflow we want to delete. 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 this to delete your own workflow
static final String WORKFLOW_ID = "my-custom-workflow";
///////////////////////////////////////////////////////////////////////////////////
// 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));
BaseResponse deleteWorkflowResponse = stub.deleteWorkflow(
DeleteWorkflowRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setWorkflowId(WORKFLOW_ID)
.build()
);
if (deleteWorkflowResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete workflow failed, status: " + deleteWorkflowResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the ID of the
// workflow we want to delete. 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 this to delete your own workflow
$WORKFLOW_ID = "my-custom-workflow";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteWorkflowRequest;
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
->DeleteWorkflow(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteWorkflowRequest([
"user_app_id" => $userDataObject,
"workflow_id" => $WORKFLOW_ID,
]),
$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) {
throw new Exception(
"Failure response: " .
$response->getStatus()->getDescription() .
" " .
$response->getStatus()->getDetails()
);
}
?>
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows/YOUR_WORKFLOW_ID_HERE" \
-H "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE"
Delete all Workflows
You can delete all custom workflows.
Instead of delete_all
, you can specify a list of workflow IDs to be deleted, using the ids
field.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################
# In this section, we set the user authentication and app ID.
# 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'
##########################################################################
# 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
delete_workflows_response = stub.DeleteWorkflows(
service_pb2.DeleteWorkflowsRequest(
user_app_id=userDataObject,
delete_all=True
# ids = ['workflow_id_1', 'workflow_id_2'] # Specify a list of workflow IDs to be deleted
),
metadata=metadata
)
if delete_workflows_response.status.code != status_code_pb2.SUCCESS:
print(delete_workflows_response.status)
raise Exception("Delete workflows failed, status: " + delete_workflows_response.status.description)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// 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,
},
"delete_all": true,
//"ids": ['workflow_id_1', 'workflow_id_2'] // Specify a list of workflow IDs to be deleted
});
const requestOptions = {
method: "DELETE",
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 and app ID.
// 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";
/////////////////////////////////////////////////////////////////////////////
// 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.DeleteWorkflows(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID,
},
delete_all: true
//ids: ['workflow_id_1', 'workflow_id_2'] // Specify a list of workflow IDs to be deleted
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Delete 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.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// 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));
BaseResponse deleteWorkflowsResponse = stub.deleteWorkflows(
DeleteWorkflowsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setDeleteAll(true)
.build()
);
if (deleteWorkflowsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete workflows failed, status: " + deleteWorkflowsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// 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";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteWorkflowsRequest;
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
->DeleteWorkflows(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteWorkflowsRequest([
"user_app_id" => $userDataObject,
"delete_all" => true,
]),
$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) {
throw new Exception(
"Failure response: " .
$response->getStatus()->getDescription() .
" " .
$response->getStatus()->getDetails()
);
}
?>
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/workflows" \
-H "Content-Type: application/json" \
-H "Authorization: Key YOUR_PAT_HERE" \
--data-raw '{
"delete_all": true
}'