From 4598c9dc0ff0810dfe56e9f0126e53b5e3efefde Mon Sep 17 00:00:00 2001 From: Matvey Kukuy Date: Tue, 12 Nov 2024 17:58:29 +0200 Subject: [PATCH] Leftovers for AI --- keep-ui/app/ai/ai.tsx | 20 +++++++++++++++----- keep-ui/components/navbar/AILink.tsx | 2 +- keep/api/bl/incidents_bl.py | 4 ++-- keep/api/models/db/ai_external.py | 7 ++++--- keep/api/routes/incidents.py | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/keep-ui/app/ai/ai.tsx b/keep-ui/app/ai/ai.tsx index 2cf17ce85..cbb39a5d2 100644 --- a/keep-ui/app/ai/ai.tsx +++ b/keep-ui/app/ai/ai.tsx @@ -9,22 +9,32 @@ export default function Ai() { const { data: aistats, isLoading, refetch: refetchAIStats } = useAIStats(); const { updateAISettings } = UseAIActions(); + useEffect(() => { + const interval = setInterval(() => { + refetchAIStats(); + }, 5000); + + return () => clearInterval(interval); + }, [refetchAIStats]); + return (
- AI Correlation + Pluggable AI - Correlating alerts to incidents based on past alerts, incidents, and - the other data. + External AI engines can be plugged in and configured here.
-
- {isLoading ?

Loading algorithms and settings...

: null} +
+ {isLoading ?

Loading algorithms and their settings...

: null} + {aistats?.algorithm_configs?.length === 0 && ( +

No AI plugged in yet. Please reach out to us!

+ )} {aistats?.algorithm_configs?.map((algorithm_config, index) => ( { const [text, setText] = useState(""); - const [newText, setNewText] = useState("AI correlation"); + const [newText, setNewText] = useState("Pluggable AI"); const mutateAILogs = (logs: any) => { setNewText("AI iterated 🎉") diff --git a/keep/api/bl/incidents_bl.py b/keep/api/bl/incidents_bl.py index f2fe58908..1bbaa37dd 100644 --- a/keep/api/bl/incidents_bl.py +++ b/keep/api/bl/incidents_bl.py @@ -80,7 +80,7 @@ def create_incident(self, incident_dto: IncidentDtoIn) -> IncidentDto: return new_incident_dto async def add_alerts_to_incident( - self, incident_id: UUID, alert_ids: List[UUID] + self, incident_id: UUID, alert_ids: List[UUID], is_created_by_ai: bool = False ) -> None: self.logger.info( "Adding alerts to incident", @@ -90,7 +90,7 @@ async def add_alerts_to_incident( if not incident: raise HTTPException(status_code=404, detail="Incident not found") - add_alerts_to_incident_by_incident_id(self.tenant_id, incident_id, alert_ids) + add_alerts_to_incident_by_incident_id(self.tenant_id, incident_id, alert_ids, is_created_by_ai) self.logger.info( "Alerts added to incident", extra={"incident_id": incident_id, "alert_ids": alert_ids}, diff --git a/keep/api/models/db/ai_external.py b/keep/api/models/db/ai_external.py index 1acbdac13..b7fea884e 100644 --- a/keep/api/models/db/ai_external.py +++ b/keep/api/models/db/ai_external.py @@ -51,9 +51,10 @@ def unique_id(self): api_url=os.environ.get("AI_TRANSFORMERS_API_HOST", None), config_default=json.dumps( [ - {"min": 0.3, "max": 0.99, "value": 0.8, "type": "float", "name": "Correlation Threshold", "description": "The minimum correlation value to consider two alerts belonging to an ancident."}, - {"min": 0.3, "max": 0.99, "value": 0.8, "type": "float", "name": "Model Accuracy Threshold", "description": "The trained model accuracy will be evaluated using cross-validation. If the accuracy is below this threshold, the model will be retrained."}, - {"min": 2, "max": 20, "value": 10, "type": "int", "name": "Train Epochs", "description": "The amount of epochs to train the model for. The less the better to avoid over-fitting."}, + {"min": 0.3, "max": 0.99, "value": 0.9, "type": "float", "name": "Model Accuracy Threshold", "description": "The trained model accuracy will be evaluated using 30 percent of alerts-to-incident correlations as a validation dataset. If the accuracy is below this threshold, the correlation won't be launched."}, + {"min": 0.3, "max": 0.99, "value": 0.9, "type": "float", "name": "Correlation Threshold", "description": "The minimum correlation value to consider two alerts belonging to an ancident."}, + {"min": 1, "max": 20, "value": 1, "type": "int", "name": "Train Epochs", "description": "The amount of epochs to train the model for. The less the better to avoid over-fitting."}, + {"value": True, "type": "bool", "name": "Create New Incidents", "description": "Do you want AI to issue new incident if correlation is detected and the icnident alerts are related to is resolved?"}, {"value": True, "type": "bool", "name": "Enabled", "description": "Enable or disable the algorithm."}, ] ) diff --git a/keep/api/routes/incidents.py b/keep/api/routes/incidents.py index 0622f8ced..485450e69 100644 --- a/keep/api/routes/incidents.py +++ b/keep/api/routes/incidents.py @@ -446,7 +446,7 @@ async def add_alerts_to_incident( ): tenant_id = authenticated_entity.tenant_id incident_bl = IncidentBl(tenant_id, session, pusher_client) - await incident_bl.add_alerts_to_incident(incident_id, alert_ids) + await incident_bl.add_alerts_to_incident(incident_id, alert_ids, is_created_by_ai) return Response(status_code=202)