fix: empty keywords moderation. (#2108)

This commit is contained in:
Garfield Dai 2024-01-20 20:02:51 +08:00 committed by GitHub
parent 9c4bad8f1e
commit 0a5de0ff0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,7 +30,10 @@ class KeywordsModeration(Moderation):
if query:
inputs['query__'] = query
# Filter out empty values
keywords_list = [keyword for keyword in self.config['keywords'].split('\n') if keyword]
flagged = self._is_violated(inputs, keywords_list)
return ModerationInputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response)
@ -40,7 +43,9 @@ class KeywordsModeration(Moderation):
preset_response = ""
if self.config['outputs_config']['enabled']:
keywords_list = self.config['keywords'].split('\n')
# Filter out empty values
keywords_list = [keyword for keyword in self.config['keywords'].split('\n') if keyword]
flagged = self._is_violated({'text': text}, keywords_list)
preset_response = self.config['outputs_config']['preset_response']