To begin using Protect initialize the Protect instance. This will handle the communication with the API and apply defined safety checks.
import osfrom fi.evals import Protectprotector = Protect(fi_api_key=os.getenv("FI_API_KEY"), fi_secret_key=os.getenv("FI_SECRET_KEY")) # Optional, if you want to set the API key and secret key manually
Replace "FI_API_KEY" and "FI_SECRET_KEY" with your actual credentials before executing the code.
rules = [{'metric': 'Toxicity'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
rules = [{'metric': 'Toxicity'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
rules = [{ 'metric': 'Tone', 'contains': ["fear", "sadness", "anger", "annoyance"], 'type': 'any'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
rules = [{'metric': 'Sexism'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
rules = [{'metric': 'Prompt Injection'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
rules = [{'metric': 'Data Privacy'}]action = "This message cannot be displayed"result = protector.protect( "This is a test message", protect_rules=rules, action=action, reason=True, timeout=25)print(result)
action = "This message cannot be displayed"result = protector.protect( "This is a test message", use_flash=True, action=action, reason=True, timeout=25)print(result)
Optionally You can directly use the protect function
from fi.evals import protectresult = protect( "This is my input string", protect_rules=rules, action="I cannot process this request", reason=True, timeout=50)print(result)
The protect function is a shortcut for the Protect class. Please configure the FI_API_KEY and FI_SECRET_KEY environment variables before using the protect function.
Our Protect feature also supports audio inputs, without making any additional changes. To run protect for audio inputs users send audio urls or local audio file paths as simple strings. Our system automatically identifies audio inputs and processes them accordingly