Skip to content

Commit

Permalink
Reduce llm context input size by taking topN active alerts
Browse files Browse the repository at this point in the history
Signed-off-by: Songkan Tang <[email protected]>
  • Loading branch information
songkant-aws committed Sep 6, 2024
1 parent 1c502e0 commit 40da2ca
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions public/pages/Dashboard/utils/tableUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const alertColumns = (
dsl = JSON.stringify({ query: search.query.query });
if (query.indexOf('{{period_end}}') !== -1) {
query = query.replaceAll('{{period_end}}', alert.start_time);
const alertStartTime = moment.utc(alert.start_time).format('YYYY-MM-DD HH:mm:ss');
const alertStartTime = moment.utc(alert.start_time).format('YYYY-MM-DDTHH:mm:ss');
dsl = dsl.replaceAll('{{period_end}}', alertStartTime);
// as we changed the format, remove it
dsl = dsl.replaceAll('"format":"epoch_millis",', '');
Expand Down Expand Up @@ -213,12 +213,18 @@ export const alertColumns = (
}
}

const filteredAlert = { ...alert };
const topN = 10;
const activeAlerts = alert.alerts.filter((alert) => alert.state === 'ACTIVE');
// Reduce llm input token size by taking topN active alerts
filteredAlert.alerts = activeAlerts.slice(0, topN);

// 3. build the context
return {
context: `
Here is the detail information about alert ${alert.trigger_name}
### Monitor definition\n ${monitorDefinitionStr}\n
### Active Alert\n ${JSON.stringify(alert)}\n
### Active Alert\n ${JSON.stringify(filteredAlert)}\n
### Data triggers this alert\n ${alertTriggeredByData}\n
### Alert query DSL ${dsl} \n`,
additionalInfo: {
Expand Down

0 comments on commit 40da2ca

Please sign in to comment.