File size: 1,546 Bytes
1e05592 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """
文本上下文构造器
"""
def build_context_text(openpilot_data, prev_action=None, prev_tta=None,
is_extended=False, use_belief_token=False):
"""
构造VLM的文本上下文
Args:
...
use_belief_token: bool - 是否在末尾添加<BELIEF> token
"""
action_names = ["silent", "observe", "alert"]
# 基础车辆状态
text = f"""Vehicle State:
- Speed: {openpilot_data.get('speed', 0):.1f} km/h
- ACC: {'ON' if openpilot_data.get('acc', False) else 'OFF'}
- LKA: {'ON' if openpilot_data.get('lka', False) else 'OFF'}
- Lane confidence: L={openpilot_data.get('lane_left_prob', 0.5):.2f}, R={openpilot_data.get('lane_right_prob', 0.5):.2f}
- Path plan confidence: {openpilot_data.get('path_confidence', 0.5):.2f}
- Lateral offset: {openpilot_data.get('lateral_offset', 0.0):.2f}m
Environment:
- Weather: {openpilot_data.get('weather', 'unknown')}
- Time: {openpilot_data.get('time_of_day', 'unknown')}
"""
# 历史信息
if prev_action is not None and prev_tta is not None:
text += f"""
Previous State:
- Action taken: {action_names[prev_action]}
- TTA estimate: {prev_tta:.2f}s
"""
# OBSERVE提示
if is_extended:
text += "\n[Note: Extended temporal window (3s) with focused spatial attention]"
# 任务描述
text += "\n\nTask: Estimate time-to-accident (TTA) from multimodal observations."
# BELIEF token(如果启用)
if use_belief_token:
text += " <BELIEF>"
return text |