Skip to content

Commit 5235f07

Browse files
author
Val Brodsky
committed
Integrate with Ontology
1 parent 0d326b4 commit 5235f07

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212

1313
from labelbox.orm.db_object import DbObject
1414
from labelbox.orm.model import Field, Relationship
15+
from labelbox.schema.tool_building.fact_checking_tool import FactCheckingTool
1516
from labelbox.schema.tool_building.step_reasoning_tool import StepReasoningTool
1617
from labelbox.schema.tool_building.tool_type import ToolType
18+
from labelbox.schema.tool_building.tool_type_mapping import (
19+
map_tool_type_to_tool_cls,
20+
)
1721

1822
FeatureSchemaId: Type[str] = Annotated[
1923
str, StringConstraints(min_length=25, max_length=25)
@@ -491,13 +495,14 @@ def add_classification(self, classification: Classification) -> None:
491495

492496

493497
def tool_cls_from_type(tool_type: str):
494-
if tool_type.lower() == ToolType.STEP_REASONING.value:
495-
return StepReasoningTool
498+
tool_cls = map_tool_type_to_tool_cls(tool_type)
499+
if tool_cls is not None:
500+
return tool_cls
496501
return Tool
497502

498503

499504
def tool_type_cls_from_type(tool_type: str):
500-
if tool_type.lower() == ToolType.STEP_REASONING.value:
505+
if ToolType.valid(tool_type):
501506
return ToolType
502507
return Tool.Type
503508

@@ -596,7 +601,9 @@ class OntologyBuilder:
596601
597602
"""
598603

599-
tools: List[Union[Tool, StepReasoningTool]] = field(default_factory=list)
604+
tools: List[Union[Tool, StepReasoningTool, FactCheckingTool]] = field(
605+
default_factory=list
606+
)
600607
classifications: List[
601608
Union[Classification, PromptResponseClassification]
602609
] = field(default_factory=list)

libs/labelbox/src/labelbox/schema/tool_building/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
import labelbox.schema.tool_building.variant
33
import labelbox.schema.tool_building.step_reasoning_tool
44
import labelbox.schema.tool_building.fact_checking_tool
5+
import labelbox.schema.tool_building.tool_type_mapping

libs/labelbox/src/labelbox/schema/tool_building/tool_type.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
class ToolType(Enum):
55
STEP_REASONING = "step-reasoning"
66
FACT_CHECKING = "fact-checking"
7+
8+
@classmethod
9+
def valid(cls, tool_type: str) -> bool:
10+
try:
11+
ToolType(tool_type.lower())
12+
return True
13+
except ValueError:
14+
return False
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from labelbox.schema.tool_building.fact_checking_tool import FactCheckingTool
2+
from labelbox.schema.tool_building.step_reasoning_tool import StepReasoningTool
3+
from labelbox.schema.tool_building.tool_type import ToolType
4+
5+
6+
def map_tool_type_to_tool_cls(tool_type_str: str):
7+
if not ToolType.valid(tool_type_str):
8+
raise ValueError(f"Invalid tool type {tool_type_str}")
9+
10+
tool_type = ToolType(tool_type_str.lower())
11+
if tool_type == ToolType.STEP_REASONING:
12+
return StepReasoningTool
13+
elif tool_type == ToolType.FACT_CHECKING:
14+
return FactCheckingTool
15+
16+
return None

libs/labelbox/src/labelbox/schema/tool_building/variant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def reset_actions(self) -> None:
3131
self.actions = set()
3232

3333
def asdict(self) -> Dict[str, Any]:
34-
return {"id": self.id, "name": self.name, "actions": self.actions}
34+
return {"id": self.id, "name": self.name, "actions": list(self.actions)}

0 commit comments

Comments
 (0)