rafaldembski commited on
Commit
1ff93c5
·
verified ·
1 Parent(s): 4ce4a16

Update utils/functions.py

Browse files
Files changed (1) hide show
  1. utils/functions.py +23 -22
utils/functions.py CHANGED
@@ -189,8 +189,8 @@ def get_phone_info(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,11 +212,11 @@ def simple_checks(message, language):
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,39 +225,40 @@ 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 = {
232
- "Authorization": f"Bearer {api_key}"
 
233
  }
234
 
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:
@@ -324,7 +325,7 @@ Additional Information:
324
  Provide your analysis and conclusions following the guidelines above."""
325
 
326
  payload = {
327
- "model": "Meta-Llama-3.1-8B-Instruct",
328
  "messages": [
329
  {"role": "system", "content": system_prompt},
330
  {"role": "user", "content": user_prompt}
 
189
  """
190
  try:
191
  parsed_number = phonenumbers.parse(phone_number, None)
192
+ country = geocoder.description_for_number(parsed_number, 'en') # Możesz zmienić język na 'pl' lub 'de'
193
+ operator = carrier.name_for_number(parsed_number, 'en') # Możesz zmienić język na 'pl' lub 'de'
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("Wiadomość zawiera słowa kluczowe związane z potencjalnym oszustwem.")
216
  if re.search(r'http[s]?://', message):
217
+ warnings.append("Wiadomość zawiera link.")
218
+ if re.search(r'\b(podaj|prześlij|udostępnij)\b.*\b(hasło|kod|dane osobowe|numer konta)\b', message.lower()):
219
+ warnings.append("Wiadomość zawiera prośbę o poufne informacje.")
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 "Brak klucza API.", "Brak klucza API.", "Brak klucza API."
229
 
230
  url = "https://api.sambanova.ai/v1/chat/completions"
231
  headers = {
232
+ "Authorization": f"Bearer {api_key}",
233
+ "Content-Type": "application/json"
234
  }
235
 
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:
 
325
  Provide your analysis and conclusions following the guidelines above."""
326
 
327
  payload = {
328
+ "model": "Meta-Llama-3.1-8B-Instruct", # Upewnij się, że to poprawny model API
329
  "messages": [
330
  {"role": "system", "content": system_prompt},
331
  {"role": "user", "content": user_prompt}