8000 fix: add model signature for batch document translation (#276) · googleapis/google-cloud-python@23f17fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 23f17fc

Browse files
fix: add model signature for batch document translation (#276)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 403140062 Source-Link: googleapis/googleapis@67e6e0a Source-Link: googleapis/googleapis-gen@779ead9 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzc5ZWFkOTJjZGMyNDMzZDg0YWU1YWU1MzQxOGIxNjAwODQzMjI0ZSJ9
1 parent 7c17fbd commit 23f17fc

File tree

6 files changed

+690
-0
lines changed

6 files changed

+690
-0
lines changed

packages/google-cloud-translate/google/cloud/translate_v3/services/translation_service/async_client.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ async def batch_translate_document(
707707
self,
708708
request: translation_service.BatchTranslateDocumentRequest = None,
709709
*,
710+
parent: str = None,
711+
source_language_code: str = None,
712+
target_language_codes: Sequence[str] = None,
713+
input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None,
714+
output_config: translation_service.BatchDocumentOutputConfig = None,
710715
retry: retries.Retry = gapic_v1.method.DEFAULT,
711716
timeout: float = None,
712717
metadata: Sequence[Tuple[str, str]] = (),
@@ -724,6 +729,63 @@ async def batch_translate_document(
724729
Args:
725730
request (:class:`google.cloud.translate_v3.types.BatchTranslateDocumentRequest`):
726731
The request object. The BatchTranslateDocument request.
732+
parent (:class:`str`):
733+
Required. Location to make a regional call.
734+
735+
Format:
736+
``projects/{project-number-or-id}/locations/{location-id}``.
737+
738+
The ``global`` location is not supported for batch
739+
translation.
740+
741+
Only AutoML Translation models or glossaries within the
742+
same region (have the same location-id) can be used,
743+
otherwise an INVALID_ARGUMENT (400) error is returned.
744+
745+
This corresponds to the ``parent`` field
746+
on the ``request`` instance; if ``request`` is provided, this
747+
should not be set.
748+
source_language_code (:class:`str`):
749+
Required. The BCP-47 language code of
750+
the input document if known, for
751+
example, "en-US" or "sr-Latn". Supported
752+
language codes are listed in Language
753+
Support
754+
(https://cloud.google.com/translate/docs/languages).
755+
756+
This corresponds to the ``source_language_code`` field
757+
on the ``request`` instance; if ``request`` is provided, this
758+
should not be set.
759+
target_language_codes (:class:`Sequence[str]`):
760+
Required. The BCP-47 language code to
761+
use for translation of the input
762+
document. Specify up to 10 language
763+
codes here.
764+
765+
This corresponds to the ``target_language_codes`` field
766+
on the ``request`` instance; if ``request`` is provided, this
767+
should not be set.
768+
input_configs (:class:`Sequence[google.cloud.translate_v3.types.BatchDocumentInputConfig]`):
769+
Required. Input configurations.
770+
The total number of files matched should
771+
be <= 100. The total content size to
772+
translate should be <= 100M Unicode
773+
codepoints. The files must use UTF-8
774+
encoding.
775+
776+
This corresponds to the ``input_configs`` field
777+
on the ``request`` instance; if ``request`` is provided, this
778+
should not be set.
779+
output_config (:class:`google.cloud.translate_v3.types.BatchDocumentOutputConfig`):
780+
Required. Output configuration.
781+
If 2 input configs match to the same
782+
file (that is, same input path), we
783+
don't generate output for duplicate
784+
inputs.
785+
786+
This corresponds to the ``output_config`` field
787+
on the ``request`` instance; if ``request`` is provided, this
788+
should not be set.
727789
retry (google.api_core.retry.Retry): Designation of what errors, if any,
728790
should be retried.
729791
timeout (float): The timeout for this request.
@@ -741,8 +803,38 @@ async def batch_translate_document(
741803
742804
"""
743805
# Create or coerce a protobuf request object.
806+
# Sanity check: If we got a request object, we should *not* have
807+
# gotten any keyword arguments that map to the request.
808+
has_flattened_params = any(
809+
[
810+
parent,
811+
source_language_code,
812+
target_language_codes,
813+
input_configs,
814+
output_config,
815+
]
816+
)
817+
if request is not None and has_flattened_params:
818+
raise ValueError(
819+
"If the `request` argument is set, then none of "
820+
"the individual field arguments should be set."
821+
)
822+
744823
request = translation_service.BatchTranslateDocumentRequest(request)
745824

825+
# If we have keyword arguments corresponding to fields on the
826+
# request, apply these.
827+
if parent is not None:
828+
request.parent = parent
829+
if source_language_code is not None:
830+
request.source_language_code = source_language_code
831+
if output_config is not None:
832+
request.output_config = output_config
833+
if target_language_codes:
834+
request.target_language_codes.extend(target_language_codes)
835+
if input_configs:
836+
request.input_configs.extend(input_configs)
837+
746838
# Wrap the RPC method; this adds retry and timeout information,
747839
# and friendly error handling.
748840
rpc = gapic_v1.method_async.wrap_method(

packages/google-cloud-translate/google/cloud/translate_v3/services/translation_service/client.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,11 @@ def batch_translate_document(
886886
self,
887887
request: Union[translation_service.BatchTranslateDocumentRequest, dict] = None,
888888
*,
889+
parent: str = None,
890+
source_language_code: str = None,
891+
target_language_codes: Sequence[str] = None,
892+
input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None,
893+
output_config: translation_service.BatchDocumentOutputConfig = None,
889894
retry: retries.Retry = gapic_v1.method.DEFAULT,
890895
timeout: float = None,
891896
metadata: Sequence[Tuple[str, str]] = (),
@@ -903,6 +908,63 @@ def batch_translate_document(
903908
Args:
904909
request (Union[google.cloud.translate_v3.types.BatchTranslateDocumentRequest, dict]):
905910
The request object. The BatchTranslateDocument request.
911+
parent (str):
912+
Required. Location to make a regional call.
913+
914+
Format:
915+
``projects/{project-number-or-id}/locations/{location-id}``.
916+
917+
The ``global`` location is not supported for batch
918+
translation.
919+
920+
Only AutoML Translation models or glossaries within the
921+
same region (have the same location-id) can be used,
922+
otherwise an INVALID_ARGUMENT (400) error is returned.
923+
924+
This corresponds to the ``parent`` field
925+
on the ``request`` instance; if ``request`` is provided, this
926+
should not be set.
927+
source_language_code (str):
928+
Required. The BCP-47 language code of
929+
the input document if known, for
930+
example, "en-US" or "sr-Latn". Supported
931+
language codes are listed in Language
932+
Support
933+
(https://cloud.google.com/translate/docs/languages).
934+
935+
This corresponds to the ``source_language_code`` field
936+
on the ``request`` instance; if ``request`` is provided, this
937+
should not be set.
938+
target_language_codes (Sequence[str]):
939+
Required. The BCP-47 language code to
940+
use for translation of the input
941+
document. Specify up to 10 language
942+
codes here.
943+
944+
This corresponds to the ``target_language_codes`` field
945+
on the ``request`` instance; if ``request`` is provided, this
946+
should not be set.
947+
input_configs (Sequence[google.cloud.translate_v3.types.BatchDocumentInputConfig]):
948+
Required. Input configurations.
949+
The total number of files matched should
950+
be <= 100. The total content size to
951+
translate should be <= 100M Unicode
952+
codepoints. The files must use UTF-8
953+
encoding.
10670 954+
955+
This corresponds to the ``input_configs`` field
956+
on the ``request`` instance; if ``request`` is provided, this
957+
should not be set.
958+
output_config (google.cloud.translate_v3.types.BatchDocumentOutputConfig):
959+
Required. Output configuration.
960+
If 2 input configs match to the same
961+
file (that is, same input path), we
962+
don't generate output for duplicate
963+
inputs.
964+
965+
This corresponds to the ``output_config`` field
966+
on the ``request`` instance; if ``request`` is provided, this
967+
should not be set.
906968
retry (google.api_core.retry.Retry): Designation of what errors, if any,
907969
should be retried.
908970
timeout (float): The timeout for this request.
@@ -920,12 +982,41 @@ def batch_translate_document(
920982
921983
"""
922984
# Create or coerce a protobuf request object.
985+
# Sanity check: If we got a request object, we should *not* have
986+
# gotten any keyword arguments that map to the request.
987+
has_flattened_params = any(
988+
[
989+
parent,
990+
source_language_code,
991+
target_language_codes,
992+
input_configs,
993+
output_config,
994+
]
995+
)
996+
if request is not None and has_flattened_params:
997+
raise ValueError(
998+
"If the `request` argument is set, then none of "
999+
"the individual field arguments should be set."
1000+
)
1001+
9231002
# Minor optimization to avoid making a copy if the user passes
9241003
# in a translation_service.BatchTranslateDocumentRequest.
9251004
# There's no risk of modifying the input as we've already verified
9261005
# there are no flattened fields.
9271006
if not isinstance(request, translation_service.BatchTranslateDocumentRequest):
9281007
request = translation_service.BatchTranslateDocumentRequest(request)
1008+
# If we have keyword arguments corresponding to fields on the
1009+
# request, apply these.
1010+
if parent is not None:
1011+
request.parent = parent
1012+
if source_language_code is not None:
1013+
request.source_language_code = source_language_code
1014+
if target_language_codes is not None:
1015+
request.target_language_codes = target_language_codes
1016+
if input_configs is not None:
1017+
request.input_configs = input_configs
1018+
if output_config is not None:
1019+
request.output_config = output_config
9291020

9301021
# Wrap the RPC method; this adds retry and timeout information,
9311022
# and friendly error handling.

packages/google-cloud-translate/google/cloud/translate_v3beta1/services/translation_service/async_client.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ async def batch_translate_document(
574574
self,
575575
request: translation_service.BatchTranslateDocumentRequest = None,
576576
*,
577+
parent: str = None,
578+
source_language_code: str = None,
579+
target_language_codes: Sequence[str] = None,
580+
input_configs: Sequence[translation_service.BatchDocumentInputConfig] = None,
581+
output_config: translation_service.BatchDocumentOutputConfig = None,
577582
retry: retries.Retry = gapic_v1.method.DEFAULT,
578583
timeout: float = None,
579584
metadata: Sequence[Tuple[str, str]] = (),
@@ -591,6 +596,63 @@ async def batch_translate_document(
591596
Args:
592597
request (:class:`google.cloud.translate_v3beta1.types.BatchTranslateDocumentRequest`):
593598
The request object. The BatchTranslateDocument request.
599+
parent (:class:`str`):
600+
Required. Location to make a regional call.
601+
602+
Format:
603+
``projects/{project-number-or-id}/locations/{location-id}``.
604+
605+
The ``global`` location is not supported for batch
606+
translation.
607+
608+
Only AutoML Translation models or glossaries within the
609+
same region (have the same location-id) can be used,
610+
otherwise an INVALID_ARGUMENT (400) error is returned.
611+
612+
This corresponds to the ``parent`` field
613+
on the ``request`` instance; if ``request`` is provided, this
614+
should not be set.
615+
source_language_code (:class:`str`):
616+
Required. The BCP-47 language code of
617+
the input document if known, for
618+
example, "en-US" or "sr-Latn". Supported
619+
language codes are listed in Language
620+
Support
621+
(https://cloud.google.com/translate/docs/languages).
622+
623+
This corresponds to the ``source_language_code`` field
624+
on the ``request`` instance; if ``request`` is provided, this
625+
should not be set.
626+
target_language_codes (:class:`Sequence[str]`):
627+
Required. The BCP-47 language code to
628+
use for translation of the input
629+
document. Specify up to 10 language
630+
codes here.
631+
632+
This corresponds to the ``target_language_codes`` field
633+
on the ``request`` instance; if ``request`` is provided, this
634+
should not be set.
635+
input_configs (:class:`Sequence[google.cloud.translate_v3beta1.types.BatchDocumentInputConfig]`):
636+
Required. Input configurations.
637+
The total number of files matched should
638+
be <= 100. The total content size to
639+
translate should be <= 100M Unicode
640+
codepoints. The files must use UTF-8
641+
encoding.
642+
643+
This corresponds to the ``input_configs`` field
644+
on the ``request`` instance; if ``request`` is provided, this
645+
should not be set.
646+
output_config (:class:`google.cloud.translate_v3beta1.types.BatchDocumentOutputConfig`):
647+
Required. Output configuration.
648+
If 2 input configs match to the same
649+
file (that is, same input path), we
650+
don't generate output for duplicate
651+
inputs.
652+
653+
This corresponds to the ``output_config`` field
654+
on the ``request`` instance; if ``request`` is provided, this
655+
should not be set.
594656
retry (google.api_core.retry.Retry): Designation of what errors, if any,
595657
should be retried.
596658
timeout (float): The timeout for this request.
@@ -608,8 +670,38 @@ async def batch_translate_document(
608670
609671
"""
610672
# Create or coerce a protobuf request object.
673+
# Sanity check: If we got a request object, we should *not* have
674+
# gotten any keyword arguments that map to the request.
675+
has_flattened_params = any(
676+
[
677+
parent,
678+
source_language_code,
679+
target_language_codes,
680+
input_configs,
681+
output_config,
682+
]
683+
)
684+
if request is not None and has_flattened_params:
685+
raise ValueError(
686+
"If the `request` argument is set, then none of "
687+
"the individual field arguments should be set."
688+
)
689+
611690
request = translation_service.BatchTranslateDocumentRequest(request)
612691

692+
# If we have keyword arguments corresponding to fields on the
693+
# request, apply these.
694+
if parent is not None:
695+
request.parent = parent
696+
if source_language_code is not None:
697+
request.source_language_code = source_language_code
698+
if output_config is not None:
699+
request.output_config = output_config
700+
if target_language_codes:
701+
request.target_language_codes.extend(target_language_codes)
702+
if input_configs:
703+
request.input_configs.extend(input_configs)
704+
613705
# Wrap the RPC method; this adds retry and timeout information,
614706
# and friendly error handling.
615707
rpc = gapic_v1.method_async.wrap_method(

0 commit comments

Comments
 (0)
0