in google/generativeai/types/safety_types.py [0:0]
def to_easy_safety_dict(settings: SafetySettingOptions) -> EasySafetySettingDict:
if settings is None:
return {}
if isinstance(settings, (int, str, HarmBlockThreshold)):
settings = _expand_block_threshold(settings)
if isinstance(settings, Mapping):
return {to_harm_category(key): to_block_threshold(value) for key, value in settings.items()}
else: # Iterable
result = {}
for setting in settings:
if isinstance(setting, protos.SafetySetting):
result[to_harm_category(setting.category)] = to_block_threshold(setting.threshold)
elif isinstance(setting, dict):
result[to_harm_category(setting["category"])] = to_block_threshold(
setting["threshold"]
)
else:
raise ValueError(
f"Could not understand safety setting:\n {type(setting)=}\n {setting=}"
)
return result