diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 9f89168677d87c..e3c1f797c61601 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -21,7 +21,7 @@ "--debug" ], "jinja": true, - "justMyCode": false + "justMyCode": true } ] } \ No newline at end of file diff --git a/api/services/app_model_config_service.py b/api/services/app_model_config_service.py index 5a421143d9ee90..a9c6db8d43746a 100644 --- a/api/services/app_model_config_service.py +++ b/api/services/app_model_config_service.py @@ -154,33 +154,6 @@ def validate_configuration(tenant_id: str, account: Account, config: dict, mode: if not isinstance(config["more_like_this"]["enabled"], bool): raise ValueError("enabled in more_like_this must be of boolean type") - # sensitive_word_avoidance - if 'sensitive_word_avoidance' not in config or not config["sensitive_word_avoidance"]: - config["sensitive_word_avoidance"] = { - "enabled": False - } - - if not isinstance(config["sensitive_word_avoidance"], dict): - raise ValueError("sensitive_word_avoidance must be of dict type") - - if "enabled" not in config["sensitive_word_avoidance"] or not config["sensitive_word_avoidance"]["enabled"]: - config["sensitive_word_avoidance"]["enabled"] = False - - if not isinstance(config["sensitive_word_avoidance"]["enabled"], bool): - raise ValueError("enabled in sensitive_word_avoidance must be of boolean type") - - if "words" not in config["sensitive_word_avoidance"] or not config["sensitive_word_avoidance"]["words"]: - config["sensitive_word_avoidance"]["words"] = "" - - if not isinstance(config["sensitive_word_avoidance"]["words"], str): - raise ValueError("words in sensitive_word_avoidance must be of string type") - - if "canned_response" not in config["sensitive_word_avoidance"] or not config["sensitive_word_avoidance"]["canned_response"]: - config["sensitive_word_avoidance"]["canned_response"] = "" - - if not isinstance(config["sensitive_word_avoidance"]["canned_response"], str): - raise ValueError("canned_response in sensitive_word_avoidance must be of string type") - # model if 'model' not in config: raise ValueError("model is required") @@ -372,17 +345,24 @@ def validate_configuration(tenant_id: str, account: Account, config: dict, mode: @staticmethod def is_moderation_valid(config): - sensitive_word_avoidance = config.get("sensitive_word_avoidance") + if 'sensitive_word_avoidance' not in config or not config["sensitive_word_avoidance"]: + config["sensitive_word_avoidance"] = { + "enabled": False + } - if not sensitive_word_avoidance.get("enabled"): - return + if not isinstance(config["sensitive_word_avoidance"], dict): + raise ValueError("sensitive_word_avoidance must be of dict type") + + if "enabled" not in config["sensitive_word_avoidance"] or not config["sensitive_word_avoidance"]["enabled"]: + config["sensitive_word_avoidance"]["enabled"] = False - type = sensitive_word_avoidance.get("type") + if not config["sensitive_word_avoidance"]["enabled"]: + return - if not type: + if "type" not in config["sensitive_word_avoidance"] or not config["sensitive_word_avoidance"]["type"]: raise ValueError("sensitive_word_avoidance.type is required") - BaseModeration.create_instance(type).validate_config(sensitive_word_avoidance.get("configs")) + BaseModeration.create_instance(type).validate_config(config["sensitive_word_avoidance"]["configs"]) @staticmethod def is_dataset_query_variable_valid(config: dict, mode: str) -> None: