AI models
This commit is contained in:
@@ -31,6 +31,7 @@ scripts = {
|
||||
"url.sieve",
|
||||
"rbl.sieve",
|
||||
"pyzor.sieve",
|
||||
"llm.sieve",
|
||||
"composites.sieve",
|
||||
"scores.sieve",
|
||||
"reputation.sieve",
|
||||
@@ -80,7 +81,7 @@ def read_file(file):
|
||||
return f.read() + "\n"
|
||||
|
||||
def build_spam_filters(scripts):
|
||||
spam_filter = "[version]\nspam-filter = \"1.1\"\n\n"
|
||||
spam_filter = "[version]\nspam-filter = \"1.2\"\n\n"
|
||||
for script_name, file_list in scripts.items():
|
||||
script_content = read_and_concatenate(file_list).replace("'''", "\\'\\'\\'")
|
||||
script_description = script_names[script_name]
|
||||
|
||||
@@ -361,4 +361,16 @@ spam-scores = {"ABUSE_SURBL" = "5.0",
|
||||
"SHORT_PART_BAD_HEADERS" = "7.0",
|
||||
"MISSING_ESSENTIAL_HEADERS" = "7.0",
|
||||
"SINGLE_SHORT_PART" = "0.0",
|
||||
"COMPLETELY_EMPTY" = "7.0"}
|
||||
"COMPLETELY_EMPTY" = "7.0",
|
||||
"LLM_UNSOLICITED_HIGH" = "3.0",
|
||||
"LLM_UNSOLICITED_MEDIUM" = "2.0",
|
||||
"LLM_UNSOLICITED_LOW" = "0.5",
|
||||
"LLM_COMMERCIAL_HIGH" = "3.0",
|
||||
"LLM_COMMERCIAL_MEDIUM" = "2.0",
|
||||
"LLM_COMMERCIAL_LOW" = "0.5",
|
||||
"LLM_HARMFUL_HIGH" = "3.0",
|
||||
"LLM_HARMFUL_MEDIUM" = "2.0",
|
||||
"LLM_HARMFUL_LOW" = "0.5",
|
||||
"LLM_LEGITIMATE_HIGH" = "-3.0",
|
||||
"LLM_LEGITIMATE_MEDIUM" = "-2.0",
|
||||
"LLM_LEGITIMATE_LOW" = "-0.5"}
|
||||
|
||||
@@ -10,5 +10,30 @@ spam-config = {
|
||||
"threshold-discard" = "0.0",
|
||||
"threshold-reject" = "0.0",
|
||||
"directory" = "",
|
||||
"lookup" = ""
|
||||
"lookup" = "",
|
||||
"llm-model" = "",
|
||||
"llm-prompt" = "You are an AI assistant specialized in analyzing email content to detect unsolicited, commercial, or harmful messages. Your task is to examine the provided email, including its subject line, and determine if it falls into any of these categories. Please follow these steps:
|
||||
|
||||
- Carefully read the entire email content, including the subject line.
|
||||
- Look for indicators of unsolicited messages, such as:
|
||||
* Lack of prior relationship or consent
|
||||
* Mass-mailing characteristics
|
||||
* Vague or misleading sender information
|
||||
- Identify commercial content by checking for:
|
||||
* Promotional language
|
||||
* Product or service offerings
|
||||
* Call-to-action for purchases
|
||||
- Detect potentially harmful content by searching for:
|
||||
* Phishing attempts (requests for personal information, suspicious links)
|
||||
* Malware indicators (suspicious attachments, urgent calls to action)
|
||||
* Scams or fraudulent schemes
|
||||
- Analyze the overall tone, intent, and legitimacy of the email.
|
||||
- Determine the most appropriate single category for the email: Unsolicited, Commercial, Harmful, or Legitimate.
|
||||
- Assess your confidence level in this determination: High, Medium, or Low.
|
||||
- Provide a brief explanation for your determination.
|
||||
- Format your response as follows, separated by commas: Category,Confidence,Explanation
|
||||
* Example: Unsolicited,High,The email contains mass-mailing characteristics without any prior relationship context.
|
||||
|
||||
Here's the email to analyze, please provide your analysis based on the above instructions, ensuring your response is in the specified comma-separated format:",
|
||||
"add-llm-result" = true
|
||||
}
|
||||
|
||||
@@ -33,3 +33,12 @@ let "DOMAIN_DIRECTORY" "key_get('spam-config', 'directory')";
|
||||
|
||||
# Store to use for Bayes tokens and ids (leave empty for default)
|
||||
let "SPAM_DB" "key_get('spam-config', 'lookup')";
|
||||
|
||||
# LLM model to use for spam classification
|
||||
let "LLM_MODEL" "key_get('spam-config', 'llm-model')";
|
||||
|
||||
# LLM prompt to use for spam classification
|
||||
let "LLM_PROMPT_TEXT" "key_get('spam-config', 'llm-prompt')";
|
||||
|
||||
# Whether to add an X-Spam-Llm-Result header
|
||||
let "ADD_HEADER_LLM" "key_get('spam-config', 'add-llm-result')";
|
||||
|
||||
41
resources/config/spamfilter/scripts/llm.sieve
Normal file
41
resources/config/spamfilter/scripts/llm.sieve
Normal file
@@ -0,0 +1,41 @@
|
||||
if eval "LLM_MODEL && LLM_PROMPT_TEXT" {
|
||||
let "llm_result" "trim(split_n(llm_prompt(LLM_MODEL, LLM_PROMPT_TEXT + '\n\nSubject: ' + subject_clean + '\n\n' + text_body), ',', 3))";
|
||||
|
||||
if eval "eq_ignore_case(llm_result[0], 'Unsolicited')" {
|
||||
if eval "eq_ignore_case(llm_result[1], 'High')" {
|
||||
let "t.LLM_UNSOLICITED_HIGH" "1";
|
||||
} elsif eval "eq_ignore_case(llm_result[1], 'Medium')" {
|
||||
let "t.LLM_UNSOLICITED_MEDIUM" "1";
|
||||
} else {
|
||||
let "t.LLM_UNSOLICITED_LOW" "1";
|
||||
}
|
||||
} elsif eval "eq_ignore_case(llm_result[0], 'Commercial')" {
|
||||
if eval "eq_ignore_case(llm_result[1], 'High')" {
|
||||
let "t.LLM_COMMERCIAL_HIGH" "1";
|
||||
} elsif eval "eq_ignore_case(llm_result[1], 'Medium')" {
|
||||
let "t.LLM_COMMERCIAL_MEDIUM" "1";
|
||||
} else {
|
||||
let "t.LLM_COMMERCIAL_LOW" "1";
|
||||
}
|
||||
} elsif eval "eq_ignore_case(llm_result[0], 'Harmful')" {
|
||||
if eval "eq_ignore_case(llm_result[1], 'High')" {
|
||||
let "t.LLM_HARMFUL_HIGH" "1";
|
||||
} elsif eval "eq_ignore_case(llm_result[1], 'Medium')" {
|
||||
let "t.LLM_HARMFUL_MEDIUM" "1";
|
||||
} else {
|
||||
let "t.LLM_HARMFUL_LOW" "1";
|
||||
}
|
||||
} elsif eval "eq_ignore_case(llm_result[0], 'Legitimate')" {
|
||||
if eval "eq_ignore_case(llm_result[1], 'High')" {
|
||||
let "t.LLM_LEGITIMATE_HIGH" "1";
|
||||
} elsif eval "eq_ignore_case(llm_result[1], 'Medium')" {
|
||||
let "t.LLM_LEGITIMATE_MEDIUM" "1";
|
||||
} else {
|
||||
let "t.LLM_LEGITIMATE_LOW" "1";
|
||||
}
|
||||
}
|
||||
|
||||
if eval "ADD_HEADER_LLM && count(llm_result) > 2" {
|
||||
eval "add_header('X-Spam-Llm-Result', 'Category=' + llm_result[0] + '; Confidence=' + llm_result[1] + '; Explanation=' + llm_result[2])";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user