diff --git a/.mock/definition/tasks.yml b/.mock/definition/tasks.yml index c45adf0fa..ffd036176 100644 --- a/.mock/definition/tasks.yml +++ b/.mock/definition/tasks.yml @@ -305,6 +305,79 @@ service: response: docs: '' type: root.LseTask + examples: + - name: Create Task + request: + data: + image: https://example.com/image.jpg + text: Hello, world! + project: 1 + response: + body: + agreement: agreement + agreement_selected: agreement_selected + annotations: annotations + annotations_ids: annotations_ids + annotations_results: annotations_results + annotators: + - 1 + annotators_count: 1 + avg_lead_time: 1.1 + cancelled_annotations: 1 + comment_authors: + - key: value + comment_authors_count: 1 + comment_count: 1 + comments: comments + completed_at: '2024-01-15T09:30:00Z' + created_at: '2024-01-15T09:30:00Z' + data: + key: value + draft_exists: true + drafts: + - created_at: '2024-01-15T09:30:00Z' + result: + - key: value + updated_at: '2024-01-15T09:30:00Z' + file_upload: file_upload + ground_truth: true + id: 1 + inner_id: 1 + is_labeled: true + last_comment_updated_at: '2024-01-15T09:30:00Z' + meta: + key: value + overlap: 1 + predictions: + - created_at: '2024-01-15T09:30:00Z' + model: + key: value + model_run: + key: value + model_version: model_version + project: 1 + result: + - key: value + score: 1.1 + task: 1 + updated_at: '2024-01-15T09:30:00Z' + predictions_model_versions: predictions_model_versions + predictions_results: predictions_results + predictions_score: 1.1 + project: 1 + reviewed: true + reviewers: + - key: value + reviewers_count: 1 + reviews_accepted: 1 + reviews_rejected: 1 + storage_filename: storage_filename + total_annotations: 1 + total_predictions: 1 + unresolved_comment_count: 1 + updated_at: '2024-01-15T09:30:00Z' + updated_by: + - key: value audiences: - public get: @@ -556,41 +629,41 @@ service: docs: |2- Create a new task event to track user interactions and system events during annotation. - + This endpoint is designed to receive events from the frontend labeling interface to enable accurate lead time calculation and detailed annotation analytics. - + ## Event Types - + **Core Annotation Events:** - `annotation_loaded` - When annotation interface is loaded - `annotation_submitted` - When annotation is submitted - `annotation_updated` - When annotation is modified - `annotation_reviewed` - When annotation is reviewed - + **User Activity Events:** - `visibility_change` - When page visibility changes (tab switch, minimize) - `idle_detected` - When user goes idle - `idle_resumed` - When user returns from idle - + **Interaction Events:** - `region_finished_drawing` - When annotation region is completed - `region_deleted` - When annotation regions are removed - `hotkey_pressed` - When keyboard shortcuts are used - + **Media Events:** - `video_playback_start/end` - Video playback control - `audio_playback_start/end` - Audio playback control - `video_scrub` - Video timeline scrubbing - + ## Usage - + Events are automatically associated with the task specified in the URL path. The current user is automatically set as the actor. Project and organization are derived from the task context. - + ## Example Request - + ```json { "event_key": "annotation_loaded", diff --git a/.mock/openapi/openapi.yaml b/.mock/openapi/openapi.yaml index e20c4d0d1..7329946ee 100644 --- a/.mock/openapi/openapi.yaml +++ b/.mock/openapi/openapi.yaml @@ -15714,6 +15714,15 @@ paths: requestBody: content: application/json: + examples: + CreateTask: + description: Example of Create Task + summary: Create Task + value: + data: + image: https://example.com/image.jpg + text: Hello, world! + project: 1 schema: $ref: '#/components/schemas/LseTaskRequest' application/x-www-form-urlencoded: @@ -16013,7 +16022,7 @@ paths: x-fern-sdk-method-name: create /api/tasks/{id}/events/: post: - description: "\n Create a new task event to track user interactions and system events during annotation.\n \n This endpoint is designed to receive events from the frontend labeling interface to enable\n accurate lead time calculation and detailed annotation analytics.\n \n ## Event Types\n \n **Core Annotation Events:**\n - `annotation_loaded` - When annotation interface is loaded\n - `annotation_submitted` - When annotation is submitted\n - `annotation_updated` - When annotation is modified\n - `annotation_reviewed` - When annotation is reviewed\n \n **User Activity Events:**\n - `visibility_change` - When page visibility changes (tab switch, minimize)\n - `idle_detected` - When user goes idle\n - `idle_resumed` - When user returns from idle\n \n **Interaction Events:**\n - `region_finished_drawing` - When annotation region is completed\n - `region_deleted` - When annotation regions are removed\n - `hotkey_pressed` - When keyboard shortcuts are used\n \n **Media Events:**\n - `video_playback_start/end` - Video playback control\n - `audio_playback_start/end` - Audio playback control\n - `video_scrub` - Video timeline scrubbing\n \n ## Usage\n \n Events are automatically associated with the task specified in the URL path.\n The current user is automatically set as the actor. Project and organization\n are derived from the task context.\n \n ## Example Request\n \n ```json\n {\n \"event_key\": \"annotation_loaded\",\n \"event_time\": \"2024-01-15T10:30:00Z\",\n \"annotation\": 123,\n \"meta\": {\n \"annotation_count\": 5,\n \"estimated_time\": 300\n }\n }\n ```\n " + description: "\n Create a new task event to track user interactions and system events during annotation.\n\n This endpoint is designed to receive events from the frontend labeling interface to enable\n accurate lead time calculation and detailed annotation analytics.\n\n ## Event Types\n\n **Core Annotation Events:**\n - `annotation_loaded` - When annotation interface is loaded\n - `annotation_submitted` - When annotation is submitted\n - `annotation_updated` - When annotation is modified\n - `annotation_reviewed` - When annotation is reviewed\n\n **User Activity Events:**\n - `visibility_change` - When page visibility changes (tab switch, minimize)\n - `idle_detected` - When user goes idle\n - `idle_resumed` - When user returns from idle\n\n **Interaction Events:**\n - `region_finished_drawing` - When annotation region is completed\n - `region_deleted` - When annotation regions are removed\n - `hotkey_pressed` - When keyboard shortcuts are used\n\n **Media Events:**\n - `video_playback_start/end` - Video playback control\n - `audio_playback_start/end` - Audio playback control\n - `video_scrub` - Video timeline scrubbing\n\n ## Usage\n\n Events are automatically associated with the task specified in the URL path.\n The current user is automatically set as the actor. Project and organization\n are derived from the task context.\n\n ## Example Request\n\n ```json\n {\n \"event_key\": \"annotation_loaded\",\n \"event_time\": \"2024-01-15T10:30:00Z\",\n \"annotation\": 123,\n \"meta\": {\n \"annotation_count\": 5,\n \"estimated_time\": 300\n }\n }\n ```\n " operationId: api_tasks_events_create parameters: - description: Task ID to associate the event with diff --git a/reference.md b/reference.md index 48966a4da..0141bbc22 100644 --- a/reference.md +++ b/reference.md @@ -10207,7 +10207,8 @@ client = LabelStudio( api_key="YOUR_API_KEY", ) client.tasks.create( - data={"key": "value"}, + data={"image": "https://example.com/image.jpg", "text": "Hello, world!"}, + project=1, ) ``` @@ -10740,41 +10741,41 @@ client.tasks.update( Create a new task event to track user interactions and system events during annotation. - + This endpoint is designed to receive events from the frontend labeling interface to enable accurate lead time calculation and detailed annotation analytics. - + ## Event Types - + **Core Annotation Events:** - `annotation_loaded` - When annotation interface is loaded - `annotation_submitted` - When annotation is submitted - `annotation_updated` - When annotation is modified - `annotation_reviewed` - When annotation is reviewed - + **User Activity Events:** - `visibility_change` - When page visibility changes (tab switch, minimize) - `idle_detected` - When user goes idle - `idle_resumed` - When user returns from idle - + **Interaction Events:** - `region_finished_drawing` - When annotation region is completed - `region_deleted` - When annotation regions are removed - `hotkey_pressed` - When keyboard shortcuts are used - + **Media Events:** - `video_playback_start/end` - Video playback control - `audio_playback_start/end` - Audio playback control - `video_scrub` - Video timeline scrubbing - + ## Usage - + Events are automatically associated with the task specified in the URL path. The current user is automatically set as the actor. Project and organization are derived from the task context. - + ## Example Request - + ```json { "event_key": "annotation_loaded", diff --git a/src/label_studio_sdk/tasks/client.py b/src/label_studio_sdk/tasks/client.py index 1c50065ee..b8970b091 100644 --- a/src/label_studio_sdk/tasks/client.py +++ b/src/label_studio_sdk/tasks/client.py @@ -372,7 +372,8 @@ def create( api_key="YOUR_API_KEY", ) client.tasks.create( - data={"key": "value"}, + data={"image": "https://example.com/image.jpg", "text": "Hello, world!"}, + project=1, ) """ _response = self._client_wrapper.httpx_client.request( @@ -1203,7 +1204,11 @@ async def create( async def main() -> None: await client.tasks.create( - data={"key": "value"}, + data={ + "image": "https://example.com/image.jpg", + "text": "Hello, world!", + }, + project=1, ) diff --git a/tests/test_tasks.py b/tests/test_tasks.py index cff84d376..a9634b271 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -81,29 +81,20 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "annotations": "annotations", "annotations_ids": "annotations_ids", "annotations_results": "annotations_results", - "annotators": [1, 1], + "annotators": [1], "annotators_count": 1, "avg_lead_time": 1.1, "cancelled_annotations": 1, - "comment_authors": [{"comment_authors": {"key": "value"}}, {"comment_authors": {"key": "value"}}], + "comment_authors": [{"key": "value"}], "comment_authors_count": 1, - "comment_count": 2147483647, + "comment_count": 1, "comments": "comments", "completed_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "data": {"key": "value"}, "draft_exists": True, "drafts": [ - { - "created_at": "2024-01-15T09:30:00Z", - "result": [{"result": {"key": "value"}}, {"result": {"key": "value"}}], - "updated_at": "2024-01-15T09:30:00Z", - }, - { - "created_at": "2024-01-15T09:30:00Z", - "result": [{"result": {"key": "value"}}, {"result": {"key": "value"}}], - "updated_at": "2024-01-15T09:30:00Z", - }, + {"created_at": "2024-01-15T09:30:00Z", "result": [{"key": "value"}], "updated_at": "2024-01-15T09:30:00Z"} ], "file_upload": "file_upload", "ground_truth": True, @@ -112,46 +103,35 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "is_labeled": True, "last_comment_updated_at": "2024-01-15T09:30:00Z", "meta": {"key": "value"}, - "overlap": 2147483647, + "overlap": 1, "predictions": [ { "created_at": "2024-01-15T09:30:00Z", - "model": {"model": {"key": "value"}}, - "model_run": {"model_run": {"key": "value"}}, - "model_version": "model_version", - "project": 1, - "result": [{"result": {"key": "value"}}, {"result": {"key": "value"}}], - "score": 1.1, - "task": 1, - "updated_at": "2024-01-15T09:30:00Z", - }, - { - "created_at": "2024-01-15T09:30:00Z", - "model": {"model": {"key": "value"}}, - "model_run": {"model_run": {"key": "value"}}, + "model": {"key": "value"}, + "model_run": {"key": "value"}, "model_version": "model_version", "project": 1, - "result": [{"result": {"key": "value"}}, {"result": {"key": "value"}}], + "result": [{"key": "value"}], "score": 1.1, "task": 1, "updated_at": "2024-01-15T09:30:00Z", - }, + } ], "predictions_model_versions": "predictions_model_versions", "predictions_results": "predictions_results", "predictions_score": 1.1, "project": 1, "reviewed": True, - "reviewers": [{"reviewers": {"key": "value"}}, {"reviewers": {"key": "value"}}], + "reviewers": [{"key": "value"}], "reviewers_count": 1, "reviews_accepted": 1, "reviews_rejected": 1, "storage_filename": "storage_filename", "total_annotations": 1, "total_predictions": 1, - "unresolved_comment_count": 2147483647, + "unresolved_comment_count": 1, "updated_at": "2024-01-15T09:30:00Z", - "updated_by": [{"updated_by": {"key": "value"}}, {"updated_by": {"key": "value"}}], + "updated_by": [{"key": "value"}], } expected_types: typing.Any = { "agreement": None, @@ -159,11 +139,11 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "annotations": None, "annotations_ids": None, "annotations_results": None, - "annotators": ("list", {0: "integer", 1: "integer"}), + "annotators": ("list", {0: "integer"}), "annotators_count": "integer", "avg_lead_time": None, "cancelled_annotations": "integer", - "comment_authors": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), + "comment_authors": ("list", {0: ("dict", {0: (None, None)})}), "comment_authors_count": "integer", "comment_count": "integer", "comments": None, @@ -176,14 +156,9 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No { 0: { "created_at": "datetime", - "result": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), - "updated_at": "datetime", - }, - 1: { - "created_at": "datetime", - "result": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), + "result": ("list", {0: ("dict", {0: (None, None)})}), "updated_at": "datetime", - }, + } }, ), "file_upload": None, @@ -203,22 +178,11 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "model_run": ("dict", {0: (None, None)}), "model_version": None, "project": "integer", - "result": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), - "score": None, - "task": "integer", - "updated_at": "datetime", - }, - 1: { - "created_at": "datetime", - "model": ("dict", {0: (None, None)}), - "model_run": ("dict", {0: (None, None)}), - "model_version": None, - "project": "integer", - "result": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), + "result": ("list", {0: ("dict", {0: (None, None)})}), "score": None, "task": "integer", "updated_at": "datetime", - }, + } }, ), "predictions_model_versions": None, @@ -226,7 +190,7 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "predictions_score": None, "project": "integer", "reviewed": None, - "reviewers": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), + "reviewers": ("list", {0: ("dict", {0: (None, None)})}), "reviewers_count": "integer", "reviews_accepted": "integer", "reviews_rejected": "integer", @@ -235,12 +199,14 @@ async def test_create(client: LabelStudio, async_client: AsyncLabelStudio) -> No "total_predictions": "integer", "unresolved_comment_count": "integer", "updated_at": "datetime", - "updated_by": ("list", {0: ("dict", {0: (None, None)}), 1: ("dict", {0: (None, None)})}), + "updated_by": ("list", {0: ("dict", {0: (None, None)})}), } - response = client.tasks.create(data={"key": "value"}) + response = client.tasks.create(data={"image": "https://example.com/image.jpg", "text": "Hello, world!"}, project=1) validate_response(response, expected_response, expected_types) - async_response = await async_client.tasks.create(data={"key": "value"}) + async_response = await async_client.tasks.create( + data={"image": "https://example.com/image.jpg", "text": "Hello, world!"}, project=1 + ) validate_response(async_response, expected_response, expected_types)