-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckscam.py
32 lines (25 loc) · 1.58 KB
/
checkscam.py
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
import logging
import redis
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.DEBUG
)
logger = logging.getLogger(__name__)
# Assuming Redis is hosted at a hostname called 'redis-host', typically configured in Docker Compose or Docker network
seen_scams = redis.Redis(host='redis-host', port=6379, db=0)
# seen_scams = redis.Redis()
def retrieve_message_seen_count(message):
logger.debug('retrieve_message_seen_count function called')
count = seen_scams.get(message)
count = 0 if count is None else count.decode('utf-8')
seen_scams.incr(message) # increment seen count
return count
def generate_check_scam_prompt(scam_message: str, seen_num: int) -> str:
logger.debug('generate_check_scam_prompt function called')
prompt = f""""
I need help discerning if the following message is a scam message or not. You are a helpful scam detection bot working within a scam detection program.
As part of this program, many people ask you for help regarding scams and also send you possible scam messages.
You have a database that tracks all the possible scam messages that all your users have ever submitted and the following submitted message has been seen a total of {seen_num} time(s).
This is the following message which was received either on a social media platform, text, or other common messaging platforms: {scam_message}
Please tell me whether or not you think this is indeed a scam message depending on the contents of the message and the number of times it has been submitted by other users.
"""
return prompt