Skip to content

Commit 39e2f8b

Browse files
committed
Add Smart Incident Categorizer AI to automate incident categorization
1 parent 56653db commit 39e2f8b

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Smart Incident Categorizer using AI
2+
3+
## Description
4+
Automatically categorizes incidents using OpenAI GPT-3.5 based on description content.
5+
6+
## Use Case
7+
- Auto-assigns category when incidents are created without category
8+
- Reduces manual categorization effort
9+
- Improves consistency in incident classification
10+
11+
## Setup
12+
1. Create system property: `openai.api.key` with your OpenAI API key
13+
2. Create Business Rule on `incident` table
14+
3. Set to run `before insert` when category is empty
15+
16+
## Categories
17+
Returns one of: network, hardware, software, database, security, email
18+
19+
## Testing
20+
Create incident without category - verify auto-assignment in work notes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Business Rule: Smart Incident Categorizer AI
2+
// Table: incident
3+
// When: before, insert
4+
// Filter Conditions: Category is empty
5+
6+
(function executeRule(current, previous) {
7+
if (current.isNewRecord() && !current.category) {
8+
var categorizer = new SmartIncidentCategorizer();
9+
var suggestedCategory = categorizer.categorizeIncident(current.short_description + ' ' + current.description);
10+
11+
if (suggestedCategory) {
12+
current.category = suggestedCategory;
13+
current.work_notes = 'Category auto-assigned by AI: ' + suggestedCategory;
14+
}
15+
}
16+
})(current, previous);
17+
18+
var SmartIncidentCategorizer = Class.create();
19+
SmartIncidentCategorizer.prototype = {
20+
categorizeIncident: function(description) {
21+
try {
22+
var openai = new sn_ws.RESTMessageV2();
23+
openai.setHttpMethod('POST');
24+
openai.setEndpoint('https://api.openai.com/v1/chat/completions');
25+
openai.setRequestHeader('Authorization', 'Bearer ' + gs.getProperty('openai.api.key'));
26+
openai.setRequestHeader('Content-Type', 'application/json');
27+
28+
var payload = {
29+
model: "gpt-3.5-turbo",
30+
messages: [{
31+
role: "system",
32+
content: "You are an IT service desk categorizer. Return only one of these categories: network, hardware, software, database, security, email"
33+
}, {
34+
role: "user",
35+
content: "Categorize this incident: " + description
36+
}],
37+
max_tokens: 10,
38+
temperature: 0.1
39+
};
40+
41+
openai.setRequestBody(JSON.stringify(payload));
42+
var response = openai.execute();
43+
44+
if (response.getStatusCode() == 200) {
45+
var result = JSON.parse(response.getBody());
46+
return result.choices[0].message.content.trim().toLowerCase();
47+
}
48+
} catch (e) {
49+
gs.error('AI Categorizer Error: ' + e.message);
50+
}
51+
return null;
52+
}
53+
};

0 commit comments

Comments
 (0)