Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee28074

Browse files
authored
refactor: add missing @OverRide decorator to Moderation subclasses (#36492)
1 parent 1fb4913 commit ee28074

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

api/core/moderation/api/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, override
22

33
from pydantic import BaseModel, Field
44
from sqlalchemy import select
@@ -25,6 +25,7 @@ class ApiModeration(Moderation):
2525
name: str = "api"
2626

2727
@classmethod
28+
@override
2829
def validate_config(cls, tenant_id: str, config: dict[str, Any]):
2930
"""
3031
Validate the incoming form config data.
@@ -43,6 +44,7 @@ def validate_config(cls, tenant_id: str, config: dict[str, Any]):
4344
if not extension:
4445
raise ValueError("API-based Extension not found. Please check it again.")
4546

47+
@override
4648
def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> ModerationInputsResult:
4749
flagged = False
4850
preset_response = ""
@@ -59,6 +61,7 @@ def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> Mode
5961
flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response
6062
)
6163

64+
@override
6265
def moderation_for_outputs(self, text: str) -> ModerationOutputsResult:
6366
flagged = False
6467
preset_response = ""

api/core/moderation/keywords/keywords.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Sequence
2-
from typing import Any
2+
from typing import Any, override
33

44
from core.moderation.base import Moderation, ModerationAction, ModerationInputsResult, ModerationOutputsResult
55

@@ -8,6 +8,7 @@ class KeywordsModeration(Moderation):
88
name: str = "keywords"
99

1010
@classmethod
11+
@override
1112
def validate_config(cls, tenant_id: str, config: dict[str, Any]):
1213
"""
1314
Validate the incoming form config data.
@@ -28,6 +29,7 @@ def validate_config(cls, tenant_id: str, config: dict[str, Any]):
2829
if len(keywords_row_len) > 100:
2930
raise ValueError("the number of rows for the keywords must be less than 100")
3031

32+
@override
3133
def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> ModerationInputsResult:
3234
flagged = False
3335
preset_response = ""
@@ -49,6 +51,7 @@ def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> Mode
4951
flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response
5052
)
5153

54+
@override
5255
def moderation_for_outputs(self, text: str) -> ModerationOutputsResult:
5356
flagged = False
5457
preset_response = ""

api/core/moderation/openai_moderation/openai_moderation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, override
22

33
from core.model_manager import ModelManager
44
from core.moderation.base import Moderation, ModerationAction, ModerationInputsResult, ModerationOutputsResult
@@ -9,6 +9,7 @@ class OpenAIModeration(Moderation):
99
name: str = "openai_moderation"
1010

1111
@classmethod
12+
@override
1213
def validate_config(cls, tenant_id: str, config: dict[str, Any]):
1314
"""
1415
Validate the incoming form config data.
@@ -19,6 +20,7 @@ def validate_config(cls, tenant_id: str, config: dict[str, Any]):
1920
"""
2021
cls._validate_inputs_and_outputs_config(config, True)
2122

23+
@override
2224
def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> ModerationInputsResult:
2325
flagged = False
2426
preset_response = ""
@@ -36,6 +38,7 @@ def moderation_for_inputs(self, inputs: dict[str, Any], query: str = "") -> Mode
3638
flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response
3739
)
3840

41+
@override
3942
def moderation_for_outputs(self, text: str) -> ModerationOutputsResult:
4043
flagged = False
4144
preset_response = ""

0 commit comments

Comments
 (0)