Created
December 29, 2023 01:38
-
-
Save wooparadog/5be3d3735cd6256aa93ffde4023a0a69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, List, Optional | |
from orion.dash.common import DefaultTopLevelLabels | |
from orion.dash.label.label import create_new_label | |
from orion.dash.label.model import Label | |
LABLES = [ | |
DefaultTopLevelLabels.PRIVATE, | |
DefaultTopLevelLabels.EVALUATION_TEMPLATE, | |
{ | |
"Source": [ | |
"Wechat", | |
"Line", | |
"Telegram", | |
"WhatsApp", | |
"iMessage", | |
], | |
}, | |
{ | |
"Primary Language": ["English", "Japanese", "Chinese"], | |
}, | |
{ | |
"Secondary Language": ["English", "Japanese", "Chinese"], | |
}, | |
{ | |
"Intention": [ | |
{ | |
"Single": [ | |
{ | |
"Calendar": [ | |
"Single Create", | |
"Multiple Create", | |
"Delete", | |
"Edit", | |
"Search", | |
"Mixed", | |
], | |
}, | |
"Task", | |
"Weather", | |
"FAQ", | |
"Settings", | |
"Feedback", | |
{ | |
"Keyword": [ | |
"Character", | |
"Settings URL", | |
] | |
}, | |
], | |
}, | |
"Mixed", | |
"Other", | |
], | |
}, | |
{ | |
"Intention Fulfillment": [ | |
"A", | |
"B", | |
"C", | |
], | |
}, | |
{ | |
"Errors": [ | |
"Time Extraction", | |
"Text Extraction", | |
"Redundant", | |
{ | |
"Multi-Model": [ | |
"Voice", | |
"Image", | |
], | |
}, | |
"Language", | |
"Misinformation", | |
"Context", | |
"Unsupported", | |
"Other", | |
], | |
}, | |
{ | |
"Feature Request": [ | |
"Yes", | |
{ | |
"No": ["Stock Price"], | |
}, | |
], | |
}, | |
{ | |
"Test Case": [ | |
"Core", | |
] | |
}, | |
] | |
def create_tree_label(label: str, parent: Optional[Label] = None): | |
if parent: | |
assert parent.slug | |
return create_new_label( | |
name=label, | |
description="system default label", | |
parent_id=parent.id, | |
created_by=0, | |
properties=[], | |
slug=parent.slug + "/" + label, | |
) | |
else: | |
return create_new_label( | |
name=label, | |
description="system default label", | |
parent_id=0, | |
created_by=0, | |
properties=[], | |
slug=label, | |
) | |
def create_label_tree(labels: List[str | Dict], parent: Optional[Label] = None): | |
for label in labels: | |
if isinstance(label, str): | |
create_tree_label(label, parent=parent) | |
if isinstance(label, dict): | |
for k, v in label.items(): | |
tree_root_label = create_tree_label(k, parent) | |
yield from create_label_tree(v, parent=tree_root_label) | |
def create_default_labels(): | |
print(f"Created: {len(list(create_label_tree(LABLES)))} labels") | |
if __name__ == "__main__": | |
create_default_labels() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment