Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
GarfieldDai committed Oct 26, 2023
1 parent 60456ed commit beb49fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
2 changes: 1 addition & 1 deletion api/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"--debug"
],
"jinja": true,
"justMyCode": false
"justMyCode": true
}
]
}
46 changes: 13 additions & 33 deletions api/services/app_model_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit beb49fd

Please sign in to comment.