Skip to content

Commit 4d29fdf

Browse files
committed
fixed one method
1 parent e8b7cac commit 4d29fdf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

libs/labelbox/src/labelbox/schema/ontology.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Option:
5353
label: Optional[Union[str, int]] = None
5454
schema_id: Optional[str] = None
5555
feature_schema_id: Optional[FeatureSchemaId] = None
56-
options: List["Classification"] = field(default_factory=list)
56+
options: Union[List["Classification"], List["PromptResponseClassification"]] = field(default_factory=list)
5757

5858
def __post_init__(self):
5959
if self.label is None:
@@ -82,7 +82,7 @@ def asdict(self) -> Dict[str, Any]:
8282
"options": [o.asdict(is_subclass=True) for o in self.options]
8383
}
8484

85-
def add_option(self, option: 'Classification') -> None:
85+
def add_option(self, option: Union["Classification", "PromptResponseClassification"]) -> None:
8686
if option.name in (o.name for o in self.options):
8787
raise InconsistentOntologyException(
8888
f"Duplicate nested classification '{option.name}' "
@@ -239,7 +239,20 @@ class ResponseOption(Option):
239239
feature_schema_id: (str)
240240
options: (list)
241241
"""
242-
pass
242+
243+
@classmethod
244+
def from_dict(
245+
cls,
246+
dictionary: Dict[str,
247+
Any]) -> Dict[Union[str, int], Union[str, int]]:
248+
return cls(value=dictionary["value"],
249+
label=dictionary["label"],
250+
schema_id=dictionary.get("schemaNodeId", None),
251+
feature_schema_id=dictionary.get("featureSchemaId", None),
252+
options=[
253+
PromptResponseClassification.from_dict(o)
254+
for o in dictionary.get("options", [])
255+
])
243256

244257

245258
@dataclass

0 commit comments

Comments
 (0)