Skip to content

Commit 202e592

Browse files
author
Val Brodsky
committed
Simplify create_project by removing ontology_kind
1 parent 4bbfec4 commit 202e592

File tree

4 files changed

+145
-134
lines changed

4 files changed

+145
-134
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ def create_project(self, **kwargs) -> Project:
744744
InvalidAttributeError: If the Project type does not contain
745745
any of the attribute names given in kwargs.
746746
"""
747-
kwargs.pop("ontology_kind", None)
748747
kwargs.pop("dataset_name_or_id", None)
749748
kwargs.pop("append_to_existing_dataset", None)
750749
kwargs.pop("data_row_count", None)
@@ -823,6 +822,9 @@ def create_offline_model_evaluation_project(self, **kwargs) -> Project:
823822
kwargs["media_type"] = MediaType.Conversational
824823
kwargs[
825824
"editor_task_type"] = EditorTaskType.OfflineModelChatEvaluation.value
825+
kwargs.pop("dataset_name_or_id", None)
826+
kwargs.pop("append_to_existing_dataset", None)
827+
kwargs.pop("data_row_count", None)
826828

827829
return self.create_project(**kwargs)
828830

@@ -866,15 +868,6 @@ def _create_project(self, **kwargs) -> Project:
866868
" through this method will soon no longer be supported.")
867869
media_type_value = None
868870

869-
ontology_kind = kwargs.pop("ontology_kind", None)
870-
if ontology_kind and OntologyKind.is_supported(ontology_kind):
871-
editor_task_type_value = EditorTaskTypeMapper.to_editor_task_type(
872-
ontology_kind, media_type).value
873-
elif ontology_kind:
874-
raise OntologyKind.get_ontology_kind_validation_error(ontology_kind)
875-
else:
876-
editor_task_type_value = None
877-
878871
quality_mode = kwargs.get("quality_mode")
879872
if not quality_mode:
880873
logger.info("Defaulting quality mode to Benchmark.")

libs/labelbox/tests/integration/conftest.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,138 @@ def chat_evaluation_project_append_to_dataset(client, dataset, rand_gen):
439439
project.delete()
440440

441441

442+
@pytest.fixture
443+
def offline_conversational_data_row(initial_dataset):
444+
convo_v2_row_data = {
445+
"type": "application/vnd.labelbox.conversational.model-chat-evaluation",
446+
"version": 2,
447+
"actors": {
448+
"clxhs9wk000013b6w7imiz0h8": {
449+
"role": "human",
450+
"metadata": {
451+
"name": "User"
452+
}
453+
},
454+
"clxhsc6xb00013b6w1awh579j": {
455+
"role": "model",
456+
"metadata": {
457+
"modelConfigId": "5a50d319-56bd-405d-87bb-4442daea0d0f"
458+
}
459+
},
460+
"clxhsc6xb00023b6wlp0768zs": {
461+
"role": "model",
462+
"metadata": {
463+
"modelConfigId": "1cfc833a-2684-47df-95ac-bb7d9f9e3e1f"
464+
}
465+
}
466+
},
467+
"messages": {
468+
"clxhs9wk000023b6wrufora3k": {
469+
"actorId": "clxhs9wk000013b6w7imiz0h8",
470+
"content": [{
471+
"type": "text",
472+
"content": "Hello world"
473+
}],
474+
"childMessageIds": ["clxhscb4z00033b6wukpvmuol"]
475+
},
476+
"clxhscb4z00033b6wukpvmuol": {
477+
"actorId": "clxhsc6xb00013b6w1awh579j",
478+
"content": [{
479+
"type":
480+
"text",
481+
"content":
482+
"Hello to you too! 👋 \n\nIt's great to be your guide in the digital world. What can I help you with today? 😊 \n"
483+
}],
484+
"childMessageIds": ["clxhu2s0900013b6wbv0ndddd"]
485+
},
486+
"clxhu2s0900013b6wbv0ndddd": {
487+
"actorId":
488+
"clxhs9wk000013b6w7imiz0h8",
489+
"content": [{
490+
"type": "text",
491+
"content": "Lets some some multi-turn happening"
492+
}],
493+
"childMessageIds": [
494+
"clxhu4qib00023b6wuep47b1l", "clxhu4qib00033b6wf18az01q"
495+
]
496+
},
497+
"clxhu4qib00023b6wuep47b1l": {
498+
"actorId": "clxhsc6xb00013b6w1awh579j",
499+
"content": [{
500+
"type":
501+
"text",
502+
"content":
503+
"Okay, I'm ready for some multi-turn fun! To make it interesting, how about we try building a story together? \n\n**Here's the beginning:**\n\nThe old, dusty book lay forgotten on the shelf, its leather cover cracked and faded. But as the afternoon sun slanted through the window, a single ray caught a glint of gold on the book's spine. Suddenly...\n\n**Now you tell me what happens!** What does the glint of gold turn out to be? What happens next? 🤔 \n"
504+
}],
505+
"childMessageIds": ["clxhu596m00043b6wvkgahcwz"]
506+
},
507+
"clxhu4qib00033b6wf18az01q": {
508+
"actorId": "clxhsc6xb00023b6wlp0768zs",
509+
"content": [{
510+
"type":
511+
"text",
512+
"content":
513+
"Okay, I'm game! Let's have a multi-turn conversation! But to get us started, give me a topic or a question to get us going! 😄 \n\nWhat's on your mind? \n"
514+
}],
515+
"childMessageIds": ["clxhu596m00043b6wvkgahcwz"]
516+
},
517+
"clxhu596m00043b6wvkgahcwz": {
518+
"actorId":
519+
"clxhs9wk000013b6w7imiz0h8",
520+
"content": [{
521+
"type": "text",
522+
"content": "Can you generate an image?"
523+
}],
524+
"childMessageIds": [
525+
"clxhu5hqk00053b6wk21u6xi7", "clxhu5hqk00063b6whl4gofx8"
526+
]
527+
},
528+
"clxhu5hqk00053b6wk21u6xi7": {
529+
"actorId": "clxhsc6xb00013b6w1awh579j",
530+
"content": [{
531+
"type":
532+
"text",
533+
"content":
534+
"I can't generate images directly yet. I'm a text-based AI, so my superpowers are all about words! 🪄 \n\nHowever, I'd love to help you describe an image that fits our story. Tell me: \n\n* **What should the image show?** (For example: The dusty book, the glint of gold, the bookshelf, the room, etc.) \n* **What kind of feeling or atmosphere should the image have?** (Mysterious? Magical? Ominous?) \n\nThe more details you give me, the better I can describe the image! ✨ \n"
535+
}],
536+
"childMessageIds": []
537+
},
538+
"clxhu5hqk00063b6whl4gofx8": {
539+
"actorId": "clxhsc6xb00023b6wlp0768zs",
540+
"content": [{
541+
"type":
542+
"text",
543+
"content":
544+
"I can't *actually* generate images directly. 😔 I'm primarily a text-based AI. \n\nTo help me understand what you'd like to see, tell me: \n\n* **What should be in the image?** Be specific! (e.g., \"A cat wearing a tiny hat\", \"A futuristic cityscape at sunset\")\n* **What style do you imagine?** (e.g., realistic, cartoonish, abstract)\n\nOnce you give me those details, I can try to give you a vivid description that's almost as good as seeing it! 😊 \n"
545+
}],
546+
"childMessageIds": []
547+
}
548+
},
549+
"rootMessageIds": ["clxhs9wk000023b6wrufora3k"]
550+
}
551+
552+
convo_v2_asset = {
553+
"row_data": convo_v2_row_data,
554+
}
555+
data_row = initial_dataset.create_data_row(convo_v2_asset)
556+
557+
return data_row
558+
559+
560+
@pytest.fixture()
561+
def conversation_data_row(initial_dataset, rand_gen):
562+
data = {
563+
"row_data":
564+
"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json",
565+
"global_key":
566+
f"https://storage.googleapis.com/labelbox-developer-testing-assets/conversational_text/1000-conversations/conversation-1.json-{rand_gen(str)}",
567+
}
568+
convo_asset = {"row_data": data}
569+
data_row = initial_dataset.create_data_row(convo_asset)
570+
571+
return data_row
572+
573+
442574
def pytest_configure():
443575
pytest.report = defaultdict(int)
444576

libs/labelbox/tests/integration/test_chat_evaluation_ontology_project.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
2-
from labelbox import OntologyBuilder, Tool
32
from labelbox import MediaType
43
from labelbox.schema.ontology_kind import OntologyKind
5-
from labelbox.schema.labeling_frontend import LabelingFrontend
4+
from labelbox.exceptions import MalformedQueryException
65

76

87
def test_create_chat_evaluation_ontology_project(
98
client, chat_evaluation_ontology,
10-
chat_evaluation_project_create_dataset):
9+
chat_evaluation_project_create_dataset, conversation_data_row,
10+
rand_gen):
1111
ontology = chat_evaluation_ontology
1212

1313
# here we are essentially testing the ontology creation which is a fixture
@@ -29,6 +29,13 @@ def test_create_chat_evaluation_ontology_project(
2929
assert project.labeling_frontend().name == "Editor"
3030
assert project.ontology().name == ontology.name
3131

32+
with pytest.raises(MalformedQueryException,
33+
match="No valid data rows to add to project"):
34+
project.create_batch(
35+
rand_gen(str),
36+
[conversation_data_row.uid], # sample of data row objects
37+
)
38+
3239

3340
def test_create_chat_evaluation_ontology_project_existing_dataset(
3441
client, chat_evaluation_ontology,

libs/labelbox/tests/integration/test_offline_chat_evaluation_project.py

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,3 @@
1-
import pytest
2-
3-
4-
@pytest.fixture
5-
def offline_conversational_data_row(initial_dataset):
6-
convo_v2_row_data = {
7-
"type": "application/vnd.labelbox.conversational.model-chat-evaluation",
8-
"version": 2,
9-
"actors": {
10-
"clxhs9wk000013b6w7imiz0h8": {
11-
"role": "human",
12-
"metadata": {
13-
"name": "User"
14-
}
15-
},
16-
"clxhsc6xb00013b6w1awh579j": {
17-
"role": "model",
18-
"metadata": {
19-
"modelConfigId": "5a50d319-56bd-405d-87bb-4442daea0d0f"
20-
}
21-
},
22-
"clxhsc6xb00023b6wlp0768zs": {
23-
"role": "model",
24-
"metadata": {
25-
"modelConfigId": "1cfc833a-2684-47df-95ac-bb7d9f9e3e1f"
26-
}
27-
}
28-
},
29-
"messages": {
30-
"clxhs9wk000023b6wrufora3k": {
31-
"actorId": "clxhs9wk000013b6w7imiz0h8",
32-
"content": [{
33-
"type": "text",
34-
"content": "Hello world"
35-
}],
36-
"childMessageIds": ["clxhscb4z00033b6wukpvmuol"]
37-
},
38-
"clxhscb4z00033b6wukpvmuol": {
39-
"actorId": "clxhsc6xb00013b6w1awh579j",
40-
"content": [{
41-
"type":
42-
"text",
43-
"content":
44-
"Hello to you too! 👋 \n\nIt's great to be your guide in the digital world. What can I help you with today? 😊 \n"
45-
}],
46-
"childMessageIds": ["clxhu2s0900013b6wbv0ndddd"]
47-
},
48-
"clxhu2s0900013b6wbv0ndddd": {
49-
"actorId":
50-
"clxhs9wk000013b6w7imiz0h8",
51-
"content": [{
52-
"type": "text",
53-
"content": "Lets some some multi-turn happening"
54-
}],
55-
"childMessageIds": [
56-
"clxhu4qib00023b6wuep47b1l", "clxhu4qib00033b6wf18az01q"
57-
]
58-
},
59-
"clxhu4qib00023b6wuep47b1l": {
60-
"actorId": "clxhsc6xb00013b6w1awh579j",
61-
"content": [{
62-
"type":
63-
"text",
64-
"content":
65-
"Okay, I'm ready for some multi-turn fun! To make it interesting, how about we try building a story together? \n\n**Here's the beginning:**\n\nThe old, dusty book lay forgotten on the shelf, its leather cover cracked and faded. But as the afternoon sun slanted through the window, a single ray caught a glint of gold on the book's spine. Suddenly...\n\n**Now you tell me what happens!** What does the glint of gold turn out to be? What happens next? 🤔 \n"
66-
}],
67-
"childMessageIds": ["clxhu596m00043b6wvkgahcwz"]
68-
},
69-
"clxhu4qib00033b6wf18az01q": {
70-
"actorId": "clxhsc6xb00023b6wlp0768zs",
71-
"content": [{
72-
"type":
73-
"text",
74-
"content":
75-
"Okay, I'm game! Let's have a multi-turn conversation! But to get us started, give me a topic or a question to get us going! 😄 \n\nWhat's on your mind? \n"
76-
}],
77-
"childMessageIds": ["clxhu596m00043b6wvkgahcwz"]
78-
},
79-
"clxhu596m00043b6wvkgahcwz": {
80-
"actorId":
81-
"clxhs9wk000013b6w7imiz0h8",
82-
"content": [{
83-
"type": "text",
84-
"content": "Can you generate an image?"
85-
}],
86-
"childMessageIds": [
87-
"clxhu5hqk00053b6wk21u6xi7", "clxhu5hqk00063b6whl4gofx8"
88-
]
89-
},
90-
"clxhu5hqk00053b6wk21u6xi7": {
91-
"actorId": "clxhsc6xb00013b6w1awh579j",
92-
"content": [{
93-
"type":
94-
"text",
95-
"content":
96-
"I can't generate images directly yet. I'm a text-based AI, so my superpowers are all about words! 🪄 \n\nHowever, I'd love to help you describe an image that fits our story. Tell me: \n\n* **What should the image show?** (For example: The dusty book, the glint of gold, the bookshelf, the room, etc.) \n* **What kind of feeling or atmosphere should the image have?** (Mysterious? Magical? Ominous?) \n\nThe more details you give me, the better I can describe the image! ✨ \n"
97-
}],
98-
"childMessageIds": []
99-
},
100-
"clxhu5hqk00063b6whl4gofx8": {
101-
"actorId": "clxhsc6xb00023b6wlp0768zs",
102-
"content": [{
103-
"type":
104-
"text",
105-
"content":
106-
"I can't *actually* generate images directly. 😔 I'm primarily a text-based AI. \n\nTo help me understand what you'd like to see, tell me: \n\n* **What should be in the image?** Be specific! (e.g., \"A cat wearing a tiny hat\", \"A futuristic cityscape at sunset\")\n* **What style do you imagine?** (e.g., realistic, cartoonish, abstract)\n\nOnce you give me those details, I can try to give you a vivid description that's almost as good as seeing it! 😊 \n"
107-
}],
108-
"childMessageIds": []
109-
}
110-
},
111-
"rootMessageIds": ["clxhs9wk000023b6wrufora3k"]
112-
}
113-
114-
convo_v2_asset = {
115-
"row_data": convo_v2_row_data,
116-
}
117-
data_row = initial_dataset.create_data_row(convo_v2_asset)
118-
119-
return data_row
120-
121-
1221
def test_create_offline_chat_evaluation_project(
1232
client, rand_gen, offline_chat_evaluation_project,
1243
chat_evaluation_ontology, offline_conversational_data_row):

0 commit comments

Comments
 (0)