refactor(governance): type annotate forbidden emojis and reuse regex pattern
All checks were successful
CI / ci (pull_request) Successful in 21s
All checks were successful
CI / ci (pull_request) Successful in 21s
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import Literal
|
from typing import Literal, cast
|
||||||
|
|
||||||
from google.adk.agents.callback_context import CallbackContext
|
from google.adk.agents.callback_context import CallbackContext
|
||||||
from google.adk.models import LlmRequest, LlmResponse
|
from google.adk.models import LlmRequest, LlmResponse
|
||||||
@@ -22,7 +22,7 @@ from .config import settings
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
FORBIDDEN_EMOJIS = [
|
FORBIDDEN_EMOJIS: list[str] = [
|
||||||
"🥵",
|
"🥵",
|
||||||
"🔪",
|
"🔪",
|
||||||
"🎰",
|
"🎰",
|
||||||
@@ -144,11 +144,18 @@ Devuelve un JSON con la siguiente estructura:
|
|||||||
person_pattern = r"(?:🧑|👩|👨)"
|
person_pattern = r"(?:🧑|👩|👨)"
|
||||||
tone_pattern = r"[\U0001F3FB-\U0001F3FF]?"
|
tone_pattern = r"[\U0001F3FB-\U0001F3FF]?"
|
||||||
|
|
||||||
|
emoji_separator: str = "|"
|
||||||
|
sorted_emojis = cast(
|
||||||
|
"list[str]", sorted(FORBIDDEN_EMOJIS, key=len, reverse=True)
|
||||||
|
)
|
||||||
|
escaped_emojis = [re.escape(emoji) for emoji in sorted_emojis]
|
||||||
|
emoji_pattern = emoji_separator.join(escaped_emojis)
|
||||||
|
|
||||||
# Unique pattern that combines all forbidden emojis, including skin tones and compound emojis
|
# Unique pattern that combines all forbidden emojis, including skin tones and compound emojis
|
||||||
return re.compile(
|
return re.compile(
|
||||||
rf"{person_pattern}{tone_pattern}\u200d❤️?\u200d💋\u200d{person_pattern}{tone_pattern}" # kissers
|
rf"{person_pattern}{tone_pattern}\u200d❤️?\u200d💋\u200d{person_pattern}{tone_pattern}" # kissers
|
||||||
rf"|{person_pattern}{tone_pattern}\u200d❤️?\u200d{person_pattern}{tone_pattern}" # lovers
|
rf"|{person_pattern}{tone_pattern}\u200d❤️?\u200d{person_pattern}{tone_pattern}" # lovers
|
||||||
rf"|{'|'.join(map(re.escape, sorted(FORBIDDEN_EMOJIS, key=len, reverse=True)))}" # simple emojis
|
rf"|{emoji_pattern}" # simple emojis
|
||||||
rf"|🖕{tone_pattern}" # middle finger with all skin tone variations
|
rf"|🖕{tone_pattern}" # middle finger with all skin tone variations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user