Skip to content

Commit 7576486

Browse files
authored
[PLT-1866][SDK][STEP REASONING] Actions Required for All Variants (#1894)
1 parent 74b076c commit 7576486

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,31 @@
99
class StepReasoningVariant:
1010
id: int
1111
name: str
12+
actions: List[str] = field(default_factory=list)
1213

1314
def asdict(self) -> Dict[str, Any]:
14-
return {"id": self.id, "name": self.name}
15+
return {"id": self.id, "name": self.name, "actions": self.actions}
1516

1617

1718
@dataclass
1819
class IncorrectStepReasoningVariant:
1920
id: int
2021
name: str
21-
regenerate_conversations_after_incorrect_step: Optional[bool] = True
22-
rate_alternative_responses: Optional[bool] = True
22+
regenerate_steps: Optional[bool] = True
23+
generate_and_rate_alternative_steps: Optional[bool] = True
24+
rewrite_steps: Optional[bool] = True
25+
justification: Optional[bool] = True
2326

2427
def asdict(self) -> Dict[str, Any]:
2528
actions = []
26-
if self.regenerate_conversations_after_incorrect_step:
29+
if self.regenerate_steps:
2730
actions.append("regenerateSteps")
28-
if self.rate_alternative_responses:
31+
if self.generate_and_rate_alternative_steps:
2932
actions.append("generateAndRateAlternativeSteps")
33+
if self.rewrite_steps:
34+
actions.append("rewriteSteps")
35+
if self.justification:
36+
actions.append("justification")
3037
return {"id": self.id, "name": self.name, "actions": actions}
3138

3239
@classmethod
@@ -36,10 +43,11 @@ def from_dict(
3643
return cls(
3744
id=dictionary["id"],
3845
name=dictionary["name"],
39-
regenerate_conversations_after_incorrect_step="regenerateSteps"
40-
in dictionary.get("actions", []),
41-
rate_alternative_responses="generateAndRateAlternativeSteps"
46+
regenerate_steps="regenerateSteps" in dictionary.get("actions", []),
47+
generate_and_rate_alternative_steps="generateAndRateAlternativeSteps"
4248
in dictionary.get("actions", []),
49+
rewrite_steps="rewriteSteps" in dictionary.get("actions", []),
50+
justification="justification" in dictionary.get("actions", []),
4351
)
4452

4553

@@ -162,20 +170,30 @@ def __post_init__(self):
162170
"This feature is experimental and subject to change.",
163171
)
164172

165-
def reset_regenerate_conversations_after_incorrect_step(self):
173+
def reset_regenerate_steps(self):
166174
"""
167175
For live models, the default acation will invoke the model to generate alternatives if a step is marked as incorrect
168176
This method will reset the action to not regenerate the conversation
169177
"""
170-
self.definition.variants.incorrect_step.regenerate_conversations_after_incorrect_step = False
178+
self.definition.variants.incorrect_step.regenerate_steps = False
171179

172-
def reset_rate_alternative_responses(self):
180+
def reset_generate_and_rate_alternative_steps(self):
173181
"""
174182
For live models, will require labelers to rate the alternatives generated by the model
175183
"""
176-
self.definition.variants.incorrect_step.rate_alternative_responses = (
177-
False
178-
)
184+
self.definition.variants.incorrect_step.generate_and_rate_alternative_steps = False
185+
186+
def reset_rewrite_steps(self):
187+
"""
188+
For live models, will require labelers to rewrite the conversation
189+
"""
190+
self.definition.variants.incorrect_step.rewrite_steps = False
191+
192+
def reset_justification(self):
193+
"""
194+
For live models, will require labelers to provide a justification for their evaluation
195+
"""
196+
self.definition.variants.incorrect_step.justification = False
179197

180198
def asdict(self) -> Dict[str, Any]:
181199
return {

libs/labelbox/tests/unit/test_unit_step_reasoning_tool.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ def test_step_reasoning_as_dict_default():
1111
"featureSchemaId": None,
1212
"definition": {
1313
"variants": [
14-
{"id": 0, "name": "Correct"},
15-
{"id": 1, "name": "Neutral"},
14+
{"id": 0, "name": "Correct", "actions": []},
15+
{"id": 1, "name": "Neutral", "actions": []},
1616
{
1717
"id": 2,
1818
"name": "Incorrect",
1919
"actions": [
2020
"regenerateSteps",
2121
"generateAndRateAlternativeSteps",
22+
"rewriteSteps",
23+
"justification",
2224
],
2325
},
2426
],
@@ -29,8 +31,10 @@ def test_step_reasoning_as_dict_default():
2931

3032
def test_step_reasoning_as_dict_with_actions():
3133
tool = StepReasoningTool(name="step reasoning")
32-
tool.reset_rate_alternative_responses()
33-
tool.reset_regenerate_conversations_after_incorrect_step()
34+
tool.reset_generate_and_rate_alternative_steps()
35+
tool.reset_regenerate_steps()
36+
tool.reset_rewrite_steps()
37+
tool.reset_justification()
3438
assert tool.asdict() == {
3539
"tool": "step-reasoning",
3640
"name": "step reasoning",
@@ -39,8 +43,8 @@ def test_step_reasoning_as_dict_with_actions():
3943
"featureSchemaId": None,
4044
"definition": {
4145
"variants": [
42-
{"id": 0, "name": "Correct"},
43-
{"id": 1, "name": "Neutral"},
46+
{"id": 0, "name": "Correct", "actions": []},
47+
{"id": 1, "name": "Neutral", "actions": []},
4448
{
4549
"id": 2,
4650
"name": "Incorrect",

0 commit comments

Comments
 (0)