Skip to content

Commit f70c5b1

Browse files
author
Val Brodsky
committed
More validations
1 parent a18eb5d commit f70c5b1

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class NoFactualInformationStepActions(Enum):
2525
@dataclass
2626
class FactCheckingVariants:
2727
"""
28-
List of possible fact checking variants (options)
29-
Note variant kinds can not be changed
28+
This class is used to define the possible options for fact-checking a step
29+
NOTE do not change steps directly
3030
"""
3131

3232
accurate_step: Variant = field(
@@ -123,13 +123,18 @@ def from_dict(cls, dictionary: List[Dict[str, Any]]):
123123
no_factual_information_step=no_factual_information_step, # type: ignore
124124
)
125125

126+
126127
@dataclass
127128
class FactCheckingDefinition:
128129
variants: FactCheckingVariants = field(default_factory=FactCheckingVariants)
129130
version: int = field(default=1)
130131
title: Optional[str] = None
131132
value: Optional[str] = None
132133

134+
def __post_init__(self):
135+
if self.version != 1:
136+
raise ValueError("Invalid version")
137+
133138
def asdict(self) -> Dict[str, Any]:
134139
result = {"variants": self.variants.asdict(), "version": self.version}
135140
if self.title is not None:
@@ -167,6 +172,9 @@ def __post_init__(self):
167172
"This feature is experimental and subject to change.",
168173
)
169174

175+
if self.name.strip() == "":
176+
raise ValueError("Name cannot be empty")
177+
170178
def set_unsupported_step_actions(
171179
self, actions: List[UnsupportedStepActions]
172180
) -> None:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class StepReasoningDefinition:
7777
title: Optional[str] = None
7878
value: Optional[str] = None
7979

80+
def __post_init__(self):
81+
if self.version != 1:
82+
raise ValueError("Invalid version")
83+
8084
def asdict(self) -> Dict[str, Any]:
8185
result = {"variants": self.variants.asdict(), "version": self.version}
8286
if self.title is not None:
@@ -115,9 +119,14 @@ def __post_init__(self):
115119
"This feature is experimental and subject to change.",
116120
)
117121

122+
if not self.name.strip():
123+
raise ValueError("Name is required")
124+
118125
def set_incorrect_step_actions(self, actions: List[IncorrectStepActions]):
119126
"""
120127
For live models, will invoke the model to generate alternatives if a step is marked as incorrect
128+
NOTE by default all actions are set to True
129+
Pass empty list to reset to false
121130
"""
122131
actions_values = [action.value for action in actions]
123132
self.definition.variants.incorrect_step.set_actions(actions_values)

libs/labelbox/tests/unit/test_unit_step_reasoning_tool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import pytest
2+
13
from labelbox.schema.tool_building.step_reasoning_tool import (
24
IncorrectStepActions,
35
StepReasoningTool,
46
)
57

68

9+
def test_validations():
10+
with pytest.raises(ValueError):
11+
StepReasoningTool(name="")
12+
13+
714
def test_step_reasoning_as_dict_default():
815
tool = StepReasoningTool(name="step reasoning")
916
assert tool.asdict() == {

0 commit comments

Comments
 (0)