Skip to content

Commit

Permalink
Leftovers for AI
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk committed Nov 12, 2024
1 parent 176706a commit 4598c9d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
20 changes: 15 additions & 5 deletions keep-ui/app/ai/ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<main className="p-4 md:p-10 mx-auto max-w-full">
<div className="flex justify-between items-center">
<div>
<Title>AI Correlation</Title>
<Title>Pluggable AI</Title>
<Subtitle>
Correlating alerts to incidents based on past alerts, incidents, and
the other data.
External AI engines can be plugged in and configured here.
</Subtitle>
</div>
</div>
<Card className="mt-10 p-4 md:p-10 mx-auto">
<div>
<div>
<div className="grid grid-cols-1 gap-4 mt-6">
{isLoading ? <p>Loading algorithms and settings...</p> : null}
<div className="grid grid-cols-1 gap-4">
{isLoading ? <p>Loading algorithms and their settings...</p> : null}
{aistats?.algorithm_configs?.length === 0 && (
<p>No AI plugged in yet. Please reach out to us!</p>
)}
{aistats?.algorithm_configs?.map((algorithm_config, index) => (
<Card
key={index}
Expand Down
2 changes: 1 addition & 1 deletion keep-ui/components/navbar/AILink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { usePollAILogs } from "utils/hooks/useAI";

export const AILink = () => {
const [text, setText] = useState("");
const [newText, setNewText] = useState("AI correlation");
const [newText, setNewText] = useState("Pluggable AI");

const mutateAILogs = (logs: any) => {
setNewText("AI iterated 🎉")
Expand Down
4 changes: 2 additions & 2 deletions keep/api/bl/incidents_bl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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},
Expand Down
7 changes: 4 additions & 3 deletions keep/api/models/db/ai_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
]
)
Expand Down
2 changes: 1 addition & 1 deletion keep/api/routes/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 4598c9d

Please sign in to comment.