Skip to content

Commit 3f894f0

Browse files
authored
[PTDT-1867] Add llm data gen label types (#1317)
2 parents 3aa42a8 + 6bf4073 commit 3f894f0

File tree

9 files changed

+169
-18
lines changed

9 files changed

+169
-18
lines changed

labelbox/data/annotation_types/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
from .data import MaskData
4343
from .data import TextData
4444
from .data import VideoData
45+
from .data import LlmPromptResponseCreationData
46+
from .data import LlmPromptCreationData
47+
from .data import LlmResponseCreationData
4548

4649
from .label import Label
4750
from .collection import LabelList

labelbox/data/annotation_types/data/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
from .raster import ImageData
77
from .raster import MaskData
88
from .text import TextData
9-
from .video import VideoData
9+
from .video import VideoData
10+
from .llm_prompt_response_creation import LlmPromptResponseCreationData
11+
from .llm_prompt_creation import LlmPromptCreationData
12+
from .llm_response_creation import LlmResponseCreationData
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from labelbox.typing_imports import Literal
2+
from labelbox.utils import _NoCoercionMixin
3+
from .base_data import BaseData
4+
5+
6+
class LlmPromptCreationData(BaseData, _NoCoercionMixin):
7+
class_name: Literal["LlmPromptCreationData"] = "LlmPromptCreationData"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from labelbox.typing_imports import Literal
2+
from labelbox.utils import _NoCoercionMixin
3+
from .base_data import BaseData
4+
5+
6+
class LlmPromptResponseCreationData(BaseData, _NoCoercionMixin):
7+
class_name: Literal[
8+
"LlmPromptResponseCreationData"] = "LlmPromptResponseCreationData"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from labelbox.typing_imports import Literal
2+
from labelbox.utils import _NoCoercionMixin
3+
from .base_data import BaseData
4+
5+
6+
class LlmResponseCreationData(BaseData, _NoCoercionMixin):
7+
class_name: Literal["LlmResponseCreationData"] = "LlmResponseCreationData"

labelbox/data/annotation_types/label.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .annotation import ClassificationAnnotation, ObjectAnnotation
1111
from .relationship import RelationshipAnnotation
1212
from .classification import ClassificationAnswer
13-
from .data import AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData, MaskData, TextData, VideoData
13+
from .data import AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData, MaskData, TextData, VideoData, LlmPromptCreationData, LlmPromptResponseCreationData, LlmResponseCreationData
1414
from .geometry import Mask
1515
from .metrics import ScalarMetric, ConfusionMatrixMetric
1616
from .types import Cuid
@@ -19,7 +19,9 @@
1919
from ..ontology import get_feature_schema_lookup
2020

2121
DataType = Union[VideoData, ImageData, TextData, TiledImageData, AudioData,
22-
ConversationData, DicomData, DocumentData, HTMLData]
22+
ConversationData, DicomData, DocumentData, HTMLData,
23+
LlmPromptCreationData, LlmPromptResponseCreationData,
24+
LlmResponseCreationData]
2325

2426

2527
class Label(BaseModel):

tests/integration/annotation_import/conftest.py

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,35 @@ def text_data_row(rand_gen):
122122
}
123123

124124

125+
@pytest.fixture()
126+
def llm_prompt_creation_data_row(rand_gen):
127+
return {
128+
"row_data": {
129+
"type": "application/llm.prompt-creation",
130+
"version": 1
131+
},
132+
"global_key": rand_gen(str)
133+
}
134+
135+
136+
@pytest.fixture()
137+
def llm_prompt_response_data_row(rand_gen):
138+
return {
139+
"row_data": {
140+
"type": "application/llm.prompt-response-creation",
141+
"version": 1
142+
},
143+
"global_key": rand_gen(str)
144+
}
145+
146+
125147
@pytest.fixture
126148
def data_row_json_by_data_type(audio_data_row, conversation_data_row,
127149
dicom_data_row, geospatial_data_row,
128150
html_data_row, image_data_row, document_data_row,
129-
text_data_row, video_data_row):
151+
text_data_row, video_data_row,
152+
llm_prompt_creation_data_row,
153+
llm_prompt_response_data_row):
130154
return {
131155
'audio': audio_data_row,
132156
'conversation': conversation_data_row,
@@ -137,6 +161,9 @@ def data_row_json_by_data_type(audio_data_row, conversation_data_row,
137161
'document': document_data_row,
138162
'text': text_data_row,
139163
'video': video_data_row,
164+
'llmpromptcreation': llm_prompt_creation_data_row,
165+
'llmpromptresponsecreation': llm_prompt_response_data_row,
166+
'llmresponsecreation': text_data_row
140167
}
141168

142169

@@ -146,16 +173,33 @@ def exports_v2_by_data_type(expected_export_v2_image, expected_export_v2_audio,
146173
expected_export_v2_video,
147174
expected_export_v2_conversation,
148175
expected_export_v2_dicom,
149-
expected_export_v2_document):
176+
expected_export_v2_document,
177+
expected_export_v2_llm_prompt_creation,
178+
expected_export_v2_llm_prompt_response_creation,
179+
expected_export_v2_llm_response_creation):
150180
return {
151-
'image': expected_export_v2_image,
152-
'audio': expected_export_v2_audio,
153-
'html': expected_export_v2_html,
154-
'text': expected_export_v2_text,
155-
'video': expected_export_v2_video,
156-
'conversation': expected_export_v2_conversation,
157-
'dicom': expected_export_v2_dicom,
158-
'document': expected_export_v2_document,
181+
'image':
182+
expected_export_v2_image,
183+
'audio':
184+
expected_export_v2_audio,
185+
'html':
186+
expected_export_v2_html,
187+
'text':
188+
expected_export_v2_text,
189+
'video':
190+
expected_export_v2_video,
191+
'conversation':
192+
expected_export_v2_conversation,
193+
'dicom':
194+
expected_export_v2_dicom,
195+
'document':
196+
expected_export_v2_document,
197+
'llmpromptcreation':
198+
expected_export_v2_llm_prompt_creation,
199+
'llmpromptresponsecreation':
200+
expected_export_v2_llm_prompt_response_creation,
201+
'llmresponsecreation':
202+
expected_export_v2_llm_response_creation
159203
}
160204

