Skip to content

Commit 3748514

Browse files
Add scale-rapid evaluation tasks endpoint support (#43)
* add evaluation tasks endpoint support
1 parent 5d004df commit 3748514

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

README.rst

+62
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,68 @@ The attribute can be passed to the task payloads, in the ``attachment`` paramete
461461
...
462462
)
463463
464+
Evaluation tasks (For Scale Rapid projects only)
465+
________________________________________________
466+
467+
Evaluation tasks are tasks that we know the answer to and are used to measure workers' performance internally to ensure the quality
468+
469+
Create Evaluation Task
470+
^^^^^^^^^^^^^^^^^^^^^^
471+
472+
Create an evaluation task.
473+
474+
.. code-block:: python
475+
476+
client.create_evaluation_task(TaskType, ...task parameters...)
477+
478+
Passing in the applicable values into the function definition. The applicable fields are the same as for create_task. Applicable fields for each task type can be found in `Scale's API documentation`__. Additionally an expected_response is required. An optional initial_response can be provided if it's for a review phase evaluation task.
479+
480+
__ https://docs.scale.com/reference
481+
482+
.. code-block:: python
483+
484+
from scaleapi.tasks import TaskType
485+
486+
expected_response = {
487+
"annotations": {
488+
"answer_reasonable": {
489+
"type": "category",
490+
"field_id": "answer_reasonable",
491+
"response": [
492+
[
493+
"no"
494+
]
495+
]
496+
}
497+
}
498+
}
499+
500+
initial_response = {
501+
"annotations": {
502+
"answer_reasonable": {
503+
"type": "category",
504+
"field_id": "answer_reasonable",
505+
"response": [
506+
[
507+
"yes"
508+
]
509+
]
510+
}
511+
}
512+
}
513+
514+
attachments = [
515+
{"type": "image", "content": "https://i.imgur.com/bGjrNzl.jpeg"}
516+
]
517+
518+
payload = dict(
519+
project = "test_project",
520+
attachments,
521+
initial_response=initial_response,
522+
expected_response=expected_response,
523+
)
524+
525+
client.create_task(TaskType.TextCollection, **payload)
464526
465527
466528
Error handling

scaleapi/__init__.py

+40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import IO, Dict, Generator, Generic, List, TypeVar, Union
22

33
from scaleapi.batches import Batch, BatchStatus
4+
from scaleapi.evaluation_tasks import EvaluationTask
45
from scaleapi.exceptions import ScaleInvalidRequest
56
from scaleapi.files import File
67
from scaleapi.projects import Project
@@ -787,3 +788,42 @@ def import_file(self, file_url: str, **kwargs) -> File:
787788
payload = dict(file_url=file_url, **kwargs)
788789
filedata = self.api.post_request(endpoint, body=payload)
789790
return File(filedata, self)
791+
792+
def create_evaluation_task(
793+
self,
794+
task_type: TaskType,
795+
**kwargs,
796+
) -> EvaluationTask:
797+
"""This method can only be used for Self-Serve projects.
798+
Supported Task Types: [
799+
ImageAnnotation,
800+
Categorization,
801+
TextCollection,
802+
NamedEntityRecognition
803+
]
804+
Parameters may differ based on the given task_type.
805+
806+
Args:
807+
task_type (TaskType):
808+
Task type to be created
809+
e.g.. `TaskType.ImageAnnotation`
810+
**kwargs:
811+
The same set of parameters are expected with
812+
create_task function. Additionally with
813+
an expected_response and an optional initial_response
814+
if you want to make it a review phase evaluation task
815+
The expected_response/initial_response should follow
816+
the format of any other tasks' response on your project.
817+
It's recommended to try a self_label batch to get
818+
familiar with the response format.
819+
Scale's API documentation.
820+
https://docs.scale.com/reference
821+
822+
Returns:
823+
EvaluationTask:
824+
Returns created evaluation task.
825+
"""
826+
endpoint = f"evaluation_tasks/{task_type.value}"
827+
828+
evaluation_task_data = self.api.post_request(endpoint, body=kwargs)
829+
return EvaluationTask(evaluation_task_data, self)

scaleapi/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.4.0"
1+
__version__ = "2.5.0"
22
__package_name__ = "scaleapi"

scaleapi/evaluation_tasks.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class EvaluationTask:
2+
"""EvaluationTask class, containing EvaluationTask information."""
3+
4+
def __init__(self, json, client):
5+
self._json = json
6+
self.id = json["id"]
7+
self.initial_response = getattr(json, "initial_response", None)
8+
self.expected_response = json["expected_response"]
9+
self._client = client
10+
11+
def __hash__(self):
12+
return hash(self.id)
13+
14+
def __str__(self):
15+
return f"EvaluationTask(id={self.id})"
16+
17+
def __repr__(self):
18+
return f"EvaluationTask({self._json})"
19+
20+
def as_dict(self):
21+
"""Returns all attributes as a dictionary"""
22+
return self._json

0 commit comments

Comments
 (0)