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