Skip to content

Commit bf0d59f

Browse files
committed
param updates + safer code
1 parent 2a714ed commit bf0d59f

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,
@@ -355,29 +354,34 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams):
355354
result.raise_for_status()
356355
holmes_result = HolmesChatResult(**json.loads(result.text))
357356
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+
363363
json_content = json.loads(tool.result)
364364
query_result = PrometheusQueryResult(data=json_content.get("data", {}))
365365
try:
366366
output_type_str = json_content.get("output_type", "Plain")
367367
output_type = ChartValuesFormat[output_type_str]
368368
except KeyError:
369369
output_type = ChartValuesFormat.Plain # fallback in case of an invalid string
370+
370371
chart = build_chart_from_prometheus_result(
371372
query_result, json_content.get("description", "graph"), values_format=output_type
372373
)
373374
contents = convert_svg_to_png(chart.render())
374375
name = json_content.get("description", "graph").replace(" ", "_")
375376
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+
381385
finding = Finding(
382386
title="AI Ask Chat",
383387
aggregation_key="HolmesChatResult",

0 commit comments

Comments
 (0)