Skip to content

Commit a99daea

Browse files
author
Tony Wu
authored
Add training tasks endpoint to Python client (#50)
* Add training tasks endpoint to Python client * fix * lint
1 parent bdbbd95 commit a99daea

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,19 @@ __ https://docs.scale.com/reference
528528
529529
client.create_evaluation_task(TaskType.TextCollection, **payload)
530530
531+
Training tasks (For Scale Rapid projects only)
532+
________________________________________________
533+
534+
Training tasks are used to onboard taskers onto your project
535+
536+
Create Training Task
537+
^^^^^^^^^^^^^^^^^^^^^^
538+
539+
Create a training task.
540+
541+
.. code-block:: python
542+
543+
client.create_training_task(TaskType, ...task parameters...)
531544
532545
Error handling
533546
______________

scaleapi/__init__.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from scaleapi.exceptions import ScaleInvalidRequest
66
from scaleapi.files import File
77
from scaleapi.projects import Project
8+
from scaleapi.training_tasks import TrainingTask
89

910
from ._version import __version__ # noqa: F401
1011
from .api import Api
@@ -794,10 +795,12 @@ def create_evaluation_task(
794795
task_type: TaskType,
795796
**kwargs,
796797
) -> EvaluationTask:
797-
"""This method can only be used for Self-Serve projects.
798+
"""This method can only be used for Rapid projects.
798799
Supported Task Types: [
800+
DocumentTranscription,
801+
SegmentAnnotation,
802+
VideoPlaybackAnnotation,
799803
ImageAnnotation,
800-
Categorization,
801804
TextCollection,
802805
NamedEntityRecognition
803806
]
@@ -827,3 +830,38 @@ def create_evaluation_task(
827830

828831
evaluation_task_data = self.api.post_request(endpoint, body=kwargs)
829832
return EvaluationTask(evaluation_task_data, self)
833+
834+
def create_training_task(
835+
self,
836+
task_type: TaskType,
837+
**kwargs,
838+
) -> TrainingTask:
839+
"""This method can only be used for Rapid projects.
840+
Supported Task Types: [
841+
DocumentTranscription,
842+
SegmentAnnotation,
843+
VideoPlaybackAnnotation,
844+
ImageAnnotation,
845+
TextCollection,
846+
NamedEntityRecognition
847+
]
848+
Parameters may differ based on the given task_type.
849+
850+
Args:
851+
task_type (TaskType):
852+
Task type to be created
853+
e.g.. `TaskType.ImageAnnotation`
854+
**kwargs:
855+
The same set of parameters are expected with
856+
create_task function and an additional expected_response.
857+
Scale's API documentation.
858+
https://docs.scale.com/reference
859+
860+
Returns:
861+
TrainingTask:
862+
Returns created training task.
863+
"""
864+
endpoint = f"training_tasks/{task_type.value}"
865+
866+
training_task_data = self.api.post_request(endpoint, body=kwargs)
867+
return TrainingTask(training_task_data, self)

scaleapi/training_tasks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class TrainingTask:
2+
"""TrainingTask class, containing TrainingTask 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"TrainingTask(id={self.id})"
16+
17+
def __repr__(self):
18+
return f"TrainingTask({self._json})"
19+
20+
def as_dict(self):
21+
"""Returns all attributes as a dictionary"""
22+
return self._json

0 commit comments

Comments
 (0)