Spaces:
Running
Running
Update utils/functions.py
Browse files- utils/functions.py +20 -21
utils/functions.py
CHANGED
@@ -61,7 +61,6 @@ def add_fake_number(phone_number):
|
|
61 |
"""
|
62 |
db = SessionLocal()
|
63 |
try:
|
64 |
-
logging.info(f"Próbuję dodać numer: {phone_number}")
|
65 |
existing_number = db.query(FakeNumber).filter(FakeNumber.phone_number == phone_number).first()
|
66 |
if not existing_number:
|
67 |
new_number = FakeNumber(phone_number=phone_number)
|
@@ -190,8 +189,8 @@ def get_phone_info(phone_number):
|
|
190 |
"""
|
191 |
try:
|
192 |
parsed_number = phonenumbers.parse(phone_number, None)
|
193 |
-
country = geocoder.description_for_number(parsed_number, 'en') #
|
194 |
-
operator = carrier.name_for_number(parsed_number, 'en')
|
195 |
logging.info(f"Numer {phone_number} - Kraj: {country}, Operator: {operator}.")
|
196 |
return country, operator
|
197 |
except phonenumbers.NumberParseException as e:
|
@@ -213,11 +212,11 @@ def simple_checks(message, language):
|
|
213 |
selected_keywords = scam_keywords.get(language, scam_keywords['English'])
|
214 |
|
215 |
if any(keyword in message.lower() for keyword in selected_keywords):
|
216 |
-
warnings.append("
|
217 |
if re.search(r'http[s]?://', message):
|
218 |
-
warnings.append("
|
219 |
-
if re.search(r'\b(
|
220 |
-
warnings.append("
|
221 |
return warnings
|
222 |
|
223 |
def analyze_message(message, phone_number, additional_info, api_key, language):
|
@@ -226,7 +225,7 @@ def analyze_message(message, phone_number, additional_info, api_key, language):
|
|
226 |
"""
|
227 |
if not api_key:
|
228 |
logging.error("Brak klucza API.")
|
229 |
-
return "
|
230 |
|
231 |
url = "https://api.sambanova.ai/v1/chat/completions"
|
232 |
headers = {
|
@@ -236,29 +235,29 @@ def analyze_message(message, phone_number, additional_info, api_key, language):
|
|
236 |
# System prompts w trzech językach
|
237 |
system_prompts = {
|
238 |
'Polish': """
|
239 |
-
|
240 |
|
241 |
<analysis>
|
242 |
-
**
|
243 |
-
-
|
244 |
-
-
|
245 |
-
-
|
246 |
</analysis>
|
247 |
|
248 |
<risk_assessment>
|
249 |
-
**
|
250 |
-
-
|
251 |
-
-
|
252 |
</risk_assessment>
|
253 |
|
254 |
<recommendations>
|
255 |
-
**
|
256 |
-
-
|
257 |
-
-
|
258 |
-
-
|
259 |
</recommendations>
|
260 |
|
261 |
-
|
262 |
""",
|
263 |
'German': """
|
264 |
Du bist ein fortgeschrittener KI-Assistent, spezialisiert auf die Identifizierung gefälschter SMS-Nachrichten. Deine Aufgabe ist es, eine detaillierte Analyse der Nachricht durchzuführen, indem du einen tiefgreifenden Denkprozess nutzt und eine umfassende Bewertung lieferst. Deine Antwort sollte in drei Abschnitte unterteilt sein:
|
|
|
61 |
"""
|
62 |
db = SessionLocal()
|
63 |
try:
|
|
|
64 |
existing_number = db.query(FakeNumber).filter(FakeNumber.phone_number == phone_number).first()
|
65 |
if not existing_number:
|
66 |
new_number = FakeNumber(phone_number=phone_number)
|
|
|
189 |
"""
|
190 |
try:
|
191 |
parsed_number = phonenumbers.parse(phone_number, None)
|
192 |
+
country = geocoder.description_for_number(parsed_number, 'en') # Zmieniono na 'en' dla uniwersalności
|
193 |
+
operator = carrier.name_for_number(parsed_number, 'en')
|
194 |
logging.info(f"Numer {phone_number} - Kraj: {country}, Operator: {operator}.")
|
195 |
return country, operator
|
196 |
except phonenumbers.NumberParseException as e:
|
|
|
212 |
selected_keywords = scam_keywords.get(language, scam_keywords['English'])
|
213 |
|
214 |
if any(keyword in message.lower() for keyword in selected_keywords):
|
215 |
+
warnings.append("Message contains keywords related to potential fraud.")
|
216 |
if re.search(r'http[s]?://', message):
|
217 |
+
warnings.append("Message contains a link.")
|
218 |
+
if re.search(r'\b(provide|send|share)\b.*\b(password|code|personal information|account number)\b', message.lower()):
|
219 |
+
warnings.append("Message contains a request for confidential information.")
|
220 |
return warnings
|
221 |
|
222 |
def analyze_message(message, phone_number, additional_info, api_key, language):
|
|
|
225 |
"""
|
226 |
if not api_key:
|
227 |
logging.error("Brak klucza API.")
|
228 |
+
return "API key is missing.", "API key is missing.", "API key is missing."
|
229 |
|
230 |
url = "https://api.sambanova.ai/v1/chat/completions"
|
231 |
headers = {
|
|
|
235 |
# System prompts w trzech językach
|
236 |
system_prompts = {
|
237 |
'Polish': """
|
238 |
+
You are an advanced AI assistant specializing in identifying fake SMS messages. Your task is to conduct a detailed analysis of the message, utilizing a deep thinking process and providing a comprehensive assessment. Your response should be divided into three sections:
|
239 |
|
240 |
<analysis>
|
241 |
+
**Message Content Analysis:**
|
242 |
+
- Conduct a detailed analysis of the message content, identifying potential red flags such as language errors, requests for personal information, urgent contact requests, etc.
|
243 |
+
- Describe the linguistic and cultural context of the message.
|
244 |
+
- Identify any elements that may suggest the message is an attempt to solicit information or money.
|
245 |
</analysis>
|
246 |
|
247 |
<risk_assessment>
|
248 |
+
**Fraud Risk Assessment:**
|
249 |
+
- Based on the content analysis and available information, assess the likelihood that the message is fraudulent. Use a scale from 1 to 10, where 1 indicates very low risk and 10 indicates very high risk.
|
250 |
+
- Explain the factors that influence this assessment.
|
251 |
</risk_assessment>
|
252 |
|
253 |
<recommendations>
|
254 |
+
**User Recommendations:**
|
255 |
+
- Provide clear and concrete recommendations regarding the next steps the user should take.
|
256 |
+
- Include security suggestions such as blocking the sender, reporting the message to appropriate authorities, or ignoring the message.
|
257 |
+
- If possible, suggest additional precautionary measures the user can take to protect their personal and financial information.
|
258 |
</recommendations>
|
259 |
|
260 |
+
Your response should be formatted exactly as specified above, using the <analysis>, <risk_assessment>, and <recommendations> tags. Ensure that each section is thoroughly and comprehensively filled out.
|
261 |
""",
|
262 |
'German': """
|
263 |
Du bist ein fortgeschrittener KI-Assistent, spezialisiert auf die Identifizierung gefälschter SMS-Nachrichten. Deine Aufgabe ist es, eine detaillierte Analyse der Nachricht durchzuführen, indem du einen tiefgreifenden Denkprozess nutzt und eine umfassende Bewertung lieferst. Deine Antwort sollte in drei Abschnitte unterteilt sein:
|