Skip to content

Commit 59b7027

Browse files
hakan458hakan458
andauthored
fix: UTC-310: Fix prediction validation for per-region labels (#629)
Co-authored-by: hakan458 <hakan@heartex.com>
1 parent 9945e08 commit 59b7027

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/label_studio_sdk/label_interface/control_tags.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ def as_tuple(self):
503503

504504

505505
class SpanSelection(BaseModel):
506-
start: Union[int, str]
507-
end: Union[int, str]
506+
start: Union[float, int, str]
507+
end: Union[float, int, str]
508508

509509

510510
class SpanSelectionOffsets(SpanSelection):
@@ -561,6 +561,7 @@ class LabelsTag(ControlTag):
561561
_label_attr_name: str = "labels"
562562
_value_class: Type[LabelsValue] = LabelsValue
563563

564+
564565
def to_json_schema(self):
565566
"""
566567
Converts the current LabelsTag instance into a JSON Schema.
@@ -572,16 +573,20 @@ def to_json_schema(self):
572573
"type": "array",
573574
"items": {
574575
"type": "object",
575-
"required": ["start", "end", "labels"],
576+
"required": ["labels"],
576577
"properties": {
577578
"start": {
578-
"type": "integer",
579+
"oneOf": [
580+
{"type": "integer", "minimum": 0},
581+
{"type": "number", "minimum": 0}
582+
],
579583
# TODO: this is incompatible with the OpenAI API using PredictedOutputs
580-
"minimum": 0
581584
},
582585
"end": {
583-
"type": "integer",
584-
"minimum": 0
586+
"oneOf": [
587+
{"type": "integer", "minimum": 0},
588+
{"type": "number", "minimum": 0}
589+
]
585590
},
586591
"labels": {
587592
"type": "array",

tests/custom/test_interface/test_json_schema.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,19 @@
8686
"description": "Labels and span indices for txt",
8787
"items": {
8888
"type": "object",
89-
"required": ["start", "end", "labels"],
89+
"required": ["labels"],
9090
"properties": {
9191
"start": {
92-
"type": "integer",
93-
"minimum": 0
92+
"oneOf": [
93+
{"type": "integer", "minimum": 0},
94+
{"type": "number", "minimum": 0}
95+
]
9496
},
9597
"end": {
96-
"type": "integer",
97-
"minimum": 0
98+
"oneOf": [
99+
{"type": "integer", "minimum": 0},
100+
{"type": "number", "minimum": 0}
101+
]
98102
},
99103
"labels": {
100104
"type": "array",
@@ -397,4 +401,4 @@ def test_concurrent_json_schema_to_pydantic_threaded():
397401
assert None not in results
398402

399403
# Check if execution time is reasonable (adjust as needed)
400-
assert end_time - start_time < 1.0, f"Execution took too long: {end_time - start_time} seconds"
404+
assert end_time - start_time < 1.0, f"Execution took too long: {end_time - start_time} seconds"

0 commit comments

Comments
 (0)