# Toloka Tasks


This module contains a collection of tasks for interacting with the Toloka API.

All Toloka-related tasks can be authenticated using the TOLOKA_TOKEN Prefect Secret that should contain a Toloka API OAuth token. See Third Party Authentication for more information.

# Functions

top-level functions:                                                                                                                                                       

prefect.tasks.toloka.utils.create_project

(obj, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to create a Toloka Project object from given config.

Args:

  • obj (Project, Dict, str, bytes): Either a Project object itself or a config to make a Project.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Project: Toloka project object with id assigned.
Example: >>> project_conf = {...} # May also be configured toloka.client.Project object. >>> project = create_project(project_conf) ...

prefect.tasks.toloka.utils.create_exam_pool

(obj, project_id=None, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to create a Toloka Training pool object from given config.

Args:

  • obj (Training, Dict, str, bytes): Either a Training object itself or a config to make a Training.
  • project_id (Project, Dict, str, optional): Project ID to assign a training pool to. May pass either an object, config or project_id value.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Training: Toloka training pool object with id assigned.
Example: >>> project = create_project({...}) >>> exam = create_exam_pool({...}, project_id=project) ...

prefect.tasks.toloka.utils.create_pool

(obj, project_id=None, exam_pool_id=None, expiration=None, reward_per_assignment=None, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to create a Toloka Pool object from given config.

Args:

  • obj (Pool, Dict, str, bytes): Either a Pool object itself or a config to make a Pool.
  • project_id (Project, Dict, str, optional): Project ID to assign a pool to. May pass either an object, config or project_id value.
  • exam_pool_id (Training, Dict, str, optional): Related training pool ID. May pass either an object, config or pool_id value.
  • expiration (datetime, timedelta, optional): Expiration setting. May pass any of: None if this setting if already present; datetime object to set exact datetime; timedelta to set expiration related to the current time.
  • reward_per_assignment (float, optional): Allow to redefine reward per assignment.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Pool: Toloka pool object with id assigned.
Example: >>> project = create_project({...}) >>> exam = create_exam_pool({...}, project_id=project) >>> pool = create_pool({...}, project_id=project, exam_pool_id=exam) ...

prefect.tasks.toloka.utils.create_tasks

(tasks, pool_id=None, allow_defaults=False, open_pool=False, skip_invalid_items=False, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to create a list of tasks for a given pool.

Args:

  • tasks (List[Union[TolokaTask, Dict]]): List of either a toloka.client.Task objects or task conofigurations.
  • pool_id (Pool, Training, Dict, str, optional): Allow to set tasks pool ID if it's not present in tasks themselves. May be either a Pool or Training object or config or a pool_id value.
  • allow_defaults (bool, optional): Allow to use the overlap that is set in the pool parameters.
  • open_pool (bool, optional): Open the pool immediately after creating a task suite, if closed.
  • skip_invalid_items (bool, optional): Allow to skip invalid tasks. You can handle them using resulting TaskBatchCreateResult object.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • TaskBatchCreateResult: Result object.
Example: >>> tasks = [{'input_values': ...}, {'input_values': ...}, {'input_values': ...}] >>> create_tasks(tasks, ... pool_id='some-pool_id-123', ... open_pool=True, ... allow_defaults=True) ...

prefect.tasks.toloka.utils.open_pool

(obj, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to open given Toloka pool.

Args:

  • obj (Pool, Dict, str): Pool id or Pool object of it's config.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Pool: Opened pool object.
Example: >>> pool = create_pool({...}) >>> _tasks_creation = create_tasks([...], pool=pool) >>> open_pool(pool, upstream_tasks=[_tasks_creation]) ...

prefect.tasks.toloka.utils.open_exam_pool

(obj, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to open given training pool.

Args:

  • obj (Training, Dict, str): Training pool_id or Training object of it's config.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Training: Opened training (exam) pool object.
Example: >>> exam = create_training({...}) >>> _exam_tasks_creation = create_tasks([...], pool=exam) >>> open_exam_pool(exam, upstream_tasks=[_exam_tasks_creation]) ...

prefect.tasks.toloka.utils.wait_pool

(pool_id, period=datetime.timedelta(seconds=60), open_pool=False, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to wait given Toloka pool until close.

Args:

  • pool_id (Pool, Dict, str): Either a Pool object or it's config or a pool ID value.
  • period (timedelta): Interval between checks. One minute by default.
  • open_pool (bool, optional): Allow to open pool at start if it's closed. False by default.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Pool: Toloka pool object.
Example: >>> pool = create_pool({...}) >>> _tasks_creation = create_tasks([...], pool=pool) >>> wait_pool(pool, open_pool=True, upstream_tasks=[_tasks_creation]) ...

prefect.tasks.toloka.utils.get_assignments

(pool_id, status=None, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION", **kwargs)[source]

Task to get all assignments of selected status from Toloka pool.

Args:

  • pool_id (Pool, Dict, str): Either a Pool object or it's config or a pool ID value.
  • status (str, List[str], optional): A status or a list of statuses to get. All statuses (None) by default.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
  • **kwargs: Other args presented in toloka.client.search_requests.AssignmentSearchRequest.
Returns:
  • List[Assignment]: Get assignments result.
Example: >>> pool = create_pool({...}) >>> _tasks_creation = create_tasks([...], pool=pool) >>> _waiting = wait_pool(pool, open_pool=True, upstream_tasks=[_tasks_creation]) >>> results = get_assignments(pool, status=['SUBMITTED'], upstream_tasks=[_waiting]) ...

prefect.tasks.toloka.utils.get_assignments_df

(pool_id, status=None, start_time_from=None, start_time_to=None, exclude_banned=False, field=None, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to get pool assignments of selected statuses in Pandas DataFrame format useful for aggregation.

Args:

  • pool_id (Pool, Dict, str): Either a Pool object or it's config or a pool ID value.
  • status (str, List[str], optional): A status or a list of statuses to get. All statuses (None) by default.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
  • start_time_from (str, optional): Upload assignments submitted after the specified datetime.
  • start_time_to (str, optional): Upload assignments submitted before the specified datetime.
  • exclude_banned (bool, optional): Exclude answers from banned performers, even if assignments in suitable status "ACCEPTED".
  • field (List[GetAssignmentsTsvParameters.Field], optional): Select some additional fields. You can find possible values in the toloka.client.assignment.GetAssignmentsTsvParameters.Field enum.
Returns:
  • DataFrame: pd.DataFrame with selected assignments. Note that nested paths are presented with a ":" sign.
Example: >>> pool = create_pool({...}) >>> _tasks_creation = create_tasks([...], pool=pool) >>> _waiting = wait_pool(pool, open_pool=True, upstream_tasks=[_tasks_creation]) >>> df = get_assignments_df(pool, status=['SUBMITTED'], upstream_tasks=[_waiting]) ...

prefect.tasks.toloka.utils.accept_assignment

(assignment_id, public_comment, fail_if_already_set=False, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to accept given assignment by given ID. Use accept_assignment.map to process multiple assignments. Pass public_comment with unmapped wrapper in this case.

Args:

  • assignment_id (Assignment, Dict, str): Either an Assignment object or it's config or an assignment ID value.
  • public_comment (str): Public comment.
  • fail_if_already_set (bool, optional): Fail if the assignment has already been accepted (in the UI for example). Skip by default.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Union[Assignment, Dict, str]: The same assignment_id, that was given.
Example: >>> aggregated = do_some_aggregation(assignments) >>> to_accept = some_filter_to_accept(aggregated) >>> accept_assignment.map(to_accept, unmapped('Well done!')) ...

prefect.tasks.toloka.utils.reject_assignment

(assignment_id, public_comment, fail_if_already_set=False, token=None, secret_name="TOLOKA_TOKEN", env="PRODUCTION")[source]

Task to reject given assignment by given ID. Use reject_assignment.map to process multiple assignments. Pass public_comment with unmapped wrapper in this case.

Args:

  • assignment_id (Assignment, Dict, str): Either an Assignment object or it's config or an assignment ID value.
  • public_comment (str): Public comment.
  • fail_if_already_set (bool, optional): Fail if the assignment has already been rejected (in the UI for example). Skip by default.
  • token (str, optional): Toloka token value provided with a Prefect Secret. If not provided the task will fallback to using Secret with secret_name.
  • secret_name (str, optional): Allow to use non-default secret for Toloka token. Default: "TOLOKA_TOKEN".
  • env (str, optional): Allow to use non-default Toloka environment. Default: "PRODUCTION".
Returns:
  • Union[Assignment, Dict, str]: The same assignment_id, that was given.
Example: >>> aggregated = do_some_aggregation(assignments) >>> to_reject = some_filter_to_reject(aggregated) >>> reject_assignment.map(to_reject, unmapped('Incorrect answer')) ...

This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC