rafaldembski commited on
Commit
2daa86a
·
verified ·
1 Parent(s): 2355128

Update utils/functions.py

Browse files
Files changed (1) hide show
  1. 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') # Możesz zmienić język na 'pl' lub 'de'
194
- operator = carrier.name_for_number(parsed_number, 'en') # Możesz zmienić język na 'pl' lub 'de'
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("Wiadomość zawiera słowa kluczowe związane z potencjalnym oszustwem.")
217
  if re.search(r'http[s]?://', message):
218
- warnings.append("Wiadomość zawiera link.")
219
- if re.search(r'\b(podaj|prześlij|udostępnij)\b.*\b(hasło|kod|dane osobowe|numer konta)\b', message.lower()):
220
- warnings.append("Wiadomość zawiera prośbę o poufne informacje.")
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 "Brak klucza API.", "Brak klucza API.", "Brak klucza API."
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
- Jesteś zaawansowanym asystentem AI specjalizującym się w identyfikacji fałszywych wiadomości SMS. Twoim zadaniem jest przeprowadzenie szczegółowej analizy wiadomości, wykorzystując głęboki proces myślenia i dostarczając kompleksową ocenę. Twoja odpowiedź powinna być podzielona na trzy sekcje:
240
 
241
  <analysis>
242
- **Analiza Treści Wiadomości:**
243
- - Przeprowadź szczegółową analizę treści wiadomości, identyfikując potencjalne czerwone flagi, takie jak błędy językowe, prośby o dane osobowe, pilne prośby o kontakt itp.
244
- - Opisz kontekst językowy i kulturowy wiadomości.
245
- - Zidentyfikuj wszelkie elementy, które mogą sugerować, że wiadomość jest próbą wyłudzenia informacji lub pieniędzy.
246
  </analysis>
247
 
248
  <risk_assessment>
249
- **Ocena Ryzyka Oszustwa:**
250
- - Na podstawie analizy treści i dostępnych informacji oceń prawdopodobieństwo, że wiadomość jest oszustwem. Użyj skali od 1 do 10, gdzie 1 oznacza bardzo niskie ryzyko, a 10 bardzo wysokie ryzyko.
251
- - Wyjaśnij, jakie czynniki wpływają na ocenę.
252
  </risk_assessment>
253
 
254
  <recommendations>
255
- **Zalecenia dla Użytkownika:**
256
- - Podaj jasne i konkretne zalecenia dotyczące dalszych kroków, które użytkownik powinien podjąć.
257
- - Uwzględnij sugestie dotyczące bezpieczeństwa, takie jak blokowanie nadawcy, zgłaszanie wiadomości do odpowiednich instytucji, czy też ignorowanie wiadomości.
258
- - Jeśli to możliwe, zasugeruj dodatkowe środki ostro��ności, które użytkownik może podjąć, aby chronić swoje dane osobowe i finansowe.
259
  </recommendations>
260
 
261
- Twoja odpowiedź powinna być sformatowana dokładnie w powyższy sposób, używając znaczników <analysis>, <risk_assessment> i <recommendations>. Upewnij się, że każda sekcja jest wypełniona kompletnie i szczegółowo.
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: