From e66a73530497480b5e74d725788384c7ed671b01 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Jul 2024 07:49:54 -0700 Subject: [PATCH] fix lakera ai tests --- enterprise/enterprise_hooks/lakera_ai.py | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/enterprise/enterprise_hooks/lakera_ai.py b/enterprise/enterprise_hooks/lakera_ai.py index 72485d589..75e346cdb 100644 --- a/enterprise/enterprise_hooks/lakera_ai.py +++ b/enterprise/enterprise_hooks/lakera_ai.py @@ -110,28 +110,28 @@ class _ENTERPRISE_lakeraAI_Moderation(CustomLogger): "content": content, } - lakera_input = [ - v - for k, v in sorted( - lakera_input_dict.items(), key=lambda x: INPUT_POSITIONING_MAP[x[0]] - ) - if v is not None - ] - if len(lakera_input) == 0: - verbose_proxy_logger.debug( - "Skipping lakera prompt injection, no roles with messages found" - ) - return - + lakera_input = [ + v + for k, v in sorted( + lakera_input_dict.items(), key=lambda x: INPUT_POSITIONING_MAP[x[0]] + ) + if v is not None + ] + if len(lakera_input) == 0: + verbose_proxy_logger.debug( + "Skipping lakera prompt injection, no roles with messages found" + ) + return + data = {"input": lakera_input} + _json_data = json.dumps(data) elif "input" in data and isinstance(data["input"], str): text = data["input"] + _json_data = json.dumps({"input": text}) elif "input" in data and isinstance(data["input"], list): text = "\n".join(data["input"]) + _json_data = json.dumps({"input": text}) # https://platform.lakera.ai/account/api-keys - data = {"input": lakera_input} - - _json_data = json.dumps(data) """ export LAKERA_GUARD_API_KEY=