Tasks : Create, Get, Update, Delete
Group your labeling work into tasks that can be delegated
Task is the work that needs to be done for labeling the inputs in an app. It's a powerful way to help your team annotate inputs fast and efficiently.
These are some parameters you can specify when working with tasks:
- Task type — It can be:
CONCEPTS_CLASSIFICATION
— Concepts classification tasks annotate concepts for the overall image, frame of video, or section of text.BOUNDING_BOX_DETECTION
— Bounding box detection tasks annotate rectangular bounding box regions around each concept in an image, frame of video, or section of text.POLYGON_DETECTION
— Polygon detection tasks annotate free-form regions around concepts in an image, frame of video, or section of text.
- Worker — Task worker includes information about the workers who will work on the task.
- Concept IDs — List of concept IDs used in the work on the task. The concepts should already be existing in your app.
- Task worker strategy — It can be:
PARTITIONED
— The inputs will be partitioned in several partitions. Each worker will label one or more input partitions.FULL
— Each worker will label all inputs from the input source.
- Input source — It can be:
ALL_INPUTS
— Use all inputs in the app.SAVED_SEARCH
— Use the inputs from a saved search. You also need to specify theid
of the saved search.DATASET
— Use inputs from a dataset.
sample_ms
— Used in video model predictions. It specifies the sample delay for video predictions (1 frame per N milliseconds).- Review strategy — It can be:
NONE
— No review is needed.MANUAL
— Manual review strategy.CONSENSUS
— Consensus review strategy.
- Partitioned strategy info — It can be:
EVENLY
— Each worker will label (approximately) the same number of inputs.WEIGHTED
— Each worker will have an assigned weight.
- Workers per input — The number of workers who will label each input.
The initialization code used in the following examples is outlined in detail on the client installation page.
Create
To create a new task in your app, you POST
the task information to the v2/task
endpoint.
Non-Assigned Task
A task should be assigned to a list of users, but it's not required. The following code will create a non-assigned task.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and concept 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 create your own non-assigned task
CONCEPT_ID = 'water'
##########################################################################
# 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)
post_tasks_response = stub.PostTasks(
service_pb2.PostTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
tasks=[
resources_pb2.Task(
type='CONCEPTS_CLASSIFICATION',
name='Annotate ' + CONCEPT_ID,
worker=resources_pb2.TaskWorker(
strategy='FULL'
),
concepts=[
resources_pb2.TaskConcept(
concept=resources_pb2.Concept(
id=CONCEPT_ID
)
)
],
input_source=resources_pb2.TaskInputSource(
type='ALL_INPUTS'
),
sample_ms=1000,
review=resources_pb2.TaskReview(
strategy='NONE'
)
)
]
),
metadata=metadata
)
if post_tasks_response.status.code != status_code_pb2.SUCCESS:
print(post_tasks_response.status)
raise Exception("Post tasks failed, status: " + post_tasks_response.status.description)
<script>
/////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept 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 create your own non-assigned task
const CONCEPT_ID = "water";
/////////////////////////////////////////////////////////////////////////////
// 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
},
"tasks": [
{
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate " + CONCEPT_ID,
"worker": {
"strategy": "FULL"
},
"concepts": [
{
"concept" : {
"id": CONCEPT_ID
}
}
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "NONE"
}
}
]
});
const requestOptions = {
method: "POST",
headers: {
"Accept": "application/json",
"Authorization": "Key " + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/tasks", 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 concept 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 portal under Authentification
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change this to create your own non-assigned task
const CONCEPT_ID = "water";
/////////////////////////////////////////////////////////////////////////////
// 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.PostTasks({
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
tasks: [{
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "FULL"
},
concepts: [{
concept: {
id: CONCEPT_ID
}
}],
input_source: {
type: "ALL_INPUTS"
},
sample_ms: 1000,
review: {
strategy: "NONE"
}
}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.error('Post tasks failed, status:', response.status);
throw new Error("Post tasks failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to create your own non-assigned task
static final String CONCEPT_ID = "water";
//////////////////////////////////////////////////////////////////////////////////
// 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));
MultiTaskResponse postTasksResponse = stub.postTasks(
PostTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addTasks(Task.newBuilder()
.setType(Task.TaskType.CONCEPTS_CLASSIFICATION)
.setName("Annotate " + CONCEPT_ID)
.setWorker(TaskWorker.newBuilder()
.setStrategy(TaskWorker.TaskWorkerStrategy.FULL)
.build())
.addConcepts(TaskConcept.newBuilder()
.setConcept(Concept.newBuilder()
.setId(CONCEPT_ID)
.build())
.build())
.setInputSource(TaskInputSource.newBuilder()
.setType(TaskInputSource.TaskInputSourceType.ALL_INPUTS)
.build())
.setSampleMs(1000)
.setReview(TaskReview.newBuilder()
.setStrategy(TaskReview.TaskReviewStrategy.NONE)
.build())
.build())
.build()
);
if (postTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post model outputs failed, status: " + postTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept 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 create your own non-assigned task
$CONCEPT_ID = "water";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostTasksRequest;
use Clarifai\Api\TASK;
use Clarifai\Api\TaskWorker;
use Clarifai\Api\TaskConcept;
use Clarifai\Api\Concept;
use Clarifai\Api\TaskInputSource;
use Clarifai\Api\TaskReview;
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->PostTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostTasksRequest([
"user_app_id" => $userDataObject,
"tasks" => [
new Task([
"type" => 1, // integer value 1 for "CONCEPTS_CLASSIFICATION" type
"name" => "Annotate " . $CONCEPT_ID,
"worker" => new TaskWorker([
"strategy" => 3 // integer value 3 for "FULL" strategy
]),
"concepts" => [
new TaskConcept([
"concept" => new Concept([
"id" => $CONCEPT_ID
]),
]),
],
"input_source" => new TaskInputSource([
"type" => 1 // integer value 1 for "ALL_INPUTS" strategy
]),
"sample_ms" => 1000,
"review" => new TaskReview([
"strategy" => 1 // integer value 1 for "NONE" strategy
]),
]),
],
]),
$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 POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"tasks": [
{
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate CONCEPT_ID_HERE",
"worker": {
"strategy": "FULL"
},
"concepts": [
{
"concept": {
"id": "CONCEPT_ID_HERE"
}
}
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "NONE"
}
}
]
}'
Assigned Task
A task should be assigned to a list of users. These users will do the labeling work, so they're also called workers. A task may also be assigned to a list of users for review purposes.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and details for
# assigning a task. 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 assign your own task
CONCEPT_ID = 'water'
WORKER_USER_ID = 'WORKER_USER_ID_HERE'
REVIEWER_USER_ID = 'REVIEWER_USER_ID_HERE' # User who will review this task
##########################################################################
# 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)
post_tasks_response = stub.PostTasks(
service_pb2.PostTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
tasks=[
resources_pb2.Task(
type='CONCEPTS_CLASSIFICATION',
name='Annotate ' + CONCEPT_ID,
worker=resources_pb2.TaskWorker(
strategy='FULL',
workers=[
resources_pb2.Worker(
user=resources_pb2.User(
id=WORKER_USER_ID
)
)
]
),
concepts=[
resources_pb2.TaskConcept(
concept=resources_pb2.Concept(
id=CONCEPT_ID
)
)
],
input_source=resources_pb2.TaskInputSource(
type='ALL_INPUTS'
),
sample_ms=1000,
review=resources_pb2.TaskReview(
strategy='MANUAL',
manual_strategy_info=resources_pb2.TaskReviewManualStrategyInfo(
sample_percentage=0.5
),
users=[
resources_pb2.User(
id=REVIEWER_USER_ID
)
]
)
)
]
),
metadata=metadata
)
if post_tasks_response.status.code != status_code_pb2.SUCCESS:
print(post_tasks_response.status)
raise Exception('Post tasks failed, status: ' + post_tasks_response.status.description)
<!-- index.html file -->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// assigning a task. 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 assign your own task
const CONCEPT_ID = "water";
const WORKER_USER_ID = "WORKER_USER_ID_HERE";
const REVIEWER_USER_ID = "REVIEWER_USER_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,
},
tasks: [
{
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "FULL",
workers: [
{
user: {
id: WORKER_USER_ID,
},
},
],
},
concepts: [
{
concept: {
id: CONCEPT_ID,
},
},
],
input_source: {
type: "ALL_INPUTS",
},
sample_ms: 1000,
review: {
strategy: "MANUAL",
manual_strategy_info: {
sample_percentage: 0.5,
},
users: [{ id: REVIEWER_USER_ID }],
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
fetch("https://api.clarifai.com/v2/tasks", 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 details for
// assigning a task. 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 portal under Authentification
const PAT = "YOUR_PAT_HERE";
const APP_ID = "YOUR_APP_ID_HERE";
// Change these to assign your own task
const CONCEPT_ID = "water";
const WORKER_USER_ID = "WORKER_USER_ID_HERE";
const REVIEWER_USER_ID = "REVIEWER_USER_ID_HERE"; // User who will review this task
/////////////////////////////////////////////////////////////////////////////
// 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.PostTasks({
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
tasks: [{
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "FULL",
users: [{
id: WORKER_USER_ID
}]
},
concepts: [{
concept: {
id: CONCEPT_ID
}
}],
input_source: {
"type": "ALL_INPUTS"
},
sample_ms: 1000,
review: {
strategy: "MANUAL",
manual_strategy_info: {
sample_percentage: 0.5
},
users: [{
id: REVIEWER_USER_ID
}]
}
}]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
console.error('Post tasks failed, status:', response.status);
throw new Error("Post tasks failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// assigning a task. 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to assign your own task
static final String CONCEPT_ID = "water";
static final String WORKER_USER_ID = "WORKER_USER_ID_HERE";
static final String REVIEWER_USER_ID = "REVIEWER_USER_ID_HERE"; // User who will review this task
//////////////////////////////////////////////////////////////////////////////////
// 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));
MultiTaskResponse postTasksResponse = stub.postTasks(
PostTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.addTasks(Task.newBuilder()
.setType(Task.TaskType.CONCEPTS_CLASSIFICATION)
.setName("Annotate " + CONCEPT_ID)
.setWorker(TaskWorker.newBuilder()
.setStrategy(TaskWorker.TaskWorkerStrategy.FULL)
.addWorkers(Worker.newBuilder()
.setUser(User.newBuilder()
.setId(WORKER_USER_ID)
.build()
)
)
.build()
)
.addConcepts(TaskConcept.newBuilder()
.setConcept(Concept.newBuilder()
.setId(CONCEPT_ID)
.build()
)
.build()
)
.setInputSource(TaskInputSource.newBuilder()
.setType(TaskInputSource.TaskInputSourceType.ALL_INPUTS)
.build()
)
.setSampleMs(1000)
.setReview(TaskReview.newBuilder()
.setStrategy(TaskReview.TaskReviewStrategy.MANUAL)
.setManualStrategyInfo(TaskReviewManualStrategyInfo.newBuilder()
.setSamplePercentage((float) 0.5)
.build()
)
.addUsers(User.newBuilder()
.setId(REVIEWER_USER_ID)
.build()
)
.build()
)
.build()
)
.build()
);
if (postTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post model outputs failed, status: " + postTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// assigning a task. 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 assign your own task
$CONCEPT_ID = "water";
$WORKER_USER_ID = "WORKER_USER_ID_HERE";
$REVIEWER_USER_ID = "REVIEWER_USER_ID_HERE"; // User who will review this task
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostTasksRequest;
use Clarifai\Api\TASK;
use Clarifai\Api\User;
use Clarifai\Api\TaskWorker;
use Clarifai\Api\TaskConcept;
use Clarifai\Api\Concept;
use Clarifai\Api\TaskInputSource;
use Clarifai\Api\TaskReviewManualStrategyInfo;
use Clarifai\Api\TaskReview;
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->PostTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostTasksRequest([
"user_app_id" => $userDataObject,
"tasks" => [
new Task([
"type" => 1, // integer value 1 for "CONCEPTS_CLASSIFICATION" type
"name" => "Annotate " . $CONCEPT_ID,
"worker" => new TaskWorker([
"strategy" => 3, // integer value 3 for "FULL" strategy
"users" => [
new User([
"id" => $WORKER_USER_ID,
]),
],
]),
"concepts" => [
new TaskConcept([
"concept" => new Concept([
"id" => $CONCEPT_ID,
]),
]),
],
"input_source" => new TaskInputSource([
"type" => 1, // integer value 1 for "ALL_INPUTS" strategy
]),
"sample_ms" => 1000,
"review" => new TaskReview([
"strategy" => 2, // integer value 2 for "MANUAL" strategy
"manual_strategy_info" => new TaskReviewManualStrategyInfo(
[
"sample_percentage" => 0.5,
]
),
"users" => [
new User([
"id" => $REVIEWER_USER_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 POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"tasks": [
{
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate CONCEPT_ID_HERE",
"worker": {
"strategy": "FULL",
"workers": [
{
"user": {
"id": "WORKER_USER_ID_HERE"
}
}
]
},
"concepts": [
{
"concept": {
"id": "CONCEPT_ID_HERE"
}
}
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "MANUAL",
"manual_strategy_info": {
"sample_percentage": 0.5
},
"users": [
{
"id": "REVIEWER_USER_ID_HERE"
}
]
}
}
]
}'
Task With Partitioned Worker Strategy
The previous tasks were created with full worker strategy.
{
"strategy": "FULL"
}
In case of FULL
worker strategy, each worker will work on all inputs selected in the input source.
If you wish the work to be distributed between workers, then you can select the PARTITIONED
worker strategy.
In the following example, there are two workers:
workers_per_input
: each input will be assigned to 1 workerweights.user_id_1
: the first worker will get 90% of inputsweights.user_id_2
: the second worker will get 10% of inputs
- Python
- JavaScript (REST)
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and details for
# creating a task. 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 task with partitioned worker strategy
CONCEPT_ID = 'water'
USER_ID_1 = 'USER_ID_1_HERE'
USER_ID_2 = 'USER_ID_2_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
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
params = Struct()
params.update({
USER_ID_1: 90,
USER_ID_2: 10
})
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_tasks_response = stub.PostTasks(
service_pb2.PostTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
tasks=[
resources_pb2.Task(
type='CONCEPTS_CLASSIFICATION',
name='Annotate ' + CONCEPT_ID,
worker=resources_pb2.TaskWorker(
strategy='PARTITIONED',
users=[
resources_pb2.User(id=USER_ID_1),
resources_pb2.User(id=USER_ID_2)
],
partitioned_strategy_info=resources_pb2.TaskWorkerPartitionedStrategyInfo(
type='WEIGHTED',
workers_per_input=1,
weights=params
)
),
concepts=[
resources_pb2.TaskConcept(
concept=resources_pb2.Concept(id=CONCEPT_ID)
)
],
input_source=resources_pb2.TaskInputSource(type='ALL_INPUTS'),
sample_ms=1000,
review=resources_pb2.TaskReview(strategy='NONE')
)
]
),
metadata=metadata
)
if post_tasks_response.status.code != status_code_pb2.SUCCESS:
print(post_tasks_response.status)
raise Exception('Post tasks failed, status: ' + post_tasks_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. 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 task with partitioned worker strategy
const CONCEPT_ID = "water";
const USER_ID_1 = "USER_ID_1_HERE";
const USER_ID_2 = "USER_ID_2_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,
},
tasks: [
{
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "PARTITIONED",
users: [{ id: USER_ID_1 }, { id: USER_ID_2 }],
partitioned_strategy_info: {
type: "WEIGHTED",
workers_per_input: 1,
weights: {
[USER_ID_1]: 90,
[USER_ID_2]: 10,
},
},
},
concepts: [
{
concept: {
id: CONCEPT_ID,
},
},
],
input_source: {
type: "ALL_INPUTS",
},
sample_ms: 1000,
review: {
strategy: "NONE",
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
fetch("https://api.clarifai.com/v2/tasks", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
</script>
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
static final String CONCEPT_ID = "water";
static final String USER_ID_1 = "USER_ID_1_HERE";
static final String USER_ID_2 = "USER_ID_2_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));
Struct.Builder params = Struct.newBuilder()
.putFields(USER_ID_1, Value.newBuilder().setNumberValue(90).build())
.putFields(USER_ID_2, Value.newBuilder().setNumberValue(10).build());
MultiTaskResponse postTasksResponse = stub.postTasks(
PostTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.addTasks(Task.newBuilder()
.setType(Task.TaskType.CONCEPTS_CLASSIFICATION)
.setName("Annotate " + CONCEPT_ID)
.setWorker(TaskWorker.newBuilder()
.setStrategy(TaskWorker.TaskWorkerStrategy.PARTITIONED)
.addUsers(User.newBuilder().setId(USER_ID_1))
.addUsers(User.newBuilder().setId(USER_ID_2))
.setPartitionedStrategyInfo(TaskWorkerPartitionedStrategyInfo.newBuilder()
.setType(TaskWorkerPartitionedStrategyInfo.TaskWorkerPartitionedStrategy.WEIGHTED)
.setWorkersPerInput(1)
.setWeights(params)
.build()
)
.build()
)
.addConcepts(TaskConcept.newBuilder()
.setConcept(Concept.newBuilder()
.setId(CONCEPT_ID)
.build()
)
.build()
)
.setInputSource(TaskInputSource.newBuilder()
.setType(TaskInputSource.TaskInputSourceType.ALL_INPUTS)
.build()
)
.setSampleMs(1000)
.setReview(TaskReview.newBuilder()
.setStrategy(TaskReview.TaskReviewStrategy.NONE)
.build()
)
.build()
)
.build()
);
if (postTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post tasks outputs failed, status: " + postTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. 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 task with partitioned worker strategy
$CONCEPT_ID = "water";
$USER_ID_1 = "USER_ID_1_HERE";
$USER_ID_2 = "USER_ID_2_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostTasksRequest;
use Clarifai\Api\TASK;
use Clarifai\Api\User;
use Clarifai\Api\TaskWorker;
use Clarifai\Api\TaskConcept;
use Clarifai\Api\Concept;
use Clarifai\Api\TaskInputSource;
use Clarifai\Api\TaskWorkerPartitionedStrategyInfo;
use Clarifai\Api\TaskReview;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
use Google\Protobuf\Struct;
use Google\Protobuf\Value;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID,
]);
// create Struct instance
$params = new Struct();
$params->getFields()[$USER_ID_1] = (new Value())->setNumberValue(90);
$params->getFields()[$USER_ID_2] = (new Value())->setNumberValue(10);
// 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->PostTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostTasksRequest([
"user_app_id" => $userDataObject,
"tasks" => [
new Task([
"type" => 1, // integer value 1 for "CONCEPTS_CLASSIFICATION" type
"name" => "Annotate " . $CONCEPT_ID,
"worker" => new TaskWorker([
"strategy" => 2, // integer value 2 for "PARTITIONED" strategy
"users" => [
new User([
"id" => $USER_ID_1
]),
new User([
"id" => $USER_ID_2
])
],
"partitioned_strategy_info" => new TaskWorkerPartitionedStrategyInfo([
"type" => 2, // integer value 2 for "WEIGHTED" strategy
"workers_per_input" => 1,
"weights" => $params
])
]),
"concepts" => [
new TaskConcept([
"concept" => new Concept([
"id" => $CONCEPT_ID
]),
]),
],
"input_source" => new TaskInputSource([
"type" => 1, // integer value 1 for "ALL_INPUTS" strategy
]),
"sample_ms" => 1000,
"review" => new TaskReview([
"strategy" => 1, // integer value 1 for "NONE" strategy
]),
]),
],
]),
$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 POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"tasks": [
{
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate CONCEPT_ID_HERE",
"worker": {
"strategy": "PARTITIONED",
"users": [
{"id": "USER_ID_1_HERE"},
{"id": "USER_ID_2_HERE"}
],
"partitioned_strategy_info": {
"type": "WEIGHTED",
"workers_per_input": 1,
"weights": {
"USER_ID_1_HERE": 90,
"USER_ID_2_HERE": 10
}
}
},
"concepts": [
{
"concept": {
"id": "CONCEPT_ID_HERE"
}
}
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "NONE"
}
}
]
}'
- It is not required for the weights to add up to 100. For example, the weights [9, 1] are equivalent with weights [90, 10].
- The partitioning is approximate. This means that the number of assigned inputs to each worker may have a small error margin, but it will be close to the assigned weight percentage.
Task With Consensus Review
The previous tasks were created with no review or manual review strategy.
{
"strategy": "MANUAL"
}
We recommend to create tasks with CONSENSUS
review strategy. When enough workers label an input in the same way, it will automatically be approved, with no need for the reviewer to spend time to check. In this way, the reviewer will be able to focus on the inputs where the workers don't agree.
Note that an approval threshold must be set. It is the number of labelers that need to agree in order to automatically approve an annotation.
For example, in case of 3 workers and approval_threshold
set to 2, if an input is labeled in the same way by 2 workers, they form a majority and the group reaches a consensus.
- Python
- JavaScript (REST)
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and details for
# creating a task. 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 task with consensus review
CONCEPT_ID = 'water'
USER_ID_1 = 'USER_ID_1_HERE'
USER_ID_2 = 'USER_ID_2_HERE'
USER_ID_3 = 'USER_ID_3_HERE'
USER_ID_4 = 'USER_ID_4_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
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
params = Struct()
params.update({
USER_ID_1: 1,
USER_ID_2: 1,
USER_ID_3: 1
})
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
post_tasks_response = stub.PostTasks(
service_pb2.PostTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
tasks=[
resources_pb2.Task(
type='CONCEPTS_CLASSIFICATION',
name='Annotate ' + CONCEPT_ID,
worker=resources_pb2.TaskWorker(
strategy='PARTITIONED',
users=[
resources_pb2.User(id=USER_ID_1),
resources_pb2.User(id=USER_ID_2),
resources_pb2.User(id=USER_ID_3)
],
partitioned_strategy_info=resources_pb2.TaskWorkerPartitionedStrategyInfo(
type='WEIGHTED',
workers_per_input=3,
weights=params
)
),
concepts=[
resources_pb2.TaskConcept(
concept=resources_pb2.Concept(id=CONCEPT_ID)
)
],
input_source=resources_pb2.TaskInputSource(type='ALL_INPUTS'),
sample_ms=1000,
review=resources_pb2.TaskReview(
strategy='CONSENSUS',
consensus_strategy_info=resources_pb2.TaskReviewConsensusStrategyInfo(
approval_threshold=2
),
users=[resources_pb2.User(id=USER_ID_4)]
)
)
]
),
metadata=metadata
)
if post_tasks_response.status.code != status_code_pb2.SUCCESS:
print(post_tasks_response.status)
raise Exception('Post tasks failed, status: ' + post_tasks_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. 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 task with consensus review
const CONCEPT_ID = "water";
const USER_ID_1 = "USER_ID_1_HERE";
const USER_ID_2 = "USER_ID_2_HERE";
const USER_ID_3 = "USER_ID_3_HERE";
const USER_ID_4 = "USER_ID_4_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,
},
tasks: [
{
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "PARTITIONED",
users: [{ id: USER_ID_1 }, { id: USER_ID_2 }, { id: USER_ID_3 }],
partitioned_strategy_info: {
type: "WEIGHTED",
workers_per_input: 3,
weights: {
[USER_ID_1]: 1,
[USER_ID_2]: 1,
[USER_ID_3]: 1,
},
},
},
concepts: [
{
concept: {
id: CONCEPT_ID,
},
},
],
input_source: {
type: "ALL_INPUTS",
},
sample_ms: 1000,
review: {
strategy: "CONSENSUS",
consensus_strategy_info: {
approval_threshold: 2,
},
users: [{ id: USER_ID_4 }],
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
fetch("https://api.clarifai.com/v2/tasks", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
</script>
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to create your own task with consensus review
static final String CONCEPT_ID = "water";
static final String USER_ID_1 = "USER_ID_1_HERE";
static final String USER_ID_2 = "USER_ID_2_HERE";
static final String USER_ID_3 = "USER_ID_3_HERE";
static final String USER_ID_4 = "USER_ID_4_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));
Struct.Builder params = Struct.newBuilder()
.putFields(USER_ID_1, Value.newBuilder().setNumberValue(1).build())
.putFields(USER_ID_2, Value.newBuilder().setNumberValue(1).build())
.putFields(USER_ID_3, Value.newBuilder().setNumberValue(1).build());
MultiTaskResponse postTasksResponse = stub.postTasks(
PostTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.addTasks(Task.newBuilder()
.setType(Task.TaskType.CONCEPTS_CLASSIFICATION)
.setName("Annotate " + CONCEPT_ID)
.setWorker(TaskWorker.newBuilder()
.setStrategy(TaskWorker.TaskWorkerStrategy.PARTITIONED)
.addUsers(User.newBuilder().setId(USER_ID_1))
.addUsers(User.newBuilder().setId(USER_ID_2))
.addUsers(User.newBuilder().setId(USER_ID_3))
.setPartitionedStrategyInfo(TaskWorkerPartitionedStrategyInfo.newBuilder()
.setType(TaskWorkerPartitionedStrategyInfo.TaskWorkerPartitionedStrategy.WEIGHTED)
.setWorkersPerInput(3)
.setWeights(params)
.build()
)
.build()
)
.addConcepts(TaskConcept.newBuilder()
.setConcept(Concept.newBuilder()
.setId(CONCEPT_ID)
.build()
)
.build()
)
.setInputSource(TaskInputSource.newBuilder()
.setType(TaskInputSource.TaskInputSourceType.ALL_INPUTS)
.build()
)
.setSampleMs(1000)
.setReview(TaskReview.newBuilder()
.setStrategy(TaskReview.TaskReviewStrategy.CONSENSUS)
.setConsensusStrategyInfo(TaskReviewConsensusStrategyInfo.newBuilder().setApprovalThreshold(2))
.addUsers(User.newBuilder().setId(USER_ID_4))
.build()
)
.build()
)
.build()
);
if (postTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post tasks outputs failed, status: " + postTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// creating a task. 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 task with consensus review
$CONCEPT_ID = "water";
$USER_ID_1 = "USER_ID_1_HERE";
$USER_ID_2 = "USER_ID_2_HERE";
$USER_ID_3 = "USER_ID_3_HERE";
$USER_ID_4 = "USER_ID_4_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostTasksRequest;
use Clarifai\Api\TASK;
use Clarifai\Api\User;
use Clarifai\Api\TaskWorker;
use Clarifai\Api\TaskConcept;
use Clarifai\Api\Concept;
use Clarifai\Api\TaskInputSource;
use Clarifai\Api\TaskWorkerPartitionedStrategyInfo;
use Clarifai\Api\TaskReviewConsensusStrategyInfo;
use Clarifai\Api\TaskReview;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
use Google\Protobuf\Struct;
use Google\Protobuf\Value;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID,
]);
// create Struct instance
$params = new Struct();
$params->getFields()[$USER_ID_1] = (new Value())->setNumberValue(1);
$params->getFields()[$USER_ID_2] = (new Value())->setNumberValue(1);
$params->getFields()[$USER_ID_3] = (new Value())->setNumberValue(1);
// 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->PostTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostTasksRequest([
"user_app_id" => $userDataObject,
"tasks" => [
new Task([
"type" => 1, // integer value 1 for "CONCEPTS_CLASSIFICATION" type
"name" => "Annotate " . $CONCEPT_ID,
"worker" => new TaskWorker([
"strategy" => 2, // integer value 2 for "PARTITIONED" strategy
"users" => [
new User([
"id" => $USER_ID_1
]),
new User([
"id" => $USER_ID_2
]),
new User([
"id" => $USER_ID_3
]),
],
"partitioned_strategy_info" => new TaskWorkerPartitionedStrategyInfo(
[
"type" => 2, // integer value 2 for "WEIGHTED" strategy
"workers_per_input" => 3,
"weights" => $params
]
),
]),
"concepts" => [
new TaskConcept([
"concept" => new Concept([
"id" => $CONCEPT_ID
]),
]),
],
"input_source" => new TaskInputSource([
"type" => 1, // integer value 1 for "ALL_INPUTS" strategy
]),
"sample_ms" => 1000,
"review" => new TaskReview([
"strategy" => 3, // integer value 1 for "CONSENSUS" strategy
"consensus_strategy_info" => new TaskReviewConsensusStrategyInfo(
[
"approval_threshold" => 2
]
),
"users" => [
new User([
"id" => $USER_ID_4
]),
],
]),
]),
],
]),
$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 POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"tasks": [
{
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate CONCEPT_ID_HERE",
"worker": {
"strategy": "PARTITIONED",
"users": [
{"id": "USER_ID_1_HERE"},
{"id": "USER_ID_2_HERE"},
{"id": "USER_ID_3_HERE"}
],
"partitioned_strategy_info": {
"type": "WEIGHTED",
"workers_per_input": 3,
"weights": {
"USER_ID_1_HERE": 1,
"USER_ID_2_HERE": 1,
"USER_ID_3_HERE": 1
}
}
},
"concepts": [
{
"concept": {
"id": "CONCEPT_ID_HERE"
}
}
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "CONSENSUS",
"consensus_strategy_info": {
"approval_threshold": 2
},
"users": [
{"id": "USER_ID_4_HERE"}
]
}
}
]
}'
Get
Get Task by ID
You can get the details of a single task by its ID, which is automatically generated upon task creation. You can output the API response to obtain this task ID.
Alternatively, you can also locate the task ID within the Clarifai platform's user interface.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and task 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 get a task by its ID
TASK_ID = 'c454edb9446c4de58d4fe3a66c286e55'
##########################################################################
# 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)
get_tasks_response = stub.GetTask(
service_pb2.GetTaskRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
task_id=TASK_ID
),
metadata=metadata
)
if get_tasks_response.status.code != status_code_pb2.SUCCESS:
print(get_tasks_response.status)
raise Exception(f'Get task failed, status: {get_tasks_response.status.description}')
print(get_tasks_response)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task 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 get a task by its ID
const TASK_ID = '77f156b3616f40c887c765f4ccb45c87';
///////////////////////////////////////////////////////////////////////////////////
// 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}/tasks/${TASK_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 task 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 get a task by its ID
const TASK_ID = "21980d42ddc4483fa9e59e6678d6af71";
///////////////////////////////////////////////////////////////////////////////////
// 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.GetTask(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
task_id: TASK_ID,
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Get tasks failed, status: " + response.status.description
);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to get a task by its ID
static final String TASK_ID = "6e71ff53fd7d4e32a1a7026737c25cb4";
//////////////////////////////////////////////////////////////////////////////////
// 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));
SingleTaskResponse getTaskResponse = stub.getTask(
GetTaskRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setTaskId(TASK_ID)
.build()
);
if (getTaskResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get tasks failed, status: " + getTaskResponse.getStatus());
}
System.out.println(getTaskResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task 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 get a task by its ID
$TASK_ID = "21980d42ddc4483fa9e59e6678d6af71";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetTaskRequest;
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->GetTask(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetTaskRequest([
"user_app_id" => $userDataObject,
"task_id" => $TASK_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()
);
}
print $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks/TASK_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
List All Tasks
You can get a list of tasks within your app with a GET
call. This call supports pagination.
- 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)
list_tasks_response = stub.ListTasks(
service_pb2.ListTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
),
metadata=metadata
)
if list_tasks_response.status.code != status_code_pb2.SUCCESS:
print(list_tasks_response.status)
raise Exception(f'Get task failed, status: {list_tasks_response.status.description}')
print(list_tasks_response)
<!--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}/tasks`, 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.ListTasks(
{
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 tasks failed, status: " + response.status.description
);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to get a task by its ID
static final String TASK_ID = "6e71ff53fd7d4e32a1a7026737c25cb4";
//////////////////////////////////////////////////////////////////////////////////
// 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));
MultiTaskResponse listTasksResponse = stub.listTasks(
ListTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.build()
);
if (listTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List tasks failed, status: " + listTasksResponse.getStatus());
}
System.out.println(listTasksResponse);
}
}
<?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\ListTasksRequest;
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->ListTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListTasksRequest([
"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 $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
List Tasks Assigned to User
Get only the tasks assigned to a specific user for work.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#######################################################################
# In this section, we set the user authentication, app ID, and
# worker user 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'
WORKER_USER_ID = 'WORKER_USER_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)
list_tasks_response = stub.ListTasks(
service_pb2.ListTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
worker_user_ids=[WORKER_USER_ID]
),
metadata=metadata
)
if list_tasks_response.status.code != status_code_pb2.SUCCESS:
print(list_tasks_response.status)
raise Exception(f'Get task failed, status: {list_tasks_response.status.description}')
print(list_tasks_response)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// worker user 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';
const WORKER_USER_ID = 'WORKER_USER_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}/tasks?worker_user_ids=${WORKER_USER_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
// worker user 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";
const WORKER_USER_ID = "WORKER_USER_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.ListTasks(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
worker_user_ids:[WORKER_USER_ID]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"List tasks failed, status: " + response.status.description
);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// worker user 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
static final String WORKER_USER_ID = "WORKER_USER_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));
MultiTaskResponse listTasksResponse = stub.listTasks(
ListTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addWorkerUserIds(WORKER_USER_ID)
.build()
);
if (listTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List tasks failed, status: " + listTasksResponse.getStatus());
}
System.out.println(listTasksResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// worker user 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";
$WORKER_USER_ID = "WORKER_USER_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListTasksRequest;
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->ListTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListTasksRequest([
"user_app_id" => $userDataObject,
"worker_user_ids" => [$WORKER_USER_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()
);
}
print $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks?worker_user_ids=WORKER_USER_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
List Tasks Assigned to User for Review
Get only the tasks assigned to a specific user for review.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#######################################################################
# In this section, we set the user authentication, app ID, and
# review user 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'
REVIEW_USER_ID = 'REVIEW_USER_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)
list_tasks_response = stub.ListTasks(
service_pb2.ListTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
review_user_ids=[REVIEW_USER_ID]
),
metadata=metadata
)
if list_tasks_response.status.code != status_code_pb2.SUCCESS:
print(list_tasks_response.status)
raise Exception(f'Get task failed, status: {list_tasks_response.status.description}')
print(list_tasks_response)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// review user 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';
const REVIEW_USER_ID = 'REVIEW_USER_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}/tasks?review_user_ids=${REVIEW_USER_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
// review user 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";
const REVIEW_USER_ID = "REVIEW_USER_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.ListTasks(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
review_user_ids: [REVIEW_USER_ID]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"List tasks failed, status: " + response.status.description
);
}
console.log(response);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// review user 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
static final String REVIEW_USER_ID = "REVIEW_USER_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));
MultiTaskResponse listTasksResponse = stub.listTasks(
ListTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addReviewUserIds(REVIEW_USER_ID)
.build()
);
if (listTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List tasks failed, status: " + listTasksResponse.getStatus());
}
System.out.println(listTasksResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
//////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and
// review user 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";
$REVIEW_USER_ID = "REVIEW_USER_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListTasksRequest;
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->ListTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListTasksRequest([
"user_app_id" => $userDataObject,
"review_user_ids" => [$REVIEW_USER_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()
);
}
print $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks?review_user_ids=REVIEW_USER_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Update
Currently, we only support updating a task by providing all information at once.
Update Task
- Python
- JavaScript (REST)
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and details for
# updating a task. 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 task
CONCEPT_ID = 'water'
TASK_ID = 'd0f2fa2b61234d1cb6b66983ea021b5b'
USER_ID_1 = 'USER_ID_1_HERE'
USER_ID_2 = 'USER_ID_2_HERE'
USER_ID_3 = 'USER_ID_3_HERE'
USER_ID_4 = 'USER_ID_4_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, status_pb2
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
params = Struct()
params.update({
USER_ID_1: 1,
USER_ID_2: 1,
USER_ID_3: 1
})
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
patch_tasks_response = stub.PatchTasks(
service_pb2.PatchTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
action="overwrite",
tasks=[
resources_pb2.Task(
id=TASK_ID,
type='CONCEPTS_CLASSIFICATION',
name='Annotate ' + CONCEPT_ID,
worker=resources_pb2.TaskWorker(
strategy='PARTITIONED',
users=[
resources_pb2.User(id=USER_ID_1),
resources_pb2.User(id=USER_ID_2),
resources_pb2.User(id=USER_ID_3)
],
partitioned_strategy_info=resources_pb2.TaskWorkerPartitionedStrategyInfo(
type='WEIGHTED',
workers_per_input=3,
weights=params
)
),
concepts=[
resources_pb2.TaskConcept(
concept=resources_pb2.Concept(id=CONCEPT_ID)
)
],
input_source=resources_pb2.TaskInputSource(type='ALL_INPUTS'),
sample_ms=1000,
review=resources_pb2.TaskReview(
strategy='CONSENSUS',
consensus_strategy_info=resources_pb2.TaskReviewConsensusStrategyInfo(
approval_threshold=2
),
users=[resources_pb2.User(id=USER_ID_4)]
),
status=status_pb2.Status(
code='TASK_DONE'
)
)
]
),
metadata=metadata
)
if patch_tasks_response.status.code != status_code_pb2.SUCCESS:
print(patch_tasks_response.status)
raise Exception('Patch tasks failed, status: ' + patch_tasks_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// updating a task. 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 task
const TASK_ID = "c454edb9446c4de58d4fe3a66c286e55";
const CONCEPT_ID = "water";
const USER_ID_1 = "USER_ID_1_HERE";
const USER_ID_2 = "USER_ID_2_HERE";
const USER_ID_3 = "USER_ID_3_HERE";
const USER_ID_4 = "USER_ID_4_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,
},
action: "overwrite",
tasks: [
{
id: TASK_ID,
type: "CONCEPTS_CLASSIFICATION",
name: "Annotate " + CONCEPT_ID,
worker: {
strategy: "PARTITIONED",
users: [{ id: USER_ID_1 }, { id: USER_ID_2 }, { id: USER_ID_3 }],
partitioned_strategy_info: {
type: "WEIGHTED",
workers_per_input: 3,
weights: {
[USER_ID_1]: 1,
[USER_ID_2]: 1,
[USER_ID_3]: 1,
},
},
},
concept_ids: [CONCEPT_ID],
input_source: {
type: "ALL_INPUTS",
},
sample_ms: 1000,
review: {
strategy: "CONSENSUS",
consensus_strategy_info: {
approval_threshold: 2,
},
users: [{ id: USER_ID_4 }],
},
status: {
code: "TASK_DONE",
},
},
],
});
const requestOptions = {
method: "PATCH",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
fetch("https://api.clarifai.com/v2/tasks", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
</script>
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.Status;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// updating a task. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to update your own task
static final String CONCEPT_ID = "water";
static final String TASK_ID = "8331bac5db8e445591ce69e351ea67fe";
static final String USER_ID_1 = "USER_ID_1_HERE";
static final String USER_ID_2 = "USER_ID_2_HERE";
static final String USER_ID_3 = "USER_ID_3_HERE";
static final String USER_ID_4 = "USER_ID_4_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));
Struct.Builder params = Struct.newBuilder()
.putFields(USER_ID_1, Value.newBuilder().setNumberValue(1).build())
.putFields(USER_ID_2, Value.newBuilder().setNumberValue(1).build())
.putFields(USER_ID_3, Value.newBuilder().setNumberValue(1).build());
MultiTaskResponse patchTasksResponse = stub.patchTasks(
PatchTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.setAction("overwrite")
.addTasks(Task.newBuilder()
.setId(TASK_ID)
.setType(Task.TaskType.CONCEPTS_CLASSIFICATION)
.setName("Annotate " + CONCEPT_ID)
.setWorker(TaskWorker.newBuilder()
.setStrategy(TaskWorker.TaskWorkerStrategy.PARTITIONED)
.addUsers(User.newBuilder().setId(USER_ID_1))
.addUsers(User.newBuilder().setId(USER_ID_2))
.addUsers(User.newBuilder().setId(USER_ID_3))
.setPartitionedStrategyInfo(TaskWorkerPartitionedStrategyInfo.newBuilder()
.setType(TaskWorkerPartitionedStrategyInfo.TaskWorkerPartitionedStrategy.WEIGHTED)
.setWorkersPerInput(3)
.setWeights(params)
.build()
)
.build()
)
.addConcepts(TaskConcept.newBuilder()
.setConcept(Concept.newBuilder()
.setId(CONCEPT_ID)
.build()
)
.build()
)
.setInputSource(TaskInputSource.newBuilder()
.setType(TaskInputSource.TaskInputSourceType.ALL_INPUTS)
.build()
)
.setSampleMs(1000)
.setReview(TaskReview.newBuilder()
.setStrategy(TaskReview.TaskReviewStrategy.CONSENSUS)
.setConsensusStrategyInfo(TaskReviewConsensusStrategyInfo.newBuilder().setApprovalThreshold(2))
.addUsers(User.newBuilder().setId(USER_ID_4))
.build()
)
.setStatus(Status.newBuilder().setCode(StatusCode.TASK_DONE))
.build()
)
.build()
);
if (patchTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Patch tasks request failed, status: " + patchTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details for
// updating a task. 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 task
$CONCEPT_ID = "water";
$TASK_ID = "8264c89ced3b4e7ebafdaa9f31f2fb59";
$USER_ID_1 = "USER_ID_1_HERE";
$USER_ID_2 = "USER_ID_2_HERE";
$USER_ID_3 = "USER_ID_3_HERE";
$USER_ID_4 = "USER_ID_4_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchTasksRequest;
use Clarifai\Api\TASK;
use Clarifai\Api\User;
use Clarifai\Api\TaskWorker;
use Clarifai\Api\TaskConcept;
use Clarifai\Api\Concept;
use Clarifai\Api\TaskInputSource;
use Clarifai\Api\TaskWorkerPartitionedStrategyInfo;
use Clarifai\Api\TaskReviewConsensusStrategyInfo;
use Clarifai\Api\TaskReview;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\Status\Status;
use Clarifai\Api\UserAppIDSet;
use Google\Protobuf\Struct;
use Google\Protobuf\Value;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID,
]);
// create Struct instance
$params = new Struct();
$params->getFields()[$USER_ID_1] = (new Value())->setNumberValue(1);
$params->getFields()[$USER_ID_2] = (new Value())->setNumberValue(1);
$params->getFields()[$USER_ID_3] = (new Value())->setNumberValue(1);
// 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->PatchTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchTasksRequest([
"user_app_id" => $userDataObject,
"action" => "overwrite",
"tasks" => [
new Task([
"id" => $TASK_ID,
"type" => 1, // integer value 1 for "CONCEPTS_CLASSIFICATION" type
"name" => "Annotate " . $CONCEPT_ID,
"worker" => new TaskWorker([
"strategy" => 2, // integer value 2 for "PARTITIONED" strategy
"users" => [
new User([
"id" => $USER_ID_1
]),
new User([
"id" => $USER_ID_2
]),
new User([
"id" => $USER_ID_3
]),
],
"partitioned_strategy_info" => new TaskWorkerPartitionedStrategyInfo(
[
"type" => 2, // integer value 2 for "WEIGHTED" strategy
"workers_per_input" => 3,
"weights" => $params
]
),
]),
"concepts" => [
new TaskConcept([
"concept" => new Concept([
"id" => $CONCEPT_ID
]),
]),
],
"input_source" => new TaskInputSource([
"type" => 1, // integer value 1 for "ALL_INPUTS" strategy
]),
"sample_ms" => 1000,
"review" => new TaskReview([
"strategy" => 3, // integer value 1 for "CONSENSUS" strategy
"consensus_strategy_info" => new TaskReviewConsensusStrategyInfo(
[
"approval_threshold" => 2
]
),
"users" => [
new User([
"id" => $USER_ID_4
]),
],
]),
"status" => new Status([
"code" => 54002 // for "TASK_DONE"
])
]),
],
]),
$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 PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"action": "overwrite",
"tasks": [
{
"id": "TASK_ID_HERE",
"type": "CONCEPTS_CLASSIFICATION",
"name": "Annotate CONCEPT_ID_HERE",
"worker": {
"strategy": "PARTITIONED",
"users": [
{"id": "USER_ID_1_HERE"},
{"id": "USER_ID_2_HERE"},
{"id": "USER_ID_3_HERE"}
],
"partitioned_strategy_info": {
"type": "WEIGHTED",
"workers_per_input": 3,
"weights": {
"USER_ID_1_HERE": 1,
"USER_ID_2_HERE": 1,
"USER_ID_3_HERE": 1
}
}
},
"concept_ids": [
"CONCEPT_ID_HERE"
],
"input_source": {
"type": "ALL_INPUTS"
},
"sample_ms": 1000,
"review": {
"strategy": "CONSENSUS",
"consensus_strategy_info": {
"approval_threshold": 2
},
"users": [
{"id": "USER_ID_4_HERE"}
]
},
"status": {
"code": "TASK_DONE"
}
}
]
}'
Delete
You can delete a task by specifying its ID. You can also delete multiple tasks by specifying a list of their IDs.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
#################################################################################
# In this section, we set the user authentication, app ID, and task IDs.
# 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 delete your own tasks
TASK_ID_1 = 'd1f2f891da9844ccafed93a18574b027'
TASK_ID_2 = 'd1f2f891da9844ccafed93a18574b027'
##########################################################################
# 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)
delete_tasks_response = stub.DeleteTasks(
service_pb2.DeleteTasksRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
ids=[TASK_ID_1, TASK_ID_2]
),
metadata=metadata
)
if delete_tasks_response.status.code != status_code_pb2.SUCCESS:
print(delete_tasks_response.status)
raise Exception('Delete tasks failed, status: ' + delete_tasks_response.status.description)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task IDs.
// 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 delete your own tasks
const TASK_ID_1 = '66262884195c427595d4bca033b2114e';
const TASK_ID_2 = '1106ba0327ed44c2b556659a58e77a48';
///////////////////////////////////////////////////////////////////////////////////
// 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
},
"ids": [TASK_ID_1, TASK_ID_2]
});
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/tasks", 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 task IDs.
// 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 delete your own tasks
const TASK_ID_1 = "ccb05c3b73344a87bfa2ad18f04d793e";
const TASK_ID_2 = "584d8ef6fe184b0a91197c0590d50953";
///////////////////////////////////////////////////////////////////////////////////
// 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.DeleteTasks(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
ids: [TASK_ID_1, TASK_ID_2],
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error(
"Delete tasks failed, status: " + response.status.description
);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task IDs.
// 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 Account's Security section
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to delete your own tasks
static final String TASK_ID_1 = "d9dc9104afd84332a6dd95dd71a38d19";
static final String TASK_ID_2 = "e2aff7156fac416e86fee02a1c1cb2f3";
//////////////////////////////////////////////////////////////////////////////////
// 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 deleteTasksResponse = stub.deleteTasks(
DeleteTasksRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addIds(TASK_ID_1)
.addIds(TASK_ID_2)
.build()
);
if (deleteTasksResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete tasks failed, status: " + deleteTasksResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and task IDs.
// 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 delete your own tasks
$TASK_ID_1 = "7aceabee601c4e73b7c1f3ca1e09c1f6";
$TASK_ID_2 = "fa0c0ddcc43944da8cc66504a2b85d76";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteTasksRequest;
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->DeleteTasks(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteTasksRequest([
"user_app_id" => $userDataObject,
"ids" => [$TASK_ID_1, $TASK_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) {
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/tasks" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"ids":["TASK_ID_HERE"]
}'