Skip to content

Commit b3da5ba

Browse files
committed
param updates + safer code
1 parent 69ad4fd commit b3da5ba

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/robusta/core/model/base_params.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,14 @@ class ConversationType(str, Enum):
182182
ISSUE = "issue"
183183

184184

185-
class HolmesChatSource(str, Enum):
186-
"""
187-
Conversation types for holmes_conversation action
188-
"""
189-
190-
UI = "ui"
191-
RELAY = "relay"
192-
193-
194185
class HolmesChatParams(HolmesParams):
195186
"""
196187
:var ask: User's prompt for holmes
197188
"""
198189

199190
ask: str
200191
conversation_history: Optional[list[dict]] = None
201-
source: HolmesChatSource = HolmesChatSource.UI
192+
render_graph_images: bool = False
202193

203194

204195
class HolmesIssueChatParams(HolmesChatParams):

src/robusta/core/playbooks/internal/ai_integration.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
AIInvestigateParams,
99
ChartValuesFormat,
1010
HolmesChatParams,
11-
HolmesChatSource,
1211
HolmesConversationParams,
1312
HolmesIssueChatParams,
1413
HolmesWorkloadHealthChatParams,
@@ -357,29 +356,34 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams):
357356
result.raise_for_status()
358357
holmes_result = HolmesChatResult(**json.loads(result.text))
359358
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+
365365
json_content = json.loads(tool.result)
366366
query_result = PrometheusQueryResult(data=json_content.get("data", {}))
367367
try:
368368
output_type_str = json_content.get("output_type", "Plain")
369369
output_type = ChartValuesFormat[output_type_str]
370370
except KeyError:
371371
output_type = ChartValuesFormat.Plain # fallback in case of an invalid string
372+
372373
chart = build_chart_from_prometheus_result(
373374
query_result, json_content.get("description", "graph"), values_format=output_type
374375
)
375376
contents = convert_svg_to_png(chart.render())
376377
name = json_content.get("description", "graph").replace(" ", "_")
377378
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+
383387
finding = Finding(
384388
title="AI Ask Chat",
385389
aggregation_key="HolmesChatResult",

0 commit comments

Comments
 (0)