Skip to content

Commit b79b11a

Browse files
author
Val Brodsky
committed
Tests for FactChecking
1 parent 64156f6 commit b79b11a

File tree

4 files changed

+98
-12
lines changed

4 files changed

+98
-12
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dataclasses import dataclass, field
2-
from typing import Any, Dict, List, Optional, Set
2+
from enum import Enum
3+
from typing import Any, Dict, List, Optional
34

45
from labelbox.schema.tool_building.tool_type import ToolType
56
from labelbox.schema.tool_building.variant import (
@@ -8,6 +9,18 @@
89
)
910

1011

12+
class UnsupportedStepActions(Enum):
13+
WRITE_JUSTIFICATION = "writeJustification"
14+
15+
16+
class CanConfidentlyAssessStepActions(Enum):
17+
WRITE_JUSTIFICATION = "writeJustification"
18+
19+
20+
class NoFactualInformationStepActions(Enum):
21+
WRITE_JUSTIFICATION = "writeJustification"
22+
23+
1124
@dataclass
1225
class FactCheckingVariants:
1326
"""
@@ -26,21 +39,32 @@ class FactCheckingVariants:
2639
)
2740
unsupported_step: VariantWithActions = field(
2841
default_factory=lambda: VariantWithActions(
29-
id=3, name="Unsupported", _available_actions={"writeJustification"}
42+
id=3,
43+
name="Unsupported",
44+
_available_actions={
45+
action.value for action in UnsupportedStepActions
46+
},
47+
actions=[UnsupportedStepActions.WRITE_JUSTIFICATION.value],
3048
)
3149
)
3250
cant_confidently_assess_step: VariantWithActions = field(
3351
default_factory=lambda: VariantWithActions(
3452
id=4,
3553
name="Can't confidently assess",
36-
_available_actions={"writeJustification"},
54+
_available_actions={
55+
action.value for action in CanConfidentlyAssessStepActions
56+
},
57+
actions=[CanConfidentlyAssessStepActions.WRITE_JUSTIFICATION.value],
3758
)
3859
)
3960
no_factual_information_step: VariantWithActions = field(
4061
default_factory=lambda: VariantWithActions(
4162
id=5,
4263
name="No factual information",
43-
_available_actions={"writeJustification"},
64+
_available_actions={
65+
action.value for action in NoFactualInformationStepActions
66+
},
67+
actions=[NoFactualInformationStepActions.WRITE_JUSTIFICATION.value],
4468
)
4569
)
4670

@@ -139,22 +163,25 @@ class FactCheckingTool:
139163
)
140164

141165
def set_unsupported_step_actions(
142-
self, actions: Set[str] = {"writeJustification"}
166+
self, actions: List[UnsupportedStepActions]
143167
) -> None:
144-
self.definition.variants.unsupported_step.set_actions(actions)
168+
actions_values = [action.value for action in actions]
169+
self.definition.variants.unsupported_step.set_actions(actions_values)
145170

146171
def set_cant_confidently_assess_step_actions(
147-
self, actions: Set[str] = {"writeJustification"}
172+
self, actions: List[CanConfidentlyAssessStepActions]
148173
) -> None:
174+
actions_values = [action.value for action in actions]
149175
self.definition.variants.cant_confidently_assess_step.set_actions(
150-
actions
176+
actions_values
151177
)
152178

153179
def set_no_factual_information_step_actions(
154-
self, actions: Set[str] = {"writeJustification"}
180+
self, actions: List[NoFactualInformationStepActions]
155181
) -> None:
182+
actions_values = [action.value for action in actions]
156183
self.definition.variants.no_factual_information_step.set_actions(
157-
actions
184+
actions_values
158185
)
159186

160187
def asdict(self) -> Dict[str, Any]:

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ def reset_actions(self) -> None:
3232
self.actions = []
3333

3434
def asdict(self) -> Dict[str, Any]:
35-
return {
35+
data = {
3636
"id": self.id,
3737
"name": self.name,
38-
"actions": list(set(self.actions)),
3938
}
39+
if len(self.actions) > 0:
40+
data["actions"] = self.actions
41+
42+
return data

libs/labelbox/tests/integration/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222
from labelbox.schema.data_row import DataRowMetadataField
2323
from labelbox.schema.ontology_kind import OntologyKind
24+
from labelbox.schema.tool_building.fact_checking_tool import FactCheckingTool
2425
from labelbox.schema.tool_building.step_reasoning_tool import StepReasoningTool
2526
from labelbox.schema.user import User
2627

@@ -579,6 +580,7 @@ def chat_evaluation_ontology(client, rand_gen):
579580
name="model output multi ranking",
580581
),
581582
StepReasoningTool(name="step reasoning"),
583+
FactCheckingTool(name="fact checking"),
582584
],
583585
classifications=[
584586
Classification(

libs/labelbox/tests/integration/test_ontology.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from labelbox import MediaType, OntologyBuilder, Tool
77
from labelbox.orm.model import Entity
8+
from labelbox.schema.tool_building.fact_checking_tool import FactCheckingTool
89
from labelbox.schema.tool_building.step_reasoning_tool import StepReasoningTool
910

1011

@@ -367,3 +368,56 @@ def test_step_reasoning_ontology(chat_evaluation_ontology):
367368
"actions": ["regenerateSteps"],
368369
},
369370
]
371+
372+
373+
def test_fact_checking_ontology(chat_evaluation_ontology):
374+
ontology = chat_evaluation_ontology
375+
fact_checking = None
376+
for tool in ontology.normalized["tools"]:
377+
if tool["tool"] == "fact-checking":
378+
fact_checking = tool
379+
break
380+
assert fact_checking is not None
381+
assert fact_checking["definition"]["variants"] == [
382+
{"id": 0, "name": "Accurate"},
383+
{"id": 1, "name": "Inaccurate"},
384+
{"id": 2, "name": "Disputed"},
385+
{"id": 3, "name": "Unsupported", "actions": ["writeJustification"]},
386+
{
387+
"id": 4,
388+
"name": "Can't confidently assess",
389+
"actions": ["writeJustification"],
390+
},
391+
{
392+
"id": 5,
393+
"name": "No factual information",
394+
"actions": ["writeJustification"],
395+
},
396+
]
397+
assert fact_checking["definition"]["version"] == 1
398+
assert fact_checking["schemaNodeId"] is not None
399+
assert fact_checking["featureSchemaId"] is not None
400+
401+
fact_checking = None
402+
for tool in ontology.tools():
403+
if isinstance(tool, FactCheckingTool):
404+
fact_checking = tool
405+
break
406+
assert fact_checking is not None
407+
408+
assert fact_checking.definition.variants.asdict() == [
409+
{"id": 0, "name": "Accurate"},
410+
{"id": 1, "name": "Inaccurate"},
411+
{"id": 2, "name": "Disputed"},
412+
{"id": 3, "name": "Unsupported", "actions": ["writeJustification"]},
413+
{
414+
"id": 4,
415+
"name": "Can't confidently assess",
416+
"actions": ["writeJustification"],
417+
},
418+
{
419+
"id": 5,
420+
"name": "No factual information",
421+
"actions": ["writeJustification"],
422+
},
423+
]

0 commit comments

Comments
 (0)