| """ |
| 文本上下文构造器 |
| """ |
|
|
| 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 |
| """ |
| |
| |
| 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." |
| |
| |
| if use_belief_token: |
| text += " <BELIEF>" |
| |
| return text |