Skip to content
This repository was archived by the owner on Dec 17, 2023. It is now read-only.

Commit 3ad188d

Browse files
Integrate Python GAPIC Microgenerator in googleapis. This PR uses using documentai as an example. Depends on googleapis/gapic-generator-python#402
PiperOrigin-RevId: 309824146 Source-Author: Google APIs <[email protected]> Source-Date: Mon May 4 15:06:44 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: e0f9d9e1f9de890db765be46f45ca8490723e3eb Source-Link: googleapis/googleapis@e0f9d9e
1 parent edfa928 commit 3ad188d

File tree

99 files changed

+15638
-5199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+15638
-5199
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
https://www.apache.org/licenses/
44

dialogflow_v2/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from dialogflow_v2.gapic import contexts_client
2525
from dialogflow_v2.gapic import entity_types_client
2626
from dialogflow_v2.gapic import enums
27+
from dialogflow_v2.gapic import environments_client
2728
from dialogflow_v2.gapic import intents_client
2829
from dialogflow_v2.gapic import session_entity_types_client
2930
from dialogflow_v2.gapic import sessions_client
@@ -53,6 +54,11 @@ class EntityTypesClient(entity_types_client.EntityTypesClient):
5354
enums = enums
5455

5556

57+
class EnvironmentsClient(environments_client.EnvironmentsClient):
58+
__doc__ = environments_client.EnvironmentsClient.__doc__
59+
enums = enums
60+
61+
5662
class IntentsClient(intents_client.IntentsClient):
5763
__doc__ = intents_client.IntentsClient.__doc__
5864
enums = enums
@@ -74,6 +80,7 @@ class SessionsClient(sessions_client.SessionsClient):
7480
"AgentsClient",
7581
"ContextsClient",
7682
"EntityTypesClient",
83+
"EnvironmentsClient",
7784
"IntentsClient",
7885
"SessionEntityTypesClient",
7986
"SessionsClient",

dialogflow_v2/gapic/agents_client.py

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -369,76 +369,6 @@ def delete_agent(
369369
request, retry=retry, timeout=timeout, metadata=metadata
370370
)
371371

