1515from ._s3client import S3Client , S3UploadFields
1616
1717TranslationStyle = Literal ["faithful" , "fluid" , "creative" ]
18+ ProfanityFilter = Literal ["detect" , "avoid" , "hide" ]
1819GlossaryFileFormat = Literal ["csv/table-uni" , "csv/table-multi" ]
1920
2021# Objects --------------------------------------------------------------------------------------------------------------
@@ -114,6 +115,11 @@ def __init__(self, **kwargs):
114115 self .text : str = kwargs .get ('text' )
115116 self .translatable : bool = kwargs .get ('translatable' , True )
116117
118+ class ProfanityDetectResult (LaraObject ):
119+ def __init__ (self , ** kwargs ):
120+ self .masked_text : Optional [str ] = kwargs .get ('masked_text' )
121+ self .profanities : List [dict ] = kwargs .get ('profanities' , [])
122+
117123class NGMemoryMatch (LaraObject ):
118124 def __init__ (self , ** kwargs ):
119125 self .memory : str = kwargs .get ('memory' )
@@ -138,6 +144,18 @@ def __init__(self, **kwargs):
138144 self .glossaries : Optional [List [str ]] = kwargs .get ('glossaries' , None )
139145 self .adapted_to_matches : Optional [Union [List [NGMemoryMatch ], List [Optional [List [NGMemoryMatch ]]]]] = None
140146 self .glossaries_matches : Optional [Union [List [NGGlossaryMatch ], List [Optional [List [NGGlossaryMatch ]]]]] = None
147+ self .profanities : Optional [Union [ProfanityDetectResult , List [Optional [ProfanityDetectResult ]]]] = None
148+
149+ # Parse profanities
150+ raw_profanities = kwargs .get ('profanities' , None )
151+ if raw_profanities is not None :
152+ if isinstance (raw_profanities , dict ):
153+ self .profanities = ProfanityDetectResult (** raw_profanities )
154+ elif isinstance (raw_profanities , list ):
155+ self .profanities = [
156+ ProfanityDetectResult (** p ) if p is not None else None
157+ for p in raw_profanities
158+ ]
141159
142160 # Parse adapted_to_matches
143161 adapted_to_matches = kwargs .get ('adapted_to_matches' , None )
@@ -686,6 +704,7 @@ def translate(self, text: Union[str, Iterable[str], Iterable[TextBlock]], *,
686704 no_trace : bool = False , verbose : bool = False , style : Optional [TranslationStyle ] = None ,
687705 headers : Optional [Dict [str , str ]] = None , reasoning : bool = False ,
688706 metadata : Optional [Union [str , Dict ]] = None ,
707+ profanity_filter : Optional [ProfanityFilter ] = None ,
689708 callback : Optional [Callable [[TextResult ], None ]] = None ) -> TextResult :
690709 if isinstance (text , str ):
691710 q = text
@@ -710,7 +729,7 @@ def translate(self, text: Union[str, Iterable[str], Iterable[TextBlock]], *,
710729 'priority' : priority .value if priority is not None else None ,
711730 'use_cache' : use_cache .value if use_cache is not None else None , 'cache_ttl' : cache_ttl_s ,
712731 'glossaries' : glossaries , 'verbose' : verbose , 'style' : style , 'reasoning' : reasoning ,
713- 'metadata' : metadata
732+ 'metadata' : metadata , 'profanity_filter' : profanity_filter
714733 }
715734
716735 request_headers = {}
0 commit comments