|
8 | 8 | AIInvestigateParams, |
9 | 9 | ChartValuesFormat, |
10 | 10 | HolmesChatParams, |
11 | | - HolmesChatSource, |
12 | 11 | HolmesConversationParams, |
13 | 12 | HolmesIssueChatParams, |
14 | 13 | HolmesWorkloadHealthChatParams, |
@@ -355,29 +354,34 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams): |
355 | 354 | result.raise_for_status() |
356 | 355 | holmes_result = HolmesChatResult(**json.loads(result.text)) |
357 | 356 | holmes_result.files = [] |
358 | | - if params.source == HolmesChatSource.RELAY: |
359 | | - for tool in holmes_result.tool_calls: |
360 | | - if tool.tool_name != "execute_prometheus_range_query": |
361 | | - continue |
362 | | - try: |
| 357 | + if params.render_graph_images: |
| 358 | + try: |
| 359 | + for tool in holmes_result.tool_calls: |
| 360 | + if tool.tool_name != "execute_prometheus_range_query": |
| 361 | + continue |
| 362 | + |
363 | 363 | json_content = json.loads(tool.result) |
364 | 364 | query_result = PrometheusQueryResult(data=json_content.get("data", {})) |
365 | 365 | try: |
366 | 366 | output_type_str = json_content.get("output_type", "Plain") |
367 | 367 | output_type = ChartValuesFormat[output_type_str] |
368 | 368 | except KeyError: |
369 | 369 | output_type = ChartValuesFormat.Plain # fallback in case of an invalid string |
| 370 | + |
370 | 371 | chart = build_chart_from_prometheus_result( |
371 | 372 | query_result, json_content.get("description", "graph"), values_format=output_type |
372 | 373 | ) |
373 | 374 | contents = convert_svg_to_png(chart.render()) |
374 | 375 | name = json_content.get("description", "graph").replace(" ", "_") |
375 | 376 | holmes_result.files.append(FileBlock(f"{name}.png", contents)) |
376 | | - except Exception as e: |
377 | | - logging.exception(f"Failed to parse JSON: {e}\nRaw content:\n{tool.result}") |
378 | | - holmes_result.tool_calls = [ |
379 | | - tool for tool in holmes_result.tool_calls if tool.tool_name != "execute_prometheus_range_query" |
380 | | - ] |
| 377 | + |
| 378 | + holmes_result.tool_calls = [ |
| 379 | + tool for tool in holmes_result.tool_calls if tool.tool_name != "execute_prometheus_range_query" |
| 380 | + ] |
| 381 | + |
| 382 | + except Exception: |
| 383 | + logging.exception(f"Failed to convert tools to images") |
| 384 | + |
381 | 385 | finding = Finding( |
382 | 386 | title="AI Ask Chat", |
383 | 387 | aggregation_key="HolmesChatResult", |
|
0 commit comments