372-
def get_agent(
373-
self,
374-
parent,
375-
retry=google.api_core.gapic_v1.method.DEFAULT,
376-
timeout=google.api_core.gapic_v1.method.DEFAULT,
377-
metadata=None,
378-
):
379-
"""
380-
Retrieves the specified agent.
381-
382-
Example:
383-
>>> import dialogflow_v2
384-
>>>
385-
>>> client = dialogflow_v2.AgentsClient()
386-
>>>
387-
>>> parent = client.project_path('[PROJECT]')
388-
>>>
389-
>>> response = client.get_agent(parent)
390-
391-
Args:
392-
parent (str): Required. The project that the agent to fetch is associated with.
393-
Format: ``projects/<Project ID>``.
394-
retry (Optional[google.api_core.retry.Retry]): A retry object used
395-
to retry requests. If ``None`` is specified, requests will
396-
be retried using a default configuration.
397-
timeout (Optional[float]): The amount of time, in seconds, to wait
398-
for the request to complete. Note that if ``retry`` is
399-
specified, the timeout applies to each individual attempt.
400-
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
401-
that is provided to the method.
402-
403-
Returns:
404-
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
405-
406-
Raises:
407-
google.api_core.exceptions.GoogleAPICallError: If the request
408-
failed for any reason.
409-
google.api_core.exceptions.RetryError: If the request failed due
410-
to a retryable error and retry attempts failed.
411-
ValueError: If the parameters are invalid.
412-
"""
413-
# Wrap the transport method to add retry and timeout logic.
414-
if "get_agent" not in self._inner_api_calls:
415-
self._inner_api_calls[
416-
"get_agent"
417-
] = google.api_core.gapic_v1.method.wrap_method(
418-
self.transport.get_agent,
419-
default_retry=self._method_configs["GetAgent"].retry,
420-
default_timeout=self._method_configs["GetAgent"].timeout,
421-
client_info=self._client_info,
422-
)
423-
424-
request = agent_pb2.GetAgentRequest(parent=parent)
425-
if metadata is None:
426-
metadata = []
427-
metadata = list(metadata)
428-
try:
429-
routing_header = [("parent", parent)]
430-
except AttributeError:
431-
pass
432-
else:
433-
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
434-
routing_header
435-
)
436-
metadata.append(routing_metadata)
437-
438-
return self._inner_api_calls["get_agent"](
439-
request, retry=retry, timeout=timeout, metadata=metadata
440-
)
441-
442372
def search_agents(
443373
self,
444374
parent,
@@ -637,7 +567,7 @@ def train_agent(
637567
def export_agent(
638568
self,
639569
parent,
640-
agent_uri=None,
570+
agent_uri,
641571
retry=google.api_core.gapic_v1.method.DEFAULT,
642572
timeout=google.api_core.gapic_v1.method.DEFAULT,
643573
metadata=None,
@@ -654,7 +584,10 @@ def export_agent(
654584
>>>
655585
>>> parent = client.project_path('[PROJECT]')
656586
>>>
657-
>>> response = client.export_agent(parent)
587+
>>> # TODO: Initialize `agent_uri`:
588+
>>> agent_uri = ''
589+
>>>
590+
>>> response = client.export_agent(parent, agent_uri)
658591
>>>
659592
>>> def callback(operation_future):
660593
... # Handle result.
@@ -727,7 +660,7 @@ def export_agent(
727660
metadata_type=struct_pb2.Struct,
728661
)
729662

730-
def import_agent(
663+
def restore_agent(
731664
self,
732665
parent,
733666
agent_uri=None,
@@ -737,11 +670,10 @@ def import_agent(
737670
metadata=None,
738671
):
739672
"""
740-
Imports the specified agent from a ZIP file.
673+
Restores the specified agent from a ZIP file.
741674
742-
Uploads new intents and entity types without deleting the existing ones.
743-
Intents and entity types with the same name are replaced with the new
744-
versions from ImportAgentRequest.
675+
Replaces the current agent version with a new one. All the intents and
676+
entity types in the older version are deleted.
745677
746678
Operation <response: ``google.protobuf.Empty``>
747679
@@ -752,7 +684,7 @@ def import_agent(
752684
>>>
753685
>>> parent = client.project_path('[PROJECT]')
754686
>>>
755-
>>> response = client.import_agent(parent)
687+
>>> response = client.restore_agent(parent)
756688
>>>
757689
>>> def callback(operation_future):
758690
... # Handle result.
@@ -764,9 +696,9 @@ def import_agent(
764696
>>> metadata = response.metadata()
765697
766698
Args:
767-
parent (str): Required. The project that the agent to import is associated with.
699+
parent (str): Required. The project that the agent to restore is associated with.
768700
Format: ``projects/<Project ID>``.
769-
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to import.
701+
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to restore.
770702
Note: The URI must start with "gs://".
771703
agent_content (bytes): Zip compressed raw byte content for agent.
772704
retry (Optional[google.api_core.retry.Retry]): A retry object used
@@ -789,13 +721,13 @@ def import_agent(
789721
ValueError: If the parameters are invalid.
790722
"""
791723
# Wrap the transport method to add retry and timeout logic.
792-
if "import_agent" not in self._inner_api_calls:
724+
if "restore_agent" not in self._inner_api_calls:
793725
self._inner_api_calls[
794-
"import_agent"
726+
"restore_agent"
795727
] = google.api_core.gapic_v1.method.wrap_method(
796-
self.transport.import_agent,
797-
default_retry=self._method_configs["ImportAgent"].retry,
798-
default_timeout=self._method_configs["ImportAgent"].timeout,
728+
self.transport.restore_agent,
729+
default_retry=self._method_configs["RestoreAgent"].retry,
730+
default_timeout=self._method_configs["RestoreAgent"].timeout,
799731
client_info=self._client_info,
800732
)
801733

@@ -805,7 +737,7 @@ def import_agent(
805737
agent_uri=agent_uri, agent_content=agent_content
806738
)
807739

808-
request = agent_pb2.ImportAgentRequest(
740+
request = agent_pb2.RestoreAgentRequest(
809741
parent=parent, agent_uri=agent_uri, agent_content=agent_content
810742
)
811743
if metadata is None:
@@ -821,7 +753,7 @@ def import_agent(
821753
)
822754
metadata.append(routing_metadata)
823755

824-
operation = self._inner_api_calls["import_agent"](
756+
operation = self._inner_api_calls["restore_agent"](
825757
request, retry=retry, timeout=timeout, metadata=metadata
826758
)
827759
return google.api_core.operation.from_gapic(
@@ -831,7 +763,77 @@ def import_agent(
831763
metadata_type=struct_pb2.Struct,
832764
)
833765

834-
def restore_agent(
766+
def get_agent(
767+
self,
768+
parent,
769+
retry=google.api_core.gapic_v1.method.DEFAULT,
770+
timeout=google.api_core.gapic_v1.method.DEFAULT,
771+
metadata=None,
772+
):
773+
"""
774+
Retrieves the specified agent.
775+
776+
Example:
777+
>>> import dialogflow_v2
778+
>>>
779+
>>> client = dialogflow_v2.AgentsClient()
780+
>>>
781+
>>> parent = client.project_path('[PROJECT]')
782+
>>>
783+
>>> response = client.get_agent(parent)
784+
785+
Args:
786+
parent (str): Required. The project that the agent to fetch is associated with.
787+
Format: ``projects/<Project ID>``.
788+
retry (Optional[google.api_core.retry.Retry]): A retry object used
789+
to retry requests. If ``None`` is specified, requests will
790+
be retried using a default configuration.
791+
timeout (Optional[float]): The amount of time, in seconds, to wait
792+
for the request to complete. Note that if ``retry`` is
793+
specified, the timeout applies to each individual attempt.
794+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
795+
that is provided to the method.
796+
797+
Returns:
798+
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
799+
800+
Raises:
801+
google.api_core.exceptions.GoogleAPICallError: If the request
802+
failed for any reason.
803+
google.api_core.exceptions.RetryError: If the request failed due
804+
to a retryable error and retry attempts failed.
805+
ValueError: If the parameters are invalid.
806+
"""
807+
# Wrap the transport method to add retry and timeout logic.
808+
if "get_agent" not in self._inner_api_calls:
809+
self._inner_api_calls[
810+
"get_agent"
811+
] = google.api_core.gapic_v1.method.wrap_method(
812+
self.transport.get_agent,
813+
default_retry=self._method_configs["GetAgent"].retry,
814+
default_timeout=self._method_configs["GetAgent"].timeout,
815+
client_info=self._client_info,
816+
)
817+
818+
request = agent_pb2.GetAgentRequest(parent=parent)
819+
if metadata is None:
820+
metadata = []
821+
metadata = list(metadata)
822+
try:
823+
routing_header = [("parent", parent)]
824+
except AttributeError:
825+
pass
826+
else:
827+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
828+
routing_header
829+
)
830+
metadata.append(routing_metadata)
831+
832+
return self._inner_api_calls["get_agent"](
833+
request, retry=retry, timeout=timeout, metadata=metadata
834+
)
835+
836+
def import_agent(
835837
self,
836838
parent,
837839
agent_uri=None,
@@ -841,10 +843,11 @@ def restore_agent(
841843
metadata=None,
842844
):
843845
"""
844-
Restores the specified agent from a ZIP file.
846+
Imports the specified agent from a ZIP file.
845847
846-
Replaces the current agent version with a new one. All the intents and
847-
entity types in the older version are deleted.
848+
Uploads new intents and entity types without deleting the existing ones.
849+
Intents and entity types with the same name are replaced with the new
850+
versions from ImportAgentRequest.
848851
849852
Operation <response: ``google.protobuf.Empty``>
850853
@@ -855,7 +858,7 @@ def restore_agent(
855858
>>>
856859
>>> parent = client.project_path('[PROJECT]')
857860
>>>
858-
>>> response = client.restore_agent(parent)
861+
>>> response = client.import_agent(parent)
859862
>>>
860863
>>> def callback(operation_future):
861864
... # Handle result.
@@ -867,9 +870,9 @@ def restore_agent(
867870
>>> metadata = response.metadata()
868871
869872
Args:
870-
parent (str): Required. The project that the agent to restore is associated with.
873+
parent (str): Required. The project that the agent to import is associated with.
871874
Format: ``projects/<Project ID>``.
872-
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to restore.
875+
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to import.
873876
Note: The URI must start with "gs://".
874877
agent_content (bytes): Zip compressed raw byte content for agent.
875878
retry (Optional[google.api_core.retry.Retry]): A retry object used
@@ -892,13 +895,13 @@ def restore_agent(
892895
ValueError: If the parameters are invalid.
893896
"""
894897
# Wrap the transport method to add retry and timeout logic.
895-
if "restore_agent" not in self._inner_api_calls:
898+
if "import_agent" not in self._inner_api_calls:
896899
self._inner_api_calls[
897-
"restore_agent"
900+
"import_agent"
898901
] = google.api_core.gapic_v1.method.wrap_method(
899-
self.transport.restore_agent,
900-
default_retry=self._method_configs["RestoreAgent"].retry,
901-
default_timeout=self._method_configs["RestoreAgent"].timeout,
902+
self.transport.import_agent,
903+
default_retry=self._method_configs["ImportAgent"].retry,
904+
default_timeout=self._method_configs["ImportAgent"].timeout,
902905
client_info=self._client_info,
903906
)
904907

@@ -908,7 +911,7 @@ def restore_agent(
908911
agent_uri=agent_uri, agent_content=agent_content
909912
)
910913

911-
request = agent_pb2.RestoreAgentRequest(
914+
request = agent_pb2.ImportAgentRequest(
912915
parent=parent, agent_uri=agent_uri, agent_content=agent_content
913916
)
914917
if metadata is None:
@@ -924,7 +927,7 @@ def restore_agent(
924927
)
925928
metadata.append(routing_metadata)
926929

927-
operation = self._inner_api_calls["restore_agent"](
930+
operation = self._inner_api_calls["import_agent"](
928931
request, retry=retry, timeout=timeout, metadata=metadata
929932
)
930933
return google.api_core.operation.from_gapic(
@@ -936,7 +939,7 @@ def restore_agent(
936939

937940
def get_validation_result(
938941
self,
939-
parent=None,
942+
parent,
940943
language_code=None,
941944
retry=google.api_core.gapic_v1.method.DEFAULT,
942945
timeout=google.api_core.gapic_v1.method.DEFAULT,
@@ -951,13 +954,15 @@ def get_validation_result(
951954
>>>
952955
>>> client = dialogflow_v2.AgentsClient()
953956
>>>
954-
>>> response = client.get_validation_result()
957+
>>> parent = client.project_path('[PROJECT]')
958+
>>>
959+
>>> response = client.get_validation_result(parent)
955960
956961
Args:
957962
parent (str): Required. The project that the agent is associated with. Format:
958963
``projects/<Project ID>``.
959-
language_code (str): Optional. The language for which you want a validation result. If not
960-
specified, the agent's default language is used. `Many
964+
language_code (str): Optional. The language for which you want a validation result. If
965+
not specified, the agent's default language is used. `Many
961966
languages <https://cloud.google.com/dialogflow/docs/reference/language>`__
962967
are supported. Note: languages must be enabled in the agent before they
963968
can be used.

0 commit comments

Comments
 (0)