@@ -951,6 +951,104 @@ def sample_classify_text():
951
951
# Done; return the response.
952
952
return response
953
953
954
+ def moderate_text (
955
+ self ,
956
+ request : Optional [Union [language_service .ModerateTextRequest , dict ]] = None ,
957
+ * ,
958
+ document : Optional [language_service .Document ] = None ,
959
+ retry : OptionalRetry = gapic_v1 .method .DEFAULT ,
960
+ timeout : Union [float , object ] = gapic_v1 .method .DEFAULT ,
961
+ metadata : Sequence [Tuple [str , str ]] = (),
962
+ ) -> language_service .ModerateTextResponse :
963
+ r"""Moderates a document for harmful and sensitive
964
+ categories.
965
+
966
+ .. code-block:: python
967
+
968
+ # This snippet has been automatically generated and should be regarded as a
969
+ # code template only.
970
+ # It will require modifications to work:
971
+ # - It may require correct/in-range values for request initialization.
972
+ # - It may require specifying regional endpoints when creating the service
973
+ # client as shown in:
974
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
975
+ from google.cloud import language_v1
976
+
977
+ def sample_moderate_text():
978
+ # Create a client
979
+ client = language_v1.LanguageServiceClient()
980
+
981
+ # Initialize request argument(s)
982
+ document = language_v1.Document()
983
+ document.content = "content_value"
984
+
985
+ request = language_v1.ModerateTextRequest(
986
+ document=document,
987
+ )
988
+
989
+ # Make the request
990
+ response = client.moderate_text(request=request)
991
+
992
+ # Handle the response
993
+ print(response)
994
+
995
+ Args:
996
+ request (Union[google.cloud.language_v1.types.ModerateTextRequest, dict]):
997
+ The request object. The document moderation request
998
+ message.
999
+ document (google.cloud.language_v1.types.Document):
1000
+ Required. Input document.
1001
+ This corresponds to the ``document`` field
1002
+ on the ``request`` instance; if ``request`` is provided, this
1003
+ should not be set.
1004
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1005
+ should be retried.
1006
+ timeout (float): The timeout for this request.
1007
+ metadata (Sequence[Tuple[str, str]]): Strings which should be
1008
+ sent along with the request as metadata.
1009
+
1010
+ Returns:
1011
+ google.cloud.language_v1.types.ModerateTextResponse:
1012
+ The document moderation response
1013
+ message.
1014
+
1015
+ """
1016
+ # Create or coerce a protobuf request object.
1017
+ # Quick check: If we got a request object, we should *not* have
1018
+ # gotten any keyword arguments that map to the request.
1019
+ has_flattened_params = any ([document ])
1020
+ if request is not None and has_flattened_params :
1021
+ raise ValueError (
1022
+ "If the `request` argument is set, then none of "
1023
+ "the individual field arguments should be set."
1024
+ )
1025
+
1026
+ # Minor optimization to avoid making a copy if the user passes
1027
+ # in a language_service.ModerateTextRequest.
1028
+ # There's no risk of modifying the input as we've already verified
1029
+ # there are no flattened fields.
1030
+ if not isinstance (request , language_service .ModerateTextRequest ):
1031
+ request = language_service .ModerateTextRequest (request )
1032
+ # If we have keyword arguments corresponding to fields on the
1033
+ # request, apply these.
1034
+ if document is not None :
1035
+ request .document = document
1036
+
1037
+ # Wrap the RPC method; this adds retry and timeout information,
1038
+ # and friendly error handling.
1039
+ rpc = self ._transport ._wrapped_methods [self ._transport .moderate_text ]
1040
+
1041
+ # Send the request.
1042
+ response = rpc (
1043
+ request ,
1044
+ retry = retry ,
1045
+ timeout = timeout ,
1046
+ metadata = metadata ,
1047
+ )
1048
+
1049
+ # Done; return the response.
1050
+ return response
1051
+
954
1052
def annotate_text (
955
1053
self ,
956
1054
request : Optional [Union [language_service .AnnotateTextRequest , dict ]] = None ,
0 commit comments