aboutsummaryrefslogtreecommitdiff
path: root/blog/context_processors.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-06-06 18:41:41 +0000
committerBobby <[email protected]>2024-06-06 18:41:41 +0000
commit4d1e96e6ab4d2bf42a32e07d6f3e0a2e6e2bc90b (patch)
treee800a85189198427fb88aeb9172c52b76f3f1f08 /blog/context_processors.py
parentd1fb79f5a78debea12f16ac6f217b978fea99832 (diff)
downloadthatcomputerscientist-4d1e96e6ab4d2bf42a32e07d6f3e0a2e6e2bc90b.tar.xz
thatcomputerscientist-4d1e96e6ab4d2bf42a32e07d6f3e0a2e6e2bc90b.zip
Better Spam Filtering + Anonymous Spam Fix
Diffstat (limited to 'blog/context_processors.py')
-rw-r--r--blog/context_processors.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/blog/context_processors.py b/blog/context_processors.py
index 6036ee86..fe2b79aa 100644
--- a/blog/context_processors.py
+++ b/blog/context_processors.py
@@ -50,9 +50,32 @@ def check_spam(comment, post):
model = genai.GenerativeModel("gemini-pro")
print(comment)
- input_prompt = f"Comment Processing Checker. This is for a personal blog site. Output only Y or N for the included text. Y if the comment seems like spam, unrelated to post or random gibberish or a bunch of letters which make no sense or looks like a coupon code or something. N if the comment seems safe. Do not access links. Just mark Y or N for the text. Post Title: {post.title}. \n Post Body: {post.body}. \n Comment: {comment}. \n Judge if the comment belongs on the post or not. Random texts, links, and gibberish are considered spam. Trying to phish or promote shady links are also considered spam. Please mark Y if the comment seems like spam. N if the comment seems safe. Only output a single character. Y or N."
+ input_prompt = f"Comment Processing Checker. This is for a personal blog site. Output only Y or N for the included text. Y if the comment seems like spam, or random gibberish or a bunch of letters which make no sense or looks like a coupon code or something. Only block spam, nothing else. If a comment contains cuss words, personal attacks, profanity or any possible harrasment, it is NOT spam (unless it contains spammy gibberish or links). This is a strict spam only filter. N if the comment is not spam. Do not access links. Just mark Y or N for the text. Post Title: {post.title}. \n Comment: {comment}. \n Judge if the comment belongs on the post or not. Random texts, links, and gibberish are considered spam. Trying to phish or promote shady links are also considered spam. Output single character - either Y or N only."
+
+ bn = [
+ {
+ "category": "HARM_CATEGORY_DANGEROUS",
+ "threshold": "BLOCK_NONE",
+ },
+ {
+ "category": "HARM_CATEGORY_HARASSMENT",
+ "threshold": "BLOCK_NONE",
+ },
+ {
+ "category": "HARM_CATEGORY_HATE_SPEECH",
+ "threshold": "BLOCK_NONE",
+ },
+ {
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+ "threshold": "BLOCK_NONE",
+ },
+ {
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+ "threshold": "BLOCK_NONE",
+ },
+ ]
- response = model.generate_content(input_prompt)
+ response = model.generate_content(input_prompt, safety_settings=bn)
r_text = response.text