-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassify.py
More file actions
51 lines (38 loc) · 1.54 KB
/
classify.py
File metadata and controls
51 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from regex_processor import classify_with_regex
from bert_processor import classify_with_bert
from llm_processor import classify_with_llm
def classify(logs):
# process a list of logs and return their labels
labels = []
for source, log_msg in logs:
label = classify_log(source, log_msg)
labels.append(label)
return labels
def classify_log(source, log_msg):
# check source to determine which model to use
if source == "LegacyCRM":
# legacy systems use the high-reasoning llm
label = classify_with_llm(log_msg)
else:
# standard systems try regex first for speed
label = classify_with_regex(log_msg)
# fallback to bert if regex finds no match
if not label:
label = classify_with_bert(log_msg)
return label
# --- api helper functions ---
def process_single_log(source, message):
# entry point for a single api request
return classify_log(source, message)
def process_batch_logs(log_data_list):
# entry point for bulk api requests
# expects a list of dictionaries: [{"source": "...", "message": "..."}, ...]
logs = [(item['source'], item['message']) for item in log_data_list]
return classify(logs)
# --- developer testing area ---
if __name__ == '__main__':
# future developers can uncomment the lines below to test logic without an api call
# test_data = [("ModernCRM", "unauthorized access attempt"), ("LegacyCRM", "retired module warning")]
# results = classify(test_data)
# print(f"test results: {results}")
pass