@@ -157,9 +157,8 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
157157 )
158158 df_metric ["metric_timestamp" ] = pd .to_datetime (df_metric ["metric_timestamp" ], format = "%Y-%m-%d %H:%M:%S" )
159159
160- # if there are detected anomalies set metric_alert to 1 if it is not already 1
161- if not df_metric ["metric_alert" ].any ():
162- df_metric ["metric_alert" ] = df_metric ["anomaly_timestamp" ].notnull ().astype (int )
160+ # if there are detected anomalies set metric_alert to 1
161+ df_metric ["metric_alert" ] = df_metric ["anomaly_timestamp" ].notnull ().astype (int )
163162
164163 num_anomalies_recent = df_metric ["metric_alert" ].tail (llmalert_recent_n ).sum ()
165164
@@ -175,9 +174,10 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
175174 anomaly_explanations = df_metric [
176175 df_metric ["anomaly_timestamp" ].notnull ()
177176 ][["anomaly_timestamp" , "anomaly_explanation" ]].apply (
178- lambda x : f"{ x [0 ]} : { x [1 ]} " , axis = 1
179- ).tail (llmalert_recent_n ).sort_values (ascending = False )
180- anomaly_explanations = "\n - " .join (anomaly_explanations )
177+ lambda x : f"- { x [0 ]} : { x [1 ]} " , axis = 1
178+ ).sort_values (ascending = False )
179+ anomaly_explanations = anomaly_explanations .head (llmalert_recent_n )
180+ anomaly_explanations = "\n " .join (anomaly_explanations )
181181 metric_timestamp_max = df_metric ["metric_timestamp" ].max ()
182182 alert_title = (
183183 f"🤖 LLM says [{ metric_name } ] looks anomalous "
0 commit comments