Create HTML visualization of a trajectory.
(trajectory: Dict[str, Any], filepath: str)
| 139 | |
| 140 | |
| 141 | def _create_html_visualization(trajectory: Dict[str, Any], filepath: str) -> None: |
| 142 | """Create HTML visualization of a trajectory.""" |
| 143 | html = """ |
| 144 | <!DOCTYPE html> |
| 145 | <html> |
| 146 | <head> |
| 147 | <title>Agent Trajectory Visualization</title> |
| 148 | <style> |
| 149 | body { font-family: Arial, sans-serif; margin: 20px; } |
| 150 | .step { margin-bottom: 20px; border: 1px solid #ddd; padding: 15px; border-radius: 5px; } |
| 151 | .response { white-space: pre-wrap; background: #f5f5f5; padding: 10px; border-radius: 3px; } |
| 152 | .parsed { margin-top: 10px; color: #555; } |
| 153 | .thought { color: #0066cc; } |
| 154 | .action { color: #cc6600; } |
| 155 | .observation { color: #006600; } |
| 156 | img { max-width: 100%; max-height: 300px; margin-top: 10px; } |
| 157 | </style> |
| 158 | </head> |
| 159 | <body> |
| 160 | <h1>Agent Trajectory Visualization</h1> |
| 161 | """ |
| 162 | |
| 163 | # Process each step |
| 164 | steps = len(trajectory.get("answer", [])) |
| 165 | for i in range(steps): |
| 166 | html += f'<div class="step"><h3>Step {i+1}</h3>' |
| 167 | |
| 168 | # Add agent response |
| 169 | if "answer" in trajectory and i < len(trajectory["answer"]): |
| 170 | html += f'<div class="response">{trajectory["answer"][i]}</div>' |
| 171 | |
| 172 | # Add parsed components |
| 173 | if "parsed_response" in trajectory and i < len(trajectory["parsed_response"]): |
| 174 | parsed = trajectory["parsed_response"][i] |
| 175 | html += '<div class="parsed">' |
| 176 | |
| 177 | if "thought" in parsed and parsed["thought"]: |
| 178 | html += f'<div class="thought"><strong>Thought:</strong> {parsed["thought"]}</div>' |
| 179 | |
| 180 | if "action" in parsed and parsed["action"]: |
| 181 | html += f'<div class="action"><strong>Action:</strong> {parsed["action"]}</div>' |
| 182 | |
| 183 | if "observation" in parsed and parsed["observation"]: |
| 184 | html += f'<div class="observation"><strong>Observation:</strong> {parsed["observation"]}</div>' |
| 185 | |
| 186 | html += '</div>' |
| 187 | |
| 188 | # Add state image if available |
| 189 | if "state" in trajectory and isinstance(trajectory["state"], list) and i < len(trajectory["state"]): |
| 190 | html += f'<div><img src="{os.path.basename(filepath)}_states/state_{i:03d}.png" alt="State {i}"></div>' |
| 191 | |
| 192 | html += '</div>' |
| 193 | |
| 194 | html += """ |
| 195 | </body> |
| 196 | </html> |
| 197 | """ |
| 198 |
no test coverage detected