161205

@@ -179,7 +223,10 @@ def annotations_by_data_type(polygon_inference, rectangle_inference,
179223
checklist_inference, text_inference
180224
],
181225
'text': [entity_inference, checklist_inference, text_inference],
182-
'video': [video_checklist_inference]
226+
'video': [video_checklist_inference],
227+
'llmpromptcreation': [checklist_inference, text_inference],
228+
'llmpromptresponsecreation': [checklist_inference, text_inference],
229+
'llmresponsecreation': [checklist_inference, text_inference]
183230
}
184231

185232

@@ -207,7 +254,10 @@ def annotations_by_data_type_v2(
207254
checklist_inference, text_inference
208255
],
209256
'text': [entity_inference, checklist_inference, text_inference],
210-
'video': [video_checklist_inference]
257+
'video': [video_checklist_inference],
258+
'llmpromptcreation': [checklist_inference, text_inference],
259+
'llmpromptresponsecreation': [checklist_inference, text_inference],
260+
'llmresponsecreation': [checklist_inference, text_inference]
211261
}
212262

213263

tests/integration/annotation_import/fixtures/export_v2.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,66 @@ def expected_export_v2_document():
317317
'relationships': []
318318
}
319319
return expected_annotations
320+
321+
322+
@pytest.fixture()
323+
def expected_export_v2_llm_prompt_creation():
324+
expected_annotations = {
325+
'objects': [],
326+
'classifications': [{
327+
'name': 'checklist',
328+
'checklist_answers': [{
329+
'name': 'option1',
330+
'classifications': []
331+
}]
332+
}, {
333+
'name': 'text',
334+
'text_answer': {
335+
'content': 'free form text...'
336+
}
337+
}],
338+
'relationships': []
339+
}
340+
return expected_annotations
341+
342+
343+
@pytest.fixture()
344+
def expected_export_v2_llm_prompt_response_creation():
345+
expected_annotations = {
346+
'objects': [],
347+
'classifications': [{
348+
'name': 'checklist',
349+
'checklist_answers': [{
350+
'name': 'option1',
351+
'classifications': []
352+
}]
353+
}, {
354+
'name': 'text',
355+
'text_answer': {
356+
'content': 'free form text...'
357+
}
358+
}],
359+
'relationships': []
360+
}
361+
return expected_annotations
362+
363+
364+
@pytest.fixture()
365+
def expected_export_v2_llm_response_creation():
366+
expected_annotations = {
367+
'objects': [],
368+
'classifications': [{
369+
'name': 'checklist',
370+
'checklist_answers': [{
371+
'name': 'option1',
372+
'classifications': []
373+
}]
374+
}, {
375+
'name': 'text',
376+
'text_answer': {
377+
'content': 'free form text...'
378+
}
379+
}],
380+
'relationships': []
381+
}
382+
return expected_annotations

tests/integration/annotation_import/test_data_types.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from labelbox.schema.data_row import DataRow
99
from labelbox.schema.media_type import MediaType
1010
import labelbox.types as lb_types
11-
from labelbox.data.annotation_types.data import AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData, TextData
11+
from labelbox.data.annotation_types.data import AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData, TextData, LlmPromptCreationData, LlmPromptResponseCreationData, LlmResponseCreationData
1212
from labelbox.data.serialization import NDJsonConverter
1313
from labelbox.schema.annotation_import import AnnotationImportState
1414
from utils import remove_keys_recursive, rename_cuid_key_recursive
@@ -134,7 +134,8 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
134134
# TODO: Add VideoData. Currently label import job finishes without errors but project.export_labels() returns empty list.
135135
@pytest.mark.parametrize('data_type_class', [
136136
AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData,
137-
TextData
137+
TextData, LlmPromptCreationData, LlmPromptResponseCreationData,
138+
LlmResponseCreationData
138139
])
139140
def test_import_data_types(
140141
client,
@@ -243,12 +244,19 @@ def set_project_media_type_from_data_type(project, data_type_class):
243244
media_type = to_pascal_case(data_type_string)
244245
if media_type == 'Conversation':
245246
media_type = 'Conversational'
247+
elif media_type == 'Llmpromptcreation':
248+
media_type = 'LLMPromptCreation'
249+
elif media_type == 'Llmpromptresponsecreation':
250+
media_type = 'LLMPromptResponseCreation'
251+
elif media_type == 'Llmresponsecreation':
252+
media_type = 'Text'
246253
project.update(media_type=MediaType[media_type])
247254

248255

249256
@pytest.mark.parametrize('data_type_class', [
250257
AudioData, HTMLData, ImageData, TextData, VideoData, ConversationData,
251-
DocumentData, DicomData
258+
DocumentData, DicomData, LlmPromptCreationData,
259+
LlmPromptResponseCreationData, LlmResponseCreationData
252260
])
253261
def test_import_data_types_v2(client, configured_project, initial_dataset,
254262
data_row_json_by_data_type,

0 commit comments

Comments
 (0)