Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def contains_profanity(text):
- profanity_list = ["bad_word1", "bad_word2", "bad_word3"] # Simplified list
- return any(word in text.lower() for word in profanity_list)
- def contains_personal_info(text):
- # Check for patterns that might indicate personal information
- email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
- phone_pattern = r'\b\d{3}[-.]?\d{3}[-.]?\d{4}\b'
- return bool(re.search(email_pattern, text) or re.search(phone_pattern, text))
- def safe_generate(prompt):
- response = llm.generate(prompt)
- if contains_profanity(response):
- return "I apologize, but I can't provide a response containing inappropriate language."
- if contains_personal_info(response):
- return "I'm sorry, but I can't include personal information in my responses."
- return response
- # Usage
- print(safe_generate("Tell me a funny joke."))
- print(safe_generate("What's your email address?"))
Advertisement
Add Comment
Please, Sign In to add comment