From a29a34a618a6ec677b5f7f76ca2b1efa15e4ab94 Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Tue, 29 Oct 2024 14:57:40 +0400 Subject: [PATCH 1/7] ci: Remove poetry cache for label-studio-client-generator in FM --- .github/workflows/follow-merge-upstream-repo-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/follow-merge-upstream-repo-sync.yml b/.github/workflows/follow-merge-upstream-repo-sync.yml index 0052798..6219af9 100644 --- a/.github/workflows/follow-merge-upstream-repo-sync.yml +++ b/.github/workflows/follow-merge-upstream-repo-sync.yml @@ -77,7 +77,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - cache: 'poetry' +# cache: 'poetry' # Disable cache since label-studio-client-generator does not have poetry.lock - name: Download Fern run: npm install -g fern-api From a588ba578c7ee12e80b244dac6bd09331d0b95eb Mon Sep 17 00:00:00 2001 From: niklub Date: Tue, 29 Oct 2024 20:55:42 +0000 Subject: [PATCH 2/7] fix: DIA-1489: Multiskill prompt autorefinement fixes (#345) Co-authored-by: nik --- .../label_interface/control_tags.py | 17 ++++++ .../test_interface/test_control_tags.py | 53 ++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/label_studio_sdk/label_interface/control_tags.py b/src/label_studio_sdk/label_interface/control_tags.py index 442d213..45e0213 100644 --- a/src/label_studio_sdk/label_interface/control_tags.py +++ b/src/label_studio_sdk/label_interface/control_tags.py @@ -462,6 +462,23 @@ def label( ) else: return self._label_simple(to_name=to_name, *args, **kwargs) + + def get_labels(self, regions: List[Dict]): + """ + Returns the simplified representation of the label. Sort of a reverse to label() method to retrieve an input `label` from an output regions + """ + values = [region.get('value') for region in regions if region.get('from_name') == self.name] + values = list(filter(lambda x: x is not None, values)) + if not hasattr(self, "_label_attr_name"): + return values + labels = [] + for value in values: + if len(value) == 1 and self._label_attr_name in value: + v = value[self._label_attr_name] + labels.append(v[0] if len(v) == 1 else v) + else: + labels.append(value) + return labels[0] if len(labels) == 1 else labels def as_tuple(self): """ """ diff --git a/tests/custom/test_interface/test_control_tags.py b/tests/custom/test_interface/test_control_tags.py index 73910bd..5ea724c 100644 --- a/tests/custom/test_interface/test_control_tags.py +++ b/tests/custom/test_interface/test_control_tags.py @@ -1,8 +1,9 @@ import json +import pytest from lxml.etree import Element from label_studio_sdk.label_interface import LabelInterface -from label_studio_sdk.label_interface.control_tags import ControlTag +from label_studio_sdk.label_interface.control_tags import ControlTag, ChoicesTag, LabelsTag, RectangleLabelsTag from . import configs as c @@ -53,3 +54,53 @@ def test_label_with_choices(): assert "choices" in rpy.get("value") assert c.LABEL1 in rpy["value"]["choices"] + + +@pytest.mark.parametrize("tag, regions, expected", [ + # Test case 1: ChoicesTag with single choice + ( + ChoicesTag(name="choices", to_name=["text"], tag="Choices"), + [{"from_name": "choices", "value": {"choices": ["positive"]}}], + "positive" + ), + + # Test case 2: ChoicesTag with multiple choices + ( + ChoicesTag(name="choices", to_name=["text"], tag="Choices"), + [{"from_name": "choices", "value": {"choices": ["positive", "negative"]}}], + ["positive", "negative"] + ), + + # Test case 3: Multiple regions with labels + ( + LabelsTag(name="label", to_name=["text"], tag="Labels"), + [ + {"from_name": "label", "to_name": "text", "value": {"labels": ["positive"], "start": 0, "end": 1}}, + {"from_name": "label", "to_name": "text", "value": {"labels": ["negative"], "start": 2, "end": 3}} + ], + [{"start": 0, "end": 1, "labels": ["positive"]}, {"start": 2, "end": 3, "labels": ["negative"]}] + ), + + # Test case 4: Empty regions + ( + ChoicesTag(name="choices", to_name=["text"], tag="Choices"), + [], + [] + ), + + # Test case 5: Regions with different from_name + ( + ChoicesTag(name="choices", to_name=["text"], tag="Choices"), + [{"from_name": "other_tag", "value": {"choices": ["positive"]}}], + [] + ), + + # Test case 6: Tag without label_attr_name + ( + ControlTag(name="base", to_name=["text"], tag="BaseTag"), + [{"from_name": "base", "value": {"some_value": 42}}], + [{"some_value": 42}] + ), +]) +def test_control_tag_get_labels(tag, regions, expected): + assert tag.get_labels(regions) == expected From 1116711f65dee597ac915c98166cf7c2f1d39d29 Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Wed, 30 Oct 2024 17:10:36 +0400 Subject: [PATCH 3/7] ci: Add all GH workflows to .fernignore --- .fernignore | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.fernignore b/.fernignore index 3802be0..2712418 100644 --- a/.fernignore +++ b/.fernignore @@ -32,24 +32,9 @@ tests/custom/test_interface tests/test_webhooks.py # manual workflows -.github/workflows/ci.yml +.github/workflows/* .github/release.yml .github/pr-title-checker-config.json .github/autolabeler.yml .github/CODEOWNERS -.github/workflows/slash-command-dispatch.yml -.github/workflows/follow-merge-sync-pr-lse.yml -.github/workflows/lint.yml -.github/workflows/build_pypi.yml -.github/workflows/codeql.yml -.github/workflows/release-set-version.yml -.github/workflows/release-pipeline.yml -.github/workflows/docs.yml -.github/workflows/release-cut-off-release-branch.yml -.github/workflows/jira-command.yml -.github/workflows/tests.yml -.github/workflows/pr-labeler.yml -.github/workflows/follow-merge-sync-pr-lso.yml -.github/workflows/follow-merge-upstream-repo-sync.yml -.github/workflows/update-draft-release.yml .github/dependabot.yml From 6b08b37523f16c6a4cd75bebe48fe60adbf0bb74 Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Wed, 30 Oct 2024 17:51:13 +0400 Subject: [PATCH 4/7] ci: Explicitly add all GH workflows to .fernignore --- .fernignore | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.fernignore b/.fernignore index 2712418..cddcaab 100644 --- a/.fernignore +++ b/.fernignore @@ -32,8 +32,21 @@ tests/custom/test_interface tests/test_webhooks.py # manual workflows -.github/workflows/* -.github/release.yml +.github/workflows/build_pypi.yml +.github/workflows/codeql.yml +.github/workflows/docs.yml +.github/workflows/follow-merge-sync-pr-adala.yml +.github/workflows/follow-merge-sync-pr-lso.yml +.github/workflows/follow-merge-upstream-repo-sync.yml +.github/workflows/jira-command.yml +.github/workflows/lint.yml +.github/workflows/pr-labeler.yml +.github/workflows/release-cut-off-release-branch.yml +.github/workflows/release-pipeline.yml +.github/workflows/release-set-version.yml +.github/workflows/slash-command-dispatch.yml +.github/workflows/tests.yml +.github/workflows/update-draft-release.yml .github/pr-title-checker-config.json .github/autolabeler.yml .github/CODEOWNERS From 6776dac00f56488da953301407aa991709b76d8f Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Wed, 30 Oct 2024 18:00:33 +0400 Subject: [PATCH 5/7] ci: Add .github/release.yml to .fernignore --- .fernignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.fernignore b/.fernignore index cddcaab..eb03f15 100644 --- a/.fernignore +++ b/.fernignore @@ -48,6 +48,7 @@ tests/test_webhooks.py .github/workflows/tests.yml .github/workflows/update-draft-release.yml .github/pr-title-checker-config.json +.github/release.yml .github/autolabeler.yml .github/CODEOWNERS .github/dependabot.yml From f68b723eed2bffb6984ddb5f8409ed9e7608d912 Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Wed, 30 Oct 2024 18:06:17 +0400 Subject: [PATCH 6/7] ci: Add .github/ci.yml to .fernignore --- .fernignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.fernignore b/.fernignore index eb03f15..65bb519 100644 --- a/.fernignore +++ b/.fernignore @@ -32,6 +32,7 @@ tests/custom/test_interface tests/test_webhooks.py # manual workflows +.github/workflows/ci.yml .github/workflows/build_pypi.yml .github/workflows/codeql.yml .github/workflows/docs.yml From 91637159ca49586098d5b5f60fa451cfe980dc0d Mon Sep 17 00:00:00 2001 From: robot-ci-heartex <87703623+robot-ci-heartex@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:03:58 +0000 Subject: [PATCH 7/7] fix: DIA-1562: false precision in cost reports (#347) Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Matt Bernstein --- .mock/definition/__package__.yml | 2 +- .mock/definition/prompts/versions.yml | 4 ++-- src/label_studio_sdk/types/refined_prompt_response.py | 2 +- tests/prompts/test_versions.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.mock/definition/__package__.yml b/.mock/definition/__package__.yml index b3c7268..dfe652e 100644 --- a/.mock/definition/__package__.yml +++ b/.mock/definition/__package__.yml @@ -2398,7 +2398,7 @@ types: docs: Status of the refinement job default: Pending total_cost: - type: optional + type: optional docs: Total cost of the refinement job (in USD) previous_version: type: optional diff --git a/.mock/definition/prompts/versions.yml b/.mock/definition/prompts/versions.yml index 3846665..f3e2d86 100644 --- a/.mock/definition/prompts/versions.yml +++ b/.mock/definition/prompts/versions.yml @@ -248,7 +248,7 @@ service: prompt: prompt refinement_job_id: refinement_job_id refinement_status: Pending - total_cost: 1.1 + total_cost: total_cost previous_version: title: title parent_model: 1 @@ -309,7 +309,7 @@ service: prompt: prompt refinement_job_id: refinement_job_id refinement_status: Pending - total_cost: 1.1 + total_cost: total_cost previous_version: title: title parent_model: 1 diff --git a/src/label_studio_sdk/types/refined_prompt_response.py b/src/label_studio_sdk/types/refined_prompt_response.py index 54c28ab..5c53a94 100644 --- a/src/label_studio_sdk/types/refined_prompt_response.py +++ b/src/label_studio_sdk/types/refined_prompt_response.py @@ -35,7 +35,7 @@ class RefinedPromptResponse(pydantic_v1.BaseModel): Status of the refinement job """ - total_cost: typing.Optional[float] = pydantic_v1.Field(default=None) + total_cost: typing.Optional[str] = pydantic_v1.Field(default=None) """ Total cost of the refinement job (in USD) """ diff --git a/tests/prompts/test_versions.py b/tests/prompts/test_versions.py index 021feb4..1af9e4d 100644 --- a/tests/prompts/test_versions.py +++ b/tests/prompts/test_versions.py @@ -182,7 +182,7 @@ async def test_get_refined_prompt(client: LabelStudio, async_client: AsyncLabelS "prompt": "prompt", "refinement_job_id": "refinement_job_id", "refinement_status": "Pending", - "total_cost": 1.1, + "total_cost": "total_cost", "previous_version": { "title": "title", "parent_model": 1, @@ -234,7 +234,7 @@ async def test_refine_prompt(client: LabelStudio, async_client: AsyncLabelStudio "prompt": "prompt", "refinement_job_id": "refinement_job_id", "refinement_status": "Pending", - "total_cost": 1.1, + "total_cost": "total_cost", "previous_version": { "title": "title", "parent_model": 1,