142 lines
4.6 KiB
Python
142 lines
4.6 KiB
Python
|
|
import unittest
|
||
|
|
|
||
|
|
from cockpit_agent.common.enums import Interaction, SliderOrientation, Zone
|
||
|
|
from cockpit_agent.grounding.semantic_target import SemanticTargetBuilder
|
||
|
|
from cockpit_agent.intent.schemas import SemanticAction
|
||
|
|
from cockpit_agent.common.enums import Domain, Operation, State, Unit
|
||
|
|
from cockpit_agent.planning.schemas import ActionPlan
|
||
|
|
|
||
|
|
|
||
|
|
class SemanticTargetBuilderTest(unittest.TestCase):
|
||
|
|
def setUp(self) -> None:
|
||
|
|
self.builder = SemanticTargetBuilder()
|
||
|
|
|
||
|
|
def test_temperature_query_uses_semantic_zone_and_direction(self) -> None:
|
||
|
|
query = self.builder.build_action_target(
|
||
|
|
ActionPlan(
|
||
|
|
interaction=Interaction.TAP,
|
||
|
|
function="temperature_decrease",
|
||
|
|
zone=Zone.DRIVER,
|
||
|
|
repeat=3,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
self.assertEqual(query, "主驾驶温度降低控制")
|
||
|
|
|
||
|
|
def test_recirculation_query(self) -> None:
|
||
|
|
query = self.builder.build_action_target(
|
||
|
|
ActionPlan(
|
||
|
|
interaction=Interaction.TAP,
|
||
|
|
function="air_recirculation",
|
||
|
|
zone=Zone.ALL,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
self.assertEqual(query, "车辆空调内循环控制")
|
||
|
|
|
||
|
|
def test_slider_query(self) -> None:
|
||
|
|
query = self.builder.build_action_target(
|
||
|
|
ActionPlan(
|
||
|
|
interaction=Interaction.DRAG,
|
||
|
|
function="tailgate_max_opening",
|
||
|
|
normalized_target=0.6,
|
||
|
|
orientation=SliderOrientation.HORIZONTAL,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
self.assertEqual(query, "后背门最大开度滑块")
|
||
|
|
|
||
|
|
def test_segmented_option_query(self) -> None:
|
||
|
|
query = self.builder.build_action_target(
|
||
|
|
ActionPlan(
|
||
|
|
interaction=Interaction.TAP,
|
||
|
|
function="unlock_mode",
|
||
|
|
option="all_doors",
|
||
|
|
)
|
||
|
|
)
|
||
|
|
self.assertEqual(query, "所有车门解锁选项")
|
||
|
|
|
||
|
|
def test_noop_has_no_grounding_query(self) -> None:
|
||
|
|
with self.assertRaisesRegex(ValueError, "noop"):
|
||
|
|
self.builder.build_action_target(
|
||
|
|
ActionPlan(
|
||
|
|
interaction=Interaction.NOOP,
|
||
|
|
reason="already_in_target_state",
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_function_targets_are_semantic_regions(self) -> None:
|
||
|
|
temperature = SemanticAction(
|
||
|
|
domain=Domain.CLIMATE,
|
||
|
|
function="temperature",
|
||
|
|
zone=Zone.DRIVER,
|
||
|
|
operation=Operation.SET,
|
||
|
|
state=None,
|
||
|
|
value=23,
|
||
|
|
unit=Unit.CELSIUS,
|
||
|
|
)
|
||
|
|
recirculation = SemanticAction(
|
||
|
|
domain=Domain.CLIMATE,
|
||
|
|
function="air_recirculation",
|
||
|
|
zone=Zone.ALL,
|
||
|
|
operation=Operation.SET,
|
||
|
|
state=State.ON,
|
||
|
|
value=None,
|
||
|
|
unit=None,
|
||
|
|
)
|
||
|
|
self.assertEqual(
|
||
|
|
self.builder.build_function_target(temperature),
|
||
|
|
(
|
||
|
|
"主驾驶温度调节控件整体,"
|
||
|
|
"包含当前温度显示以及用于升高和降低温度的控制元素"
|
||
|
|
),
|
||
|
|
)
|
||
|
|
self.assertEqual(
|
||
|
|
self.builder.build_function_target(recirculation),
|
||
|
|
"车辆空调内循环控制",
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_function_targets_describe_complete_control_structure(self) -> None:
|
||
|
|
intents = (
|
||
|
|
SemanticAction(
|
||
|
|
domain=Domain.BODY,
|
||
|
|
function="tailgate_max_opening",
|
||
|
|
zone=None,
|
||
|
|
operation=Operation.SET,
|
||
|
|
state=None,
|
||
|
|
value=80,
|
||
|
|
unit=Unit.PERCENT,
|
||
|
|
),
|
||
|
|
SemanticAction(
|
||
|
|
domain=Domain.BODY,
|
||
|
|
function="unlock_mode",
|
||
|
|
zone=None,
|
||
|
|
operation=Operation.SET,
|
||
|
|
state=None,
|
||
|
|
value="all_doors",
|
||
|
|
unit=None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
targets = tuple(
|
||
|
|
self.builder.build_function_target(intent) for intent in intents
|
||
|
|
)
|
||
|
|
self.assertIn("滑轨", targets[0])
|
||
|
|
self.assertIn("滑块", targets[0])
|
||
|
|
self.assertIn("控件整体", targets[1])
|
||
|
|
self.assertIn("所有可选择的解锁方式选项", targets[1])
|
||
|
|
|
||
|
|
forbidden = (
|
||
|
|
"AUTO",
|
||
|
|
"风扇",
|
||
|
|
"蓝色",
|
||
|
|
"橙色",
|
||
|
|
"左边",
|
||
|
|
"右边",
|
||
|
|
"固定像素",
|
||
|
|
)
|
||
|
|
for target in targets:
|
||
|
|
for term in forbidden:
|
||
|
|
with self.subTest(target=target, term=term):
|
||
|
|
self.assertNotIn(term, target)